Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

HSSFWorkbook POI API  RSS feed

 
Shweta Sah
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The getSheet() of HSSFWorkbook returns null when the excel is downloaded for the first time. However, when the download button is called 2nd time, it displays the excel correctly. Pls refer the below code snippet for the same.

HSSFSheet sheet=wb.getSheet(excelSheet.getSheetName());

In spite of wb or getSheetName() returning the correct value, the getSheet() returns null only for the first time after the server startup. But 2nd time onwards it is not null, & returns the correct value.

Can somebody pls help me how to get rid of this problem.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36423
454
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shweta,
Is this a new workbook that you are building? If so, can you show where you call wb.createSheet("new sheet");
 
Shweta Sah
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your immediate response. No, this is not a new Workbook, we are using spring framework & implementing buildExcelDocument() of AbstractExcelView class. please check the below code snippet

public class ExcelHelper extends AbstractExcelView {
protected void buildExcelDocument(Map model,
HSSFWorkbook wb,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
model=(HashMap)model.get("map");
ExcelModel excelModel = (ExcelModel) model.get("modelobject");
ExcelMain excel = (ExcelMain)model.get("excel");
setUrl(excel.getExcelLocation());
HSSFSheet sheet=wb.getSheet(excelSheet.getSheetName());
for(ExcelSheetHeader sheetHeader : excelSheet.getSheetHeaders()){
HSSFRow row = sheet.getRow(sheetHeader.getHeaderElementRow());
row.createCell(Short.parseShort(sheetHeader.getHeaderElementColumn().toString())).setCellValue(excelModel.getExcelHeaderValues(sheetHeader.getHeaderElementName()));

}
if(excelSheet.getGridStartRow()!=null){
Integer gridRow = excelSheet.getGridStartRow();
for(ExcelModel excelGridModel : excelModel.getExcelCollection()){
HSSFRow row = sheet.getRow(gridRow);
if(row == null){
row = sheet.createRow(gridRow);
}
. . .
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36423
454
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this might be a Spring question. Or at least that you'd have better luck getting an answer from someone who knows about Spring. I'll slide this over to our Spring forum for you.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!