| Article: |
Opening Microsoft File Formats to Java | |
| Subject: | reading and writing excel and database entries and writing it into new excelsheet | |
| Date: | 2007-03-05 22:47:57 | |
| From: | bhavna13 | |
|
i m facing a problem while i m creating an excelsheet.as i have to create a new excel sheet and store the data by reading from other excelsheet or from a database. please help me to solve out this problem
|
||
Showing messages 1 through 2 of 2.
-
reading and writing excel and database entries and writing it into new excelsheet
2007-08-31 03:15:41 Rupali. [View]
-
reading and writing excel and database entries and writing it into new excelsheet
2007-11-12 00:46:45 kumar12345 [View]
how i will convert the excel sheet to PDF format with help of apache POI package in servlet and jsp in java. and what is the source code for this?



I need to look into the kind of code or entries you have to fetch form data base. Well till then, i can give you the general code for the same. It may be like,,
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("Report");
FileOutputStream fileOutputStream = new FileOutputStream(exportFile);
Iterator rowIterator = tabularRows.iterator();
int rowCount = 0;
while (rowIterator.hasNext()) {
HSSFRow row = sheet.createRow(rowCount++);
String rowToExport = (String) rowIterator.next();
List<String> columnsToExportForRow = tokenizeString(rowToExport,
your string from database);
int cellCount = 0;
if (columnsToExportForRow != null && columnsToExportForRow.size() > 0) {
Iterator columnIterator = columnsToExportForRow.iterator();
// System.out.println("\n");
while (columnIterator.hasNext()) {
HSSFCell cell = row.createCell((short) cellCount++);
cell.setCellType(1); //store numbers as text
cell.setCellValue((String) columnIterator.next());
if (rowCount == 1) {
/**
* this is the header row. so decorate it
*/
HSSFFont font = workbook.createFont();
font.setFontHeightInPoints((short) 12);
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
HSSFCellStyle style = workbook.createCellStyle();
style.setFillBackgroundColor(HSSFColor.BLUE_GREY.index);
style.setFont(font);
cell.setCellStyle(style);
}
}// end of while (columnIterator.hasNext())
}// end of if(columnsToExportForRow!=null && ...
}// end of while(listIterator.hasNext())
try {
workbook.write(fileOutputStream);
if (fileOutputStream != null) {
fileOutputStream.close();
}
} catch (IOException e) {
responseString = "The report could not be generated due to an internal error.";
}
}// end of if(tabularRows!=null && tabularRows.size()>0)
} catch (FileNotFoundException e) {
responseString = "The report could not be generated due to an internal error.";
}
return responseString;
}
Try this code out and let me know if anything more you need to know on it.
Thanks.
Rupali