FearFactor_x
asked on
Some Issues in POI-HSSF -[ Java API To Access Microsoft Excel Format Files ]
hi Experts,
Has Anybody used HSSF of the POI Project's [Provided by apache.org] , I got the binaries from the site
http://jakarta.apache.org/poi/hssf/
HSSF is the POI Project's pure Java implementation of the Excel '97(-2002) file format. HSSF provides a way to read spreadsheets create, modify, read and write XLS spreadsheets.
With that i am able to create Simple Excel Files thru Java. But i dont know how to set the Sheet Properties.
That is the Excel that i am creating is unformatted. I deally i need to set these properties in my excel Files
1) Wrap Text to Cell Width
2) Set the COlumn Widths.. .. If anyone has previously solved the same problems can y ou please update me on the same..
Thanx
NewBieWebProgrammer..
Has Anybody used HSSF of the POI Project's [Provided by apache.org] , I got the binaries from the site
http://jakarta.apache.org/poi/hssf/
HSSF is the POI Project's pure Java implementation of the Excel '97(-2002) file format. HSSF provides a way to read spreadsheets create, modify, read and write XLS spreadsheets.
With that i am able to create Simple Excel Files thru Java. But i dont know how to set the Sheet Properties.
That is the Excel that i am creating is unformatted. I deally i need to set these properties in my excel Files
1) Wrap Text to Cell Width
2) Set the COlumn Widths.. .. If anyone has previously solved the same problems can y ou please update me on the same..
Thanx
NewBieWebProgrammer..
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hi Experts,
i used the setColumnWidth::HSSFSheet function to set the column Widths.. But
If i do so i am not able to write into those cells using row.createCell() Function.. But if i dont set the column widths i am able to write.. {by the Term "i am not able to write.." i mean = The text that i write does not appear in the Excel file..} Here is my complete SOuce code..
public void excelTester() {
String[][] Data={{"Row1: Column 1","Row 1: Column 2 "},{"Row2 : Column1","Row 2: COlumn 2"}};
int rowOffset=3; // leave the first first 3 rows blank and start from the 4th one..
int columnOffset=1; // leave the first column blank and start from the next one..
int i=0,j=0;
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
sheet.setColumnWidth((shor t)1,(short )20); // Setting the width for column 1 as 20 as it going to hold a big string
for(i=0;i<=Data.length-1;i ++){
// Create a Row Here.
HSSFRow row = sheet.createRow(rowOffset+ +);
for(j=0;j<=Data[i].length- 1;j++){
row.createCell((short)(col umnOffset+ j)).setCel lValue(Dat a[i][j]);
}
}
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook .xls");
wb.write(fileOut);
fileOut.close();
}
FOr the above program when i run and open workbook.xls i get only the items in COLUMN displayed that is
<blank> Row 1: Column 2
<blank> Row 2: Column 2
The column 1 items are missing.. HOw do i overcome this problem..
NewBieProgrammer..
HSSFSheet sheet1 = wb.createSheet("Test Results");
sheet1.setColumnWidth((sho rt)0, (short)2300);
row.createCell((short)(col umnOffset+ j)).setCel lValue(Dat a[i][j]);
i used the setColumnWidth::HSSFSheet function to set the column Widths.. But
If i do so i am not able to write into those cells using row.createCell() Function.. But if i dont set the column widths i am able to write.. {by the Term "i am not able to write.." i mean = The text that i write does not appear in the Excel file..} Here is my complete SOuce code..
public void excelTester() {
String[][] Data={{"Row1: Column 1","Row 1: Column 2 "},{"Row2 : Column1","Row 2: COlumn 2"}};
int rowOffset=3; // leave the first first 3 rows blank and start from the 4th one..
int columnOffset=1; // leave the first column blank and start from the next one..
int i=0,j=0;
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
sheet.setColumnWidth((shor
for(i=0;i<=Data.length-1;i
// Create a Row Here.
HSSFRow row = sheet.createRow(rowOffset+
for(j=0;j<=Data[i].length-
row.createCell((short)(col
}
}
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook
wb.write(fileOut);
fileOut.close();
}
FOr the above program when i run and open workbook.xls i get only the items in COLUMN displayed that is
<blank> Row 1: Column 2
<blank> Row 2: Column 2
The column 1 items are missing.. HOw do i overcome this problem..
NewBieProgrammer..
HSSFSheet sheet1 = wb.createSheet("Test Results");
sheet1.setColumnWidth((sho
row.createCell((short)(col
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks!
8-)
HSSFSheet sheet1 = wb.createSheet("Test Results");
sheet1.setColumnWidth((sho
sheet1.setColumnWidth((sho
sheet1.setColumnWidth((sho
sheet1.setColumnWidth((sho
sheet1.setColumnWidth((sho
HSSFPrintSetup printSet = sheet1.getPrintSetup();
printSet.setPaperSize(HSSF
printSet.setLandscape(true
printSet.setFitWidth((shor
printSet.setFitHeight((sho
sheet1.setFitToPage(true);
sheet1.setHorizontallyCent
HSSFHeader header = sheet1.getHeader();
header.setLeft(HSSFHeader.
header.setRight(HSSFHeader
HSSFFooter footer = sheet1.getFooter();
footer.setRight( "Page " + HSSFFooter.page() + " of " + HSSFFooter.numPages() );
wb.setRepeatingRowsAndColu
sheet1.setDisplayGridlines
HSSFRow bTitle = sheet1.createRow((short)0)
HSSFCell cTcell = bTitle.createCell((short)0
cTcell.setCellValue("Autom
HSSFCellStyle st1 = WorkbookStyles.createStyle
st1.setBorderBottom(HSSFCe
st1.setBorderLeft(HSSFCell
st1.setBorderRight(HSSFCel
st1.setBorderTop(HSSFCellS
st1.setAlignment(HSSFCellS
st1.setFillForegroundColor
st1.setFillBackgroundColor
st1.setWrapText(true);
cTcell.setCellStyle(st1);
I would say to go through the documentation and examples. It is a bit different than javadocs but it does show how.