Interop.Word无法使用阿拉伯文本。

4

我正在尝试使用C#.net创建Word文档,我所做的是使用Interop.Word,并使用以下代码:

object oMissing = System.Reflection.Missing.Value;
object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */ 

//Start Word and create a new document.
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
oDoc = oWord.Documents.Add(ref oMissing, ref oMissing,
    ref oMissing, ref oMissing);

//Insert a paragraph at the beginning of the document.
Word.Paragraph oPara1;
oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing);
oPara1.Range.Text = "Heading 1";
oPara1.Range.Font.Bold = 1;
oPara1.Format.SpaceAfter = 24;    //24 pt spacing after paragraph.
oPara1.Range.InsertParagraphAfter();

//Insert a paragraph at the end of the document.
Word.Paragraph oPara2;
object oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
oPara2 = oDoc.Content.Paragraphs.Add(ref oRng);
oPara2.Range.Text = "Heading 2";
oPara2.Format.SpaceAfter = 6;
oPara2.Range.InsertParagraphAfter();

除了我的文本是阿拉伯语而设置oPara1.Range.Font.Bold = 1;不起作用并更改字体名称之外,一切正常。您能否找出我为什么会遇到这个问题以及我该如何解决它?

你的意思是这样使用正常,但如果你将“Heading 1”替换为阿拉伯语中的某个词,它就不能正常工作?你得到了什么错误? - Vadim
这在我的机器上似乎对英语、阿拉伯语或希伯来语都可以正常工作。也许错误与阿拉伯语无关?还是有其他问题? - Vadim
1
是的,如果我用阿拉伯语替换标题1,那么font.bold和font.Name就不起作用了,而下划线和字体颜色则正常工作! - nagham_4ng
是不工作就像什么都没发生还是抛出一个错误? - Vadim
它不起作用意味着文本仍然没有加粗(即使我尝试了Bold = 1和Bold = -1),字体也没有更改(我将字体名称设置为阿拉伯语)。 - nagham_4ng
1
我解决了,伙计们。我必须使用“Bi”字体,例如font.BoldBi或font.NameBi。 - nagham_4ng
1个回答

3
根据上面评论中 nagham_4ng 的解决方案,应在适当的地方使用 Font.NameBiFont.BoldBi 属性,而不是 Font.NameFont.Bold

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接