Displaytag is exporting CSV into a .xls file

爱⌒轻易说出口 提交于 2020-01-06 23:44:33

问题


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.


回答1:


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



回答2:


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



回答3:


You need to add the below lines in your properties file:

export.excel.class=org.displaytag.export.excel.DefaultHssfExportView
export.pdf.class=org.displaytag.export.DefaultPdfExportView

But this outputs the current page record only and not the complete list.



来源:https://stackoverflow.com/questions/2366570/displaytag-is-exporting-csv-into-a-xls-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!