How do I send Unicode text from MATLAB into a Word document via the ActiveX interface?
조회 수: 7 (최근 30일)
이전 댓글 표시
I'm using MATLAB to programmatically create a Microsoft Word document on Windows. In general this solution works fine, but it is having trouble with non-ASCII text. For example, take this code:
% Define a string to send with a non-ASCII character.
umbrella = char(9730);
toSend = ['Have you seen my ' umbrella '?'];
disp(toSend)
% Open a new Word document.
wordApplication = actxserver('Word.Application');
wordApplication.Visible = 1;
wordApplication.Documents.Add;
% Send the text.
selection = wordApplication.Selection;
selection.TypeText(toSend)
The Command Window displays the umbrella character correctly, but the character in the Word document is the "question mark in a box" missing character symbol. I can cut-and-paste the character from the Command Window into Word, so that character is indeed available in that font.
The TypeText method must be assuming ASCII. There are resources on how to set Unicode flags for similar operations from other languages, but I don't know how to translate them into the syntax I have available in MATLAB.
댓글 수: 3
Dasharath Gulvady
2015년 5월 12일
You may use selection.InsertSymbol(character_code) to insert a symbol to the MS Word
Walter Roberson
2015년 5월 12일
편집: Walter Roberson
2015년 5월 12일
You need to tell InsertSymbol that you want Unicode. That's a third parameter. See http://stackoverflow.com/questions/30132932/how-do-i-send-unicode-text-from-matlab-into-a-word-document-via-the-activex-inte/30133199#30133199
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 ActiveX에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!