views:

404

answers:

2

I export an Excel document with DisplayTag. It saves as a .xls file to my Desktop. When I open it with Excel, this error displays:

"The file you are trying to open, 'filename.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."

If I click "Yes", it displays just fine in Excel. If I open this with Textpad, I see that it's a binary file, but it appears to just be "." delimited strings.

Any ideas what I might have done wrong, or how next to debug this?

edit::

If I change the extension to .txt, it's not a binary file; it's simply a list of delimited strings.

+2  A: 

Are you on Excel 2007? Seems to be a known issue:

In some cases after upgrading to Excel 2007, you may get the following error: The file you are trying to open .xlsx is in a different format than specified by the file extension. verify the file is not corrupted and is from trusted source before opening the file. Do you want to open the file now?

This errors particularly occurs when you’re trying to open an XLS file (Excel 2000-2003) with Excel 2007. In most cases, the problem can be solved by defining MIME types and associating them with extensions.

...

However, if you don’t want to look for a solution, but just want to solve the problem, insert this key in your registry to suppress the notification:

[HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Excel\Security] “ExtensionHardening”=dword:00000000

You can accomplish the above by doing the following:

  1. Open your Registry (Start -> Run -> regedit.exe)
  2. Navigate to HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\OFFICE\12.0\EXCEL\SECURITY
  3. Right click in the right window and choose New -> DWORD
  4. Type “ExtensionHardening” as the name (without the quotes)
  5. Verify that the data has the value “0
Marcus
Thank you! That page seems to be blocked at my company's firewall, but it's exactly what I was looking for.
Dean J
Rotating back, nope, that wasn't it. :-/
Dean J
Hmm.. added some more details from the thread if you can't access from the office..
Marcus
Gave that a shot, but no luck; it really seems to just be a delimited text file that's being sent to the browser, which Excel 2007 (half) chokes on.
Dean J
When you ouput to Excel, isn't DisplayTag just creating a CSV file? (CSV's usually default to Excel). Should you be saving this with a .csv extension?
Marcus
CSV is a separate option, which also seems to produce CSV. Excel is exporting a CSV... with an XLS extension.
Dean J
A: 

The default export class for Excel was set to the CSV class, but giving it the .xls extension. Changing displaytag.properties was the key here, something like:

export.types=csv excel xml rtf pdf 
export.excel=true
export.xml=true
export.csv=true
export.rtf=false
export.pdf=false
export.excel.class=org.displaytag.export.excel.DefaultHssfExportView
export.pdf.class=org.displaytag.export.DefaultPdfExportView
export.rtf.class=org.displaytag.export.DefaultRtfExportView
export.excel.filename=data.xls
export.pdf.filename=data.pdf
export.xml.filename=data.xml
export.csv.filename=data.csv
export.rtf.filename=data.rtf
Dean J