2

I have a requirement in which I have to make a exportable word document from a contract record. I have decided to create a visualforce page with contentType set to application/msword.

I understand that Salesforce offers this as a workaround but there is no official documentation or support (only a help.salesforce page) and they explicitely say that the necessary css/html code needed to visualize a word in a certain way is out of scope for Salesforce support, so I come here to see if anyone knows.

The documents I'm generating are in Spanish, and there are a lot of special characters (ñ, for example, and acute letters)

When I first exported the document, with the text in my html with the special characters added directly, the word shows, for example, the "ñ" character as "ñ", the "á" as "á", etc etc.

I thought that using the HTML codes for those characters would the trick "& aacute;", etc etc. But it doesnt. Is there any other way to represent those special characters so the Word engine understands them? Do I have to explicitely define the encoding or something? Any help would be appreciated!

(I tried with the entity name, entity number and HEX code, and nothing works. Do I have to involve CSS into this?)

2
  • 3
    Can you try contentType="application/msword; charset=utf-8" and see if that helps? It sounds like the encoding or the default encoding is limited to ASCII and specifying the character set should help.
    – nbrown
    Commented Dec 2, 2022 at 15:30
  • @nbrown it didn't work sadly :( contentType="application/msword#wordprueba.doc;charset=utf-8" Commented Dec 2, 2022 at 15:37

1 Answer 1

4

I found the solution:

Adding this did the trick:

<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
</head>

Apparently adding the charset specification in the contentType attribute of apex:page doesn't work, but adding it manually in the html head works.

Props to @nbrown for the charset idea.

2
  • 2
    FWIW I used to use HTML a lot for Word Docs - it generally works ok as long as you avoid anything particularly fancy!
    – Matt Lacey
    Commented Dec 2, 2022 at 16:22
  • 1
    @MattLacey yeah, that's what I read, but there isn't a lot of forum threads or questions about exporting visualforce pages as msword documents and I never did this so I had to ask. I believe this special character issue could be encountered by other people and no one asked before so I did, now a solution is available. Commented Dec 2, 2022 at 16:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .