• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

does excel support utf-8 encoding?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my application need to display the greek data from jsp to the excel sheet
but i am not able to display the greek charcaters in excel even after using utf-8 character encoding. i tried with iso-8859-7 also even then its taking by default windows-latin encoding.

my code goes like this:
<%
Vector x = (Vector)session.getAttribute("QRES");

if (x != null)
{

response.setContentType("application/vnd.ms-excel:charset=UTF-8");
response.setHeader("Content-Disposition","attachment;filename=QueryResult.csv");








int iNoOfCols = (new Integer((String)request.getParameter("noOfCols"))).intValue();
String displayNames = ((String)request.getParameter("displayNames"));

out.println(displayNames);
out.println("\r\n");

for(int a = 0; a < x.size(); a = a + iNoOfCols)
{
String eachRow = "";
for (int b = 0; b < iNoOfCols ; b++)
{
if((x.elementAt(a+b)) != null)
{


eachRow=(x.elementAt(a+b)).toString();
}
else
{
eachRow += " ";
}
// comma seperated values...
eachRow += ",";


}




out.println(eachRow);
out.flush();
}
out.close();

}

does excel support UTF-8 character encoding if not do we have anyother alternative for this? wud be thankful if anyone cud provide solution for this
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

Your setContentType seems to have a colon where it should have a semicolon. But you're not actually creating an Excel file, you're creating a CSV file, and I don't think the browser passes on to Excel what it thinks the file is encoded in. Have you tried adding an UTF-8 signature to the file?
 
anil prakash
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no doubt the browser is opening the file in excel(even the .CSV file wud get opened in excel only as far as my knowledge goes) but if the same file if i try to open with MSWord document its displaying THE GREEK CHARACTERS correctly with UTF-8 ENCODING but with the same UTF-8 encoding i am unable to display the greek characters correctly in excel sheet.
is there any alternative way to display the non-ascii characters correctly in excel?
 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alternative to csv is html which can use meta tag to set encoding (the meta tag may not work in Excel and it has to have .xls extension to open in Excel) or real xls format created by Jakarta POI (which allows utf-8 or utf-16).
 
"I know this defies the law of gravity... but I never studied law." -B. Bunny Defiant tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic