我有以下程序可以生成一個示例 Word 文檔:using DocumentFormat.OpenXml;using DocumentFormat.OpenXml.Packaging;using DocumentFormat.OpenXml.Wordprocessing;namespace OpenXmlExample{ class Program { static void Main(string[] args) { string filePath = @"C:\Users\[Redacted]\Desktop\OpenXmlExample.docx"; using (WordprocessingDocument document = WordprocessingDocument.Create(filePath, WordprocessingDocumentType.Document)) { // Create main part and body of document MainDocumentPart mainPart = document.AddMainDocumentPart(); mainPart.Document = new Document(); Body body = mainPart.Document.AppendChild(new Body()); // Prototype code for generation of the document title Paragraph paragraph = new Paragraph(); ParagraphProperties pPr = new ParagraphProperties { Justification = new Justification { Val = JustificationValues.Center } }; RunProperties rPr = new RunProperties { RunFonts = new RunFonts { ComplexScript = new StringValue("Arial") }, Bold = new Bold { Val = true }, Caps = new Caps { Val = true }, FontSize = new FontSize { Val = "32" }, FontSizeComplexScript = new FontSizeComplexScript { Val = "36" } }; Text t = new Text("Example Document"); Run r = new Run(); r.Append((OpenXmlElement) rPr.Clone()); r.Append(t); pPr.Append((OpenXmlElement) rPr.Clone()); paragraph.Append(pPr); paragraph.Append(r); body.Append(paragraph); } } }}它似乎工作得很好?!笆纠臋n”正確呈現,粗體和大寫,16pt 字體。但是,該ComplexScript = new StringValue("Arial")部分似乎不起作用。文本僅以默認字體呈現。任何人都可以幫助我了解我是否做錯了什么?如果我將該Ascii屬性設置為 Arial,它似乎可以工作,但我希望將其生成為<w:rFonts w:cs="Arial"/>標簽。
1 回答

HUH函數
TA貢獻1836條經驗 獲得超4個贊
對于單次運行,可以配置 4 種不同的字體。
這些字體中的每一種的使用應由運行內容的 Unicode 字符值確定。
Unicode 范圍內的字符的ASCII (U+0000-U+007F)。
復雜腳本的復雜的腳本Unicode的范圍,例如字符。阿拉伯文。
東亞用于東亞 Unicode 范圍內的字符,例如。日本人。Unicode 范圍內不屬于其他類別之一的字符的
高 ANSI。
'EXAMPLE DOCUMENT' 中的字符都屬于 ASCII 組,因此將應用相應組的字體。
MSDN和Office Open XML 中的更多詳細信息。
- 1 回答
- 0 關注
- 202 瀏覽
添加回答
舉報
0/150
提交
取消