• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Microsoft security warning while opening excel file

 
rajesh babu Y
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I'm writing the data in form of inputstream to servlet response output stream as ".xls" file.

The download happens fine, when i trying to open the file it's giving the security warn and alert message with yes or no option

message:

" The file you're trying to open 'ABC DATA.xls', is in a different format than specified by the file extension. verify that the file is not corrupted and is from a trusted source before opening file. Do you to open file now ? "

How should i get resolved from that ..

 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is actually in the downloaded file? What format? Have you opened it to take a look and ensure that the downloaded data is what you think it is?
 
rajesh babu Y
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve,
The downloaded file contains normal result data. format is xls only. The data in file is absolute fine.
response.setContentType("application/xls");
response.setHeader("Content-disposition", "attachment; filename=\""+ stFileName + ".xls" + "\"");

The only thing the error is getting because, I'm writing the data in form of inputstream to servlet response output stream as ".xls" file.

I had gone through the few google references, found to set the content type

response.setContentType ("application/vnd.ms-excel");

response.setContentType ("application/vnd.openxml");

but still getting the same error message

" The file you're trying to open 'ABC DATA.xls', is in a different format than specified by the file extension. verify that the file is not corrupted and is from a trusted source before opening file. Do you to open file now ? "
 
margaret gillon
Ranch Hand
Posts: 335
6
Linux Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excel 2007 and forward will issue this warning about the older format Excel files. We haven't found a way to get rid of the warning because our software (not Java) only outputs Excel files up to Excel version 5. What happens if you name the output file with the extension '.xlsx' ?

Here are two posts on the issue.

This thread contains information about a property that can be set to suppress the warning message, you would have to see if the API supports it.
http://superuser.com/questions/153192/excel-2007-user-warning-when-opening-xls-files

From Microsoft:
http://blogs.msdn.com/b/vsofficedeveloper/archive/2008/03/11/excel-2007-extension-warning.aspx

 
rajesh babu Y
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Margaret,

Thanks for the suggestion, i had gone through the links which you have provided. But as per my need, i'm looking for a solution from the java to get rid of that micro soft format limitation warn.

I tried with '.xlsx' and '.xlsb' extensions, it's not allowing to open the file with same message " The file you're trying to open 'ABC DATA.xls', is in a different format than specified by the file extension. verify that the file is not corrupted and is from a trusted source before opening file. "

i'm tried with different possibilities, writing into '.csv', but it need a user action to split the data into cells respectively.

I had tried with jxl, poi, OpenCSV api's, it's an performance impact to application and java variable can't able to hold large chunk of the data.

Can we have any possibility to write into excel files in chunk flush manner with out the micro soft format error....
 
Mark Beardsley
Ranch Hand
Posts: 32
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You said you have tried POI; did you lok at the SXSSF stream at all? That provides the ability to write to an output file chunks of data - really smaller numbers of rows - at a time.

Take a look here - http://poi.apache.org/spreadsheet/how-to.html#sxssf

The one point to bear in mind is that one user has recently reported an issue with the preview on the 'mac and on some mobile devices as they do not recognise in-line strings at the preview stage even though the file can be opened successfully. Sadly SXSSF makes extensive use of in-line strings.
 
Mark Beardsley
Ranch Hand
Posts: 32
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, I should have added that it is not possible to write the older binary format files (BIFF8) as chunks, nor to stream these files The reason lies in the file format itself; BIFF8 files are composed of a series of streams of data and each stream is organised into one or more records. The problem lies in fact that pointers are used to reference the various records in the streams and these pointers can only be calculated once all of the data for the file is assembled.
 
rajesh babu Y
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,

I tried with following but still the same micro soft excel warn getting. i tried with the diff extensions .xls, .xlsx and .csv

ServletOutputStream outStream = response.getOutputStream();
SXSSFWorkbook wb = new SXSSFWorkbook(1000);
int rowcount =0;
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition", "attachment; filename=\""+ stFileName + ".csv" + "\"");
Sheet sh = wb.createSheet();
Row rw = sh.createRow(0);
for(int headCnt=0;headCnt<headers.size();headCnt++){
Cell cell = rw.createCell(headCnt);
cell.setCellValue(headers.get(headCnt));
}
while(rs.next())
{
int columnCount = rs.getMetaData().getColumnCount();
rowcount++;
rw = sh.createRow(rowcount);
for (int column = 0; column <columnCount; column++) {
Cell cell = rw.createCell(column);
cell.setCellValue(rs.getString(column+1));
}

}

wb.write(outStream);


Could you let me know your inputs here
 
Mark Beardsley
Ranch Hand
Posts: 32
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry to say that I missed your question and do not know whether you are still looking for a response.

My advice would be for you to register with the POI users list and to ask the question there.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic