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

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
rospccAsked:
Who is Participating?
 
CetusMODCommented:
PAQed with points refunded (500)

CetusMOD
Community Support Moderator
0
 
CEHJCommented:
Make sure the JRE it's running under has Additional Language Support installed
0
 
Giant2Commented:
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
rospccAuthor Commented:
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
 
Giant2Commented:
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
 
CEHJCommented:
If you're looking at mail headers, i'm not sure if they support Unicode
0
 
rospccAuthor Commented:
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
 
Giant2Commented:
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
 
rospccAuthor Commented:
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
 
Giant2Commented:
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
 
CEHJCommented:
>>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
 
CEHJCommented:
>>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
 
rospccAuthor Commented:
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
 
CEHJCommented:
The email subject (i assume you mean) is yet another header

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

How and why?
0
 
CEHJCommented:
Correction rospcc, that should have been

String filename = "\\u1234\\uaef9";
0
 
rospccAuthor Commented:
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
 
rospccAuthor Commented:
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
 
CEHJCommented:
>>Anything to do with this?

Don't think so, but see my correction above
0
 
rospccAuthor Commented:
\\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
 
CEHJCommented:
>>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
 
rospccAuthor Commented:
Ok, understood. Let my try it out first, I'll get back to you tomorrow. Thanks very much for the support.


Regards,
rospcc
0
 
rospccAuthor Commented:
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
 
CEHJCommented:
>>Could you help me with the encoding??

You mean as per my last suggestion?
0
 
rospccAuthor Commented:
Yes, per your last suggestion.....
0
 
CEHJCommented:
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
 
Giant2Commented:
>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
 
rospccAuthor Commented:
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
 
Giant2Commented:
For TAI you must use:
th_TH
or
th_TH_TH
like specified in the Locale article I told before.
0
 
Giant2Commented:
I'm interested.
I believe rospcc solves.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.