RunProperties runProperties0 = new RunProperties();
var runFont0 = new RunFonts { Ascii = "Arial" };
var size0 = new FontSize { Val = new StringValue("24") };
runProperties0.Append(new Bold());
runProperties0.Append(new Underline() { Val = DocumentFormat.OpenXml.Wordprocessing.UnderlineValues.Single });
//runProperties0.Append(runFont0);
runProperties0.Append(size0);
我原本期待 Times New Roman 中的“PROCURAÇãO”,但我得到“PROCURAÇãO”,其中 Çà 返回为 Calibri(Corpo)。
如何应用 Times New Roman,即使是特殊的葡萄牙语字符。谢谢!
代码在这里:
public static void CreateWordprocessingDocument_teste(string filepath)
{
using (WordprocessingDocument wordDocument =
WordprocessingDocument.Create(filepath, WordprocessingDocumentType.Document))
{
MainDocumentPart mainPart = wordDocument.AddMainDocumentPart();
mainPart.Document = new Document();
Body body = mainPart.Document.AppendChild(new Body());
Text text0 = new Text() { Text = "PROCURAÇÃO", Space = SpaceProcessingModeValues.Preserve };
Run run0 = new Run();
Paragraph para0 = new Paragraph();
ParagraphProperties paragraphProperties0 = new ParagraphProperties();
SpacingBetweenLines spaceBetweenLines0 = new SpacingBetweenLines();
ParagraphStyleId paragraphStyleId0 = new ParagraphStyleId() { Val = "Normal" };
Justification justification0 = new Justification() { Val = JustificationValues.Center };
ParagraphMarkRunProperties paragraphMarkRunProperties0 = new ParagraphMarkRunProperties();
paragraphProperties0.Append(paragraphStyleId0);
paragraphProperties0.Append(justification0);
paragraphProperties0.Append(paragraphMarkRunProperties0);
RunProperties runProperties0 = new RunProperties();
var size0 = new FontSize { Val = new StringValue("24") };
var runFont0 = new RunFonts { Ascii = "Times New Roman" };
runProperties0.Append(new Bold());
runProperties0.Append(new Underline() { Val = DocumentFormat.OpenXml.Wordprocessing.UnderlineValues.Single });
runProperties0.Append(runFont0);
runProperties0.Append(size0);
run0.Append(runProperties0);
run0.Append(text0);
para0.Append(paragraphProperties0);
para0.Append(run0);
body.AppendChild(para0);
}
}
Ascii
属性上使用
RunFonts
。根据文档,此字体分配适用于
前 128 个 Unicode 代码点仅(请参阅
https://learn.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.runfonts?view=openxml-2.8.1)
因此,虽然 Ç 和 à 是 Latin1 字符,但它们不是纯 ASCII。将字体分配给整个字形运行,而不仅仅是其中那些纯 ASCII 字符。