簡體   English   中英

openxml sdk 2.0-未在元音突變上設置字體

[英]openxml sdk 2.0 - Font not set on vowel mutations

我正在使用openxml sdk 2.0生成一些Word文件。 我現在的問題是,對於德語元音變體(äöÄÖÜ),該字體未應用。

這是一個例子: 在此處輸入圖片說明

嘗試過使用其他一些字體,但是即使它們不起作用,該字體也始終設置為“ Calibri”。

有誰知道將這些樣式附加到這些特殊德語字符的提示?

感謝您的建議。

這是我創建字符樣式的方法:

public static void CreateAndAddCharacterStyle(StyleDefinitionsPart styleDefinitionsPart,
    string styleid, string stylename, string aliases = "")
{
    Styles styles = styleDefinitionsPart.Styles;

    DocumentFormat.OpenXml.Wordprocessing.Style style = new DocumentFormat.OpenXml.Wordprocessing.Style()
    {
        Type = StyleValues.Character,
        StyleId = styleid,
        CustomStyle = true
    };

    Aliases aliases1 = new Aliases() { Val = aliases };
    StyleName styleName1 = new StyleName() { Val = stylename };
    LinkedStyle linkedStyle1 = new LinkedStyle() { Val = styleid + "Para" };
    if (aliases != "")
        style.Append(aliases1);
    style.Append(styleName1);
    style.Append(linkedStyle1);

    StyleRunProperties styleRunProperties1 = new StyleRunProperties();

    if (styleid == "textfett")
    {
        RunFonts font1 = new RunFonts() { Ascii = "Gotham Narrow Medium" };
        styleRunProperties1.Append(font1);
    }
    else
    {
        RunFonts font1 = new RunFonts() { Ascii = "Gotham Narrow Light" };
        styleRunProperties1.Append(font1);
    }

    style.Append(styleRunProperties1);

    styles.Append(style);
}

和我寫文本的代碼:

List<Run> runs = new List<Run>();

Run r = new Run(new Text(node.Attributes["titel"].InnerText) { Space = SpaceProcessingModeValues.Preserve });
r.RunProperties = new RunProperties();
r.RunProperties.RunStyle = new RunStyle();
r.RunProperties.RunStyle.Val = "textfett";
runs.Add(r);

r = new Run(new Break());
runs.Add(r);

foreach (System.Xml.XmlNode node2 in node.ChildNodes)
{
    if (node2.Name == "info")
    {
        r = new Run(new Text(node2.Attributes["name"].InnerText + ":") { Space = SpaceProcessingModeValues.Preserve });
        r.RunProperties = new RunProperties();
        r.RunProperties.RunStyle = new RunStyle();
        r.RunProperties.RunStyle.Val = "textfett";
        runs.Add(r);

        r = new Run(new Text(" " + node2.InnerText + " ") { Space = SpaceProcessingModeValues.Preserve });
        r.RunProperties = new RunProperties();
        r.RunProperties.RunStyle = new RunStyle();
        r.RunProperties.RunStyle.Val = "textnormal";
        runs.Add(r);
    }
    if (node2.Name == "ende")
    {
        //r = new Run(new Break());
        //runs.Add(r);

        r = new Run(new Text(node2.InnerText) { Space = SpaceProcessingModeValues.Preserve });
        r.RunProperties = new RunProperties();
        r.RunProperties.RunStyle = new RunStyle();
        r.RunProperties.RunStyle.Val = "textnormal";
        runs.Add(r);
    }
}

Paragraph p = new Paragraph();
foreach (Run run in runs)
{
    p.AppendChild<Run>(run);
}
doc.MainDocumentPart.Document.Body.AppendChild(p);

我對法語重音字符有同樣的問題。

您需要設置這些屬性,以將字體應用於重音符號。 例如 :

RunFonts font = new RunFonts();
font.Ascii = font.HighAnsi = font.ComplexScript = @"Calibri";

因此,如下修改您的代碼:

    RunFonts font1 = new RunFonts() { 
        Ascii = "Gotham Narrow Medium", 
        HighAnsi = "Gotham Narrow Medium", 
        ComplexScript = "Gotham Narrow Medium" };

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM