POI api question
807601Mar 19 2008 — edited Mar 19 2008ok ok ok i got some code i will list this in the bottom of this sheet. This code takes data and exports it to a Excel sheet format. Some of the code might be hacked and that really isn't the point or details or whatever anyway......................
We want to include the date format and after the code runs the output file is something .xls cant remember and when i open the sheet it has the date listed but the format is in days since 1900 or something like that i forgot what exactly the numbers of days or the past date 1900 or something that it refers to but it does.
Any way if i click the column with the date in there it will show the correct format of date Ex. March 19 2008 but i tried to add to my code somewhere in there a method in POI i read about that sets column width and height and all that.
So i tried to add this method into my code and it kept saying it couldn't find this method. I went back to POI API website and read only newer version supports this. so i went back and got POI 3 xxx something cant remember and thought this would solve the cannot find method problem but no
----------------------------------------------------------------------------------------------------------------------
package com.gdls.harvest;
import com.sun.rowset.internal.Row;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public class DateTest {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
sheet= wb.getSheetAt(0);
sheet.setColumnWidth((short)1, (short)1)
// sheet.autoSizeColumn((short)0); //adjust width of the first column
// sheet.autoSizeColumn((short)1); //adjust width of the second column
// Create a row and put some cells in it. Rows are 0 based.
HSSFCell cell = row.createCell((short)0);
cell.setCellValue(new Date());
// Create a cell and put a date value in it. The first cell is not styled
// as a date.
HSSFCell cell = createCell((short)0);
cell.setCellValue(new Date());
// we style the second cell as a date (and time). It is important to
// create a new cell style from the workbook otherwise you can end up
// modifying the built in style and effecting not only this cell but other cells.
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm"));
cell = Row.createCell((short)1);
cell.setCellValue(new Date());
cell.setCellStyle(cellStyle);
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("c://tmp//workbook.xls");
wb.write(fileOut);
fileOut.close();
}
}
-------------------------------------------------
like i said i been messing around in here so it might look all hacked or something but as you see me trying to edit width and all that
Edited by: vndkmps on Mar 19, 2008 3:57 PM