This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes In Struts2 unable to export the data to excel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "In Struts2 unable to export the data to excel" Watch "In Struts2 unable to export the data to excel" New topic
Author

In Struts2 unable to export the data to excel

Anjanaya swamy
Greenhorn

Joined: Jun 14, 2012
Posts: 7
hi all,

i am trying to export the data into excel from struts 2. In my case excel is opening but no data is getting interested into the excel (blank excel sheet).

The code is struts.xml is as follows :

<action name="downloadReserveNumbersPri" class="com.wipro.vel.nmp.web.NMP.DownloadReserveAction">
<result name="success" type="stream">
<param name="contentType">application/vnd.ms-excel</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">attachment; filename="excelExport.xls"</param>
<param name="bufferSize">4096</param>
</result>
</action>

The code in the action class is as follows :

private InputStream inputStream;


public void exportExcel() throws Exception {

Map session = ActionContext.getContext().getSession();
FileOutputStream file = null;
file = new FileOutputStream("poi-test.xls");

List<SearchNumberDTO> outputCityAndRangeList=(List<SearchNumberDTO>)session.get("outputCityAndRangeList");
System.out.println("numberTypes--------------->"+outputCityAndRangeList.size());

HSSFWorkbook workbook = createWorkbook(outputCityAndRangeList);

ByteArrayOutputStream baos = new ByteArrayOutputStream();
workbook.write(file);
workbook.write(baos);
ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
inputStream = bis;


}


public HSSFWorkbook createWorkbook(List<SearchNumberDTO> totalSearchNumberDTO) throws Exception {

HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Reservation Details ");

HSSFCellStyle headerCellStyle = wb.createCellStyle();
HSSFFont boldFont = wb.createFont();
boldFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
headerCellStyle.setFont(boldFont);

HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell(0);
cell.setCellStyle(headerCellStyle);
cell.setCellValue(new HSSFRichTextString("Reservation Id"));
cell = row.createCell(1);
cell.setCellStyle(headerCellStyle);
cell.setCellValue(new HSSFRichTextString("Customer Name"));
cell = row.createCell(2);
cell.setCellStyle(headerCellStyle);
cell.setCellValue(new HSSFRichTextString("STD Code"));

for(int index=0;index < totalSearchNumberDTO.size(); index++){
row = sheet.createRow(index);
cell = row.createCell(0);
SearchNumberDTO searchNumberDTO = (SearchNumberDTO) totalSearchNumberDTO.get(index);
HSSFRichTextString reservationId = new HSSFRichTextString(searchNumberDTO.getReservationId());
cell.setCellValue(reservationId);
cell = row.createCell(1);
HSSFRichTextString customerName = new HSSFRichTextString(searchNumberDTO.getCustomerName());
cell.setCellValue(customerName);
cell = row.createCell(2);
HSSFRichTextString stdCode = new HSSFRichTextString(searchNumberDTO.getStdCode());
cell.setCellValue(stdCode);
cell = row.createCell(3);

}

return wb;
}


public InputStream getInputStream() {
return inputStream;
}


public void setInputStream(InputStream inputStream) {
this.inputStream = inputStream;
}


Please someone help me .

Thanks in advance.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: In Struts2 unable to export the data to excel
 
Similar Threads
writing into excel sheet
opening the excel sheet from servlet
root cause of problem ,why 2003 excel cell background color is not reflecting in orginal document
facing diffculty to highlight background color of an excel cell which is not reflected in file
How to make POI HSSF support Chinese Encoding?