G
Guy
Hello
This is not a pure java question and can also be related to HTML, but
I'll try.
Ive written a java servlet that queries a database table and shows the
result as a html table. The user can also ask to receive the result as
an Excel sheet.
Im creating the Excel sheet by printing the same html table, but with
the content-type of "application/vnd.ms-excel". The Excel file is
created fine.
The problem is that the tables may contain non-english data so I want
to use a UTF-8 encoding.
I put this in my code:
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Encoding","utf-8");
And even this:
out.println("<!DOCTYPE
application/vnd.ms-excel;charset=utf-8>");
But it doesnt seem to be enough.
The non-english characters appear as garbage and the produced code
looks like this:
<Content-type: application/vnd.ms-excel;charset=utf-8>
<!DOCTYPE application/vnd.ms-excel;charset=utf-8>
<META HTTP-EQUIV="expires" CONTENT="0">
<META HTTP-EQUIV="pragma" CONTENT="NO-CACHE">
<html xmlns="urn:schemas-microsoft-comfficeffice"
xmlns:x="urn:schemas-microsoft-comffice:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html;
charset=Windows-1254">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 10">
<link rel=File-List href="a.files/filelist.xml">
<link rel=Edit-Time-Data href="a.files/editdata.mso">
<link rel=OLE-Object-Data href="a.files/oledata.mso">
<title>Show user history</title>
Note that although the page encoding is utf-8, Excel adds another line
with the "Windows-1254" charset and thats what causing the problem.
When I change it manually everything works fine.
Is there a way I can control this charset parameter dynamically ? Or
fix the whole thing in a different way ?
Thanks
Guy
This is not a pure java question and can also be related to HTML, but
I'll try.
Ive written a java servlet that queries a database table and shows the
result as a html table. The user can also ask to receive the result as
an Excel sheet.
Im creating the Excel sheet by printing the same html table, but with
the content-type of "application/vnd.ms-excel". The Excel file is
created fine.
The problem is that the tables may contain non-english data so I want
to use a UTF-8 encoding.
I put this in my code:
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Encoding","utf-8");
And even this:
out.println("<!DOCTYPE
application/vnd.ms-excel;charset=utf-8>");
But it doesnt seem to be enough.
The non-english characters appear as garbage and the produced code
looks like this:
<Content-type: application/vnd.ms-excel;charset=utf-8>
<!DOCTYPE application/vnd.ms-excel;charset=utf-8>
<META HTTP-EQUIV="expires" CONTENT="0">
<META HTTP-EQUIV="pragma" CONTENT="NO-CACHE">
<html xmlns="urn:schemas-microsoft-comfficeffice"
xmlns:x="urn:schemas-microsoft-comffice:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html;
charset=Windows-1254">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 10">
<link rel=File-List href="a.files/filelist.xml">
<link rel=Edit-Time-Data href="a.files/editdata.mso">
<link rel=OLE-Object-Data href="a.files/oledata.mso">
<title>Show user history</title>
Note that although the page encoding is utf-8, Excel adds another line
with the "Windows-1254" charset and thats what causing the problem.
When I change it manually everything works fine.
Is there a way I can control this charset parameter dynamically ? Or
fix the whole thing in a different way ?
Thanks
Guy