File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

In Struts2 unable to export the data to excel

Anjanaya swamy
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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/</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">attachment; filename="excelExport.xls"</param>
<param name="bufferSize">4096</param>

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");

HSSFWorkbook workbook = createWorkbook(outputCityAndRangeList);

ByteArrayOutputStream baos = new ByteArrayOutputStream();
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();

HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell(0);
cell.setCellValue(new HSSFRichTextString("Reservation Id"));
cell = row.createCell(1);
cell.setCellValue(new HSSFRichTextString("Customer Name"));
cell = row.createCell(2);
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 = row.createCell(1);
HSSFRichTextString customerName = new HSSFRichTextString(searchNumberDTO.getCustomerName());
cell = row.createCell(2);
HSSFRichTextString stdCode = new HSSFRichTextString(searchNumberDTO.getStdCode());
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.

  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic