简体   繁体   English

openxml sdk 2.0-未在元音突变上设置字体

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

I'm using the openxml sdk 2.0 for generating some word files. 我正在使用openxml sdk 2.0生成一些Word文件。 My problem now is that for german vowel mutations (äöÄÖÜ) the font isn't applied. 我现在的问题是,对于德语元音变体(äöÄÖÜ),该字体未应用。

Here's an example: 这是一个例子: 在此处输入图片说明

Tried it with some other fonts but even with them it's not working, the font is always set to "Calibri". 尝试过使用其他一些字体,但是即使它们不起作用,该字体也始终设置为“ Calibri”。

Anyone knows some hints to get the style appended to these special german characters? 有谁知道将这些样式附加到这些特殊德语字符的提示?

Thanks in advice. 感谢您的建议。

.

This is my Method to create the character styles: 这是我创建字符样式的方法:

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);
}

and my code for writing text: 和我写文本的代码:

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);

I had the same problem with French accented chars. 我对法语重音字符有同样的问题。

You need to set these properties for the font to be applied to accented characters. 您需要设置这些属性,以将字体应用于重音符号。 For instance : 例如 :

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

So for modify your code as the following : 因此,如下修改您的代码:

    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