I'm using Drupal 7.x with the "Views Data Export" (VDE) module to provide Excel file downloads of view data in a nice and neat spreadsheet form. Thankfully, the file exports fine except that it creates an Excel file that Excel believes is corrupted. The version of the VDE module I'm using is 7.x-3.0-beta7 and the exact message I get when trying to open the XLS file is as follows:

The file you are trying to open, '.xls.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 the file. Do you want to open the file now?

In the above message, "filename" appears in the message as some sort of hash (i.e. - it looks like encrypted text and is about 8 or 9 characters in length--this time, it was "i7P8vU9O"). I'm not sure why "xls" is showing twice like it is and I'm not sure if this is why I'm getting the error when I try to open the file, but it's not from anything I've done and after removing the extra ".xls" from the filename, it still gives me the error when I try to open it. This message-window has 3 buttons: "Yes", "No", and "Help" and if I click on "Yes", the Excel file opens perfectly fine... But I'd like to fix this if possible.

Any ideas what's causing this? I might be wrong here but after scouring the module's code, I found what I believe are the headers being sent:

meta http-equiv="Content-Type" content="application/vnd.ms-excel"
meta http-equiv="Content-Type" content="text/html; charset=utf-8"

Comments

wolf_22’s picture

I found a way to fix the error we're receiving when we open the XLS file output--I haven't implemented it yet and I'm hoping you can steer me in the right direction: the cells need binary packing for M$ output.

For example, take the following proof-of-concept code (shove it all in a PHP file and access the file in your browser):

//Beginning of file...
function xlsBOF() {
   echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);  
   return;
}

//End of file...
function xlsEOF() {
   echo pack("ss", 0x0A, 0x00);
   return;
}

//Creates a heading...
function xlsWriteLabel($Row, $Col, $Value ) {
   $L = strlen($Value);
   echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
   echo $Value;
   return;
}

//Test Data
$result='this is a test';

//Send Headers
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;
header("Content-Disposition: attachment;filename=test.xls ");
header("Content-Transfer-Encoding: binary ");

//XLS Data Cell
$title = 'test';
xlsBOF();
xlsWriteLabel(1,1,$result);
xlsEOF();

That code above creates an XLS file without that irritating corruption message at the beginning but the problem is that the module appears to be using Drupal theming to theme the Excel output--which isn't going to fly as far as Excel is concerned.

The file I'm assuming this code should be applied to is "views_data_export.theme.inc". Is this correct? If so, where at should the change occur? For headings, I was thinking that it would be in "template_preprocess_views_data_export_msoffice_header()" and for the body, "template_preprocess_views_data_export_msoffice_body()". Is this right?

Any insight is appreciated.

danreb’s picture

Hi Wolf_22,

Do you manage to remove the error message in the xls files using views data export?
I'm having the same issue and searching for the solutions seems that this is mesage was introduce in excel 2007 and later as explain here -> http://stackoverflow.com/questions/3363520/create-excel-file-as-html-markup and here -> http://support.microsoft.com/kb/948615

Was anybody here know's any work around?

steven jones’s picture

Status: Active » Closed (won't fix)

This is explained here: https://www.drupal.org/node/1820458

Sorry, but we won't be supporting binary XLS files in VDE 'core' any time soon.

bharath2232’s picture

thankz for the help it solved for me - http://www.filesheart.com