openxml sdk 2.0 - 未在元音突变上设置字体 [英] openxml sdk 2.0 - Font not set on vowel mutations

查看:56
本文介绍了openxml sdk 2.0 - 未在元音突变上设置字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 openxml sdk 2.0 来生成一些 word 文件.我现在的问题是,对于德语元音突变 (äöÄÖÜ),该字体不适用.

I'm using the openxml sdk 2.0 for generating some word files. My problem now is that for german vowel mutations (äöÄÖÜ) the font isn't applied.

这是一个例子:

尝试使用其他一些字体,但即使使用它们也不起作用,字体始终设置为Calibri".

Tried it with some other fonts but even with them it's not working, the font is always set to "Calibri".

有人知道将样式附加到这些特殊的德语字符的提示吗?

感谢您的建议.

.

这是我创建字符样式的方法:

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

这篇关于openxml sdk 2.0 - 未在元音突变上设置字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆