Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to save a spreadsheet filename in Thai Characters using JAVA + OpenOffice

Posted on 2006-05-23
32
Medium Priority
?
503 Views
Last Modified: 2012-06-22
Currently I am using JAVA and OpenOffice API to write a spreadsheet document. WHen I save the file and if the filename contains some Thai Characters, the file is being save as ?????????.xls
If the filename only has Thai Characters, the file will be saved as .DAT file and filename is something like a physical location address.

It is alright when I save it manually from the OpenOffice application.


Regards,
rospcc
0
Comment
Question by:rospcc
  • 11
  • 10
  • 8
  • +1
30 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 16740897
Make sure the JRE it's running under has Additional Language Support installed
0
 
LVL 12

Expert Comment

by:Giant2
ID: 16740930
Try to write a file from Java using Thai Characters.
If it goes, the problem could be in a configuration of OpenOffice API.
If it doesn't go, the problem is one told by CEHJ before.

Bye, Giant.
0
 

Author Comment

by:rospcc
ID: 16757216
Hi,

Thanks for the quick response. Sorry, I was mistaken. When I generated the file, everything was actually alright. But, because after it was generated, I used Java to attach the file into an email and send it over.

The filename that I saved is something like Report100506.xls, but when I attached to email, I set the sourceFileName as Report100506.xls and set the display fileName in the attachment as Thai. The problem happened here actually. When I received the email, it was in ??????? and .dat


Regards,
rospcc
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 12

Expert Comment

by:Giant2
ID: 16758132
I think it could be a problem with the machine language because if java receive Report100506.xls (here I do not see any special char) there is no reason it change to other.
What is the mail client you use to send e-mail?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16758525
If you're looking at mail headers, i'm not sure if they support Unicode
0
 

Author Comment

by:rospcc
ID: 16813285
I'm using Outlook Express, the mail header is not so important. I need the attachment filename to be display in Thai. Here is the codes that I used to add in the attachement:


String filename_path = filename;   // This is Report100506.xls
                        
                      // Create second body part
                      messageBodyPart = new MimeBodyPart();
                  
                      // Get the attachment
                      DataSource source = new FileDataSource(filename_path);
                  
                      // Set the data handler to the attachment
                      messageBodyPart.setDataHandler(new DataHandler(source));
                        
                        String fileNameDefault = save;  //This is in Thai so that when user receives using their mail client, they will see the Thai
                        
                      // Set the filename
                      messageBodyPart.setFileName(fileNameDefault);
                  
                      // Add part two
                      multipart.addBodyPart(messageBodyPart);
0
 
LVL 12

Expert Comment

by:Giant2
ID: 16830769
Here you can find something about the internationalization:
http://java.sun.com/developer/technicalArticles/J2SE/locale/
Try to see it.
Hope this could help you.
Bye, Giant.
0
 

Author Comment

by:rospcc
ID: 16949607
I did try to take a look at the website, but I don't have time to read through. If you guys can help by pointing me to exact codings or API or anything that can be implemented straight away, I would really appreciated it.


Regards,
rospcc
0
 
LVL 12

Expert Comment

by:Giant2
ID: 16949645
Try this to see what locales are in your system:
http://javaalmanac.com/egs/java.util/GetAllLocales.html

and here to set the Locale using:
http://javaalmanac.com/egs/java.util/SetDefLocale.html?l=rel
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16949679
>>the mail header is not so important. I need the attachment filename to be display in Thai.

The attachment filename *is* a header essentially
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16949755
>>or anything that can be implemented straight away

You could use Unicode escaped format to encode the file name and decode it on the other side. E.g.:


String filename = "\u1234\uaef9";
0
 

Author Comment

by:rospcc
ID: 16949784
ooo sorry what I meant was actually the email title :)..Anyway we do need the email title in Thai too now :(

Does it help by changing the Locale? I tried it but the email is still recieved as ?????????????

>>You could use Unicode escaped format to encode the file name and decode it on the other side.

I tried this, didn't work too. Or should I use other email API?

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16949808
The email subject (i assume you mean) is yet another header

>>I tried this, didn't work too.

How and why?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16949822
Correction rospcc, that should have been

String filename = "\\u1234\\uaef9";
0
 

Author Comment

by:rospcc
ID: 16949828
Instead of trying with the attachment, I tried with the email title (email subject) first. I passed in Thai characters as the subject and tried to run the codes to send the email.

Using the Java code:

// Create the message
          Message message = new MimeMessage(session);
      
          // Fill its headers
          message.setSubject(subject); //this is where the email subject is set

Another part of the message is set as message.setContent(content, "text/plain");
Anything to do with this?
0
 

Author Comment

by:rospcc
ID: 16949844
It seems that CEHJ is on the right track, by setting the Unicode.

I tried to send email manually from Outlook Express, I set as PLAIN TEXT, then when I click send, it will ask me whether I want to send as Unicode or send as it is. I click send as it is, and I received ???????????? for the Thai characters.

If we know how to set the Plain to Unicode, it might solve the problem..
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16949846
>>Anything to do with this?

Don't think so, but see my correction above
0
 

Author Comment

by:rospcc
ID: 16949877
\\u1234\\uaef9

I need to encode the thai characters to the format above first. Otherwise if I paste exactly what you gave me, it will set \u1234\uaef9 as the email subject
0
 
LVL 12

Expert Comment

by:Giant2
ID: 16950002
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16950009
>>it will set \u1234\uaef9 as the email subject

That's the whole idea. I can't confirm whether Unicode is supported, but if it isn't, you can recreate the subject, in Thai, from that String
0
 

Author Comment

by:rospcc
ID: 16950080
Ok, understood. Let my try it out first, I'll get back to you tomorrow. Thanks very much for the support.


Regards,
rospcc
0
 

Author Comment

by:rospcc
ID: 16957443
Sorry cehj, I tried the MimeUtility, but I am not familiar with it, so until now I still couldn't do the encoding.  I tried to look at MimeMessage class which I am using it to send the email, the particular function setSubject(java.lang.String subject, java.lang.String charset) I tried to set the charset as UTF-8 also cannot.

Could you help me with the encoding??
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16957554
>>Could you help me with the encoding??

You mean as per my last suggestion?
0
 

Author Comment

by:rospcc
ID: 16957595
Yes, per your last suggestion.....
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16957646
This is all you need really:



      /**
       * @param c The char to present in Java Unicode escaped format
       * @return A String in Java Unicode escaped format
       */
      public static String toUnicodeEscaped(char c) {
            String charIndex = "0123456789abcdef";
            StringBuffer sb = new StringBuffer(6);
            sb.append("\\u");
            for(int i = 0;i < 4;i++) {
                  int index = (c >> (i * 4)) & 0xF;
                  sb.insert(2, charIndex.charAt(index));
            }
            return sb.toString();
      }


      /**
       *      Description of the Method
       *
       * @param      escaped      A String in Unicode escaped format,
       *e.g. \u45ed\u23ae
       * @return                              The decoded character
       */
      public static char fromUnicodeEscaped(String escaped) {
            escaped = escaped.toLowerCase();
            return (char) Integer.parseInt(escaped.substring(escaped.indexOf("\\u") + 2), 16);
      }

0
 
LVL 12

Expert Comment

by:Giant2
ID: 16957693
>I tried the MimeUtility...
Here is an example of MimeUtility:
http://java-house.jp/ml/archive/j-h-b/028062.html
It uses japanese conversion.

Bye, Giant.
0
 

Author Comment

by:rospcc
ID: 16957770
Strange, when I received the email, the default charset of that email was being set to Japan which is correct. But the characters are still in ??????????

I have tried with MimeUtility.encodeWord("JAVA &#12513;&#12540;&#12523; &#12486;&#12473;&#12488;", "ISO-2022-JP", "B") and also with  msg.setSubject("JAVA MAIL &#12486;&#12473;&#12488;","ISO-2022-JP");

It seems to be correct, but still does not work :(
0
 
LVL 12

Expert Comment

by:Giant2
ID: 16966480
For TAI you must use:
th_TH
or
th_TH_TH
like specified in the Locale article I told before.
0
 
LVL 12

Expert Comment

by:Giant2
ID: 17128090
I'm interested.
I believe rospcc solves.
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
ID: 17395713
PAQed with points refunded (500)

CetusMOD
Community Support Moderator
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month12 days, 5 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question