3

In my application, I am using apache POI 3.8 for report generation.

The system is working fine and its generating report in xls format.

But when I open the xls file it given me warning before opening the file.

enter image description here

And here is the response type I am using...

response.setHeader("Content-Type", "application/vnd.ms-excel");         
response.setHeader("Content-Disposition","attachment; filename="+xlsFileName+".xls");

I also tried with ...

response.setHeader("Content-Disposition","attachment; filename="+xlsFileName+".xls");
 response.setHeader("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");

But the problem still exist. Here in both of the case If I use file extension as ".xlsx" then Its not giving any warning and works fine.

So can anyone suggest me why it gives warning for MS-Excel 2003 format ??

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Gunjan Shah
  • 5,088
  • 16
  • 53
  • 72
  • Maybe your xls is not really xls but is in fact HTML pretending to be xls? In that case the message is due to extension hardening in Office. http://blogs.msdn.com/b/vsofficedeveloper/archive/2008/03/11/excel-2007-extension-warning.aspx – Tim Williams Jan 11 '13 at 06:41

1 Answers1

8

Apache POI uses HSSFWorkbook object for creating xls files and XSSFWorkbook object for xlsx files. Please check what object you used for creating xls.

http://poi.apache.org/spreadsheet/quick-guide.html

SANN3
  • 9,459
  • 6
  • 61
  • 97
  • So is there any common interface to create both xls and xlsx file ?? – Gunjan Shah Jan 11 '13 at 06:33
  • Workbook is a common interface for both xls and xlsx. Check the above link which contains the code samples. – SANN3 Jan 11 '13 at 06:35
  • 1
    ohk..I had used Workbook wb = new XSSFWorkbook(); so I was generating xlsx file but the extension was xks. So I was getting above mentioned warning. I replaced it with Workbook wb = new HSSFWorkbook(); Now its not giving any warning and working fine. Thanks for the reply :) – Gunjan Shah Jan 11 '13 at 06:53