ColdFusion, MS Word Document and Greek Characters

后端 未结 2 1115
囚心锁ツ
囚心锁ツ 2021-01-25 17:11

I am trying to dynamically build word documents from a database (I am using a CFC for query handling). My efforts were successful, but I can only reproduce docs for the English

相关标签:
2条回答
  • 2021-01-25 17:23

    Sounds very much like a character set issue. Take a read through this article http://www.joelonsoftware.com/articles/Unicode.html which does a great job of explaining things. In this case though, you've gone to lengths to set everything to utf-8, which would make me thing that what you're getting from the DB isn't in unicode, but in a greek codepage. As an experiment, you could try setting the charset in the cfheader and tags to ISO-8859-7 or Windows-1253. That may correctly show the content. You could also take out the and open up the document in IE. There's a View->Encoding menu which lets you change the encoding IE uses to render the document which may show what's actually in use.

    By commenting out the tag I think you're letting the browser decide the content type and it's probably working it out to be one of the greek charsets. You could also try using fiddler to capture and inspect the response from CF. If the greek characters are truly encoded as utf-8 they'll take up more than 1 byte, whereas if they're in a greek codepage, they'll only take up 1 byte. Using the hex view in the response tab of fiddler ought to show you this pretty quickly.

    The other option might to be to use something like Apache POI to generate 'real' word .doc or .docx files. It's a chunk of work, but we use it to good effect where I work.

    0 讨论(0)
  • 2021-01-25 17:37

    When I tried your pastebin example I too got gibberish. It looks like you dropped the <meta> tag specifying utf-8. When I added it back, the characters displayed properly for me in MS Word.

    <cfprocessingdirective pageencoding="utf-8">
    <cfheader name="Content-Disposition" value="inline; filename=Save-Print.doc" charset="utf-8">
    <cfcontent type="application/msword; charset=utf-8">
    <html xmlns:o="urn:schemas-microsoft-com:office:office"
          xmlns:w="urn:schemas-microsoft-com:office:word" 
          xmlns="http://www.w3.org/TR/REC-html40">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Print</title>
    ...
    
    0 讨论(0)
提交回复
热议问题