- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用下面的代码将两种不同的字符样式应用于一个段落的两次运行:
Paragraph heading = new Paragraph();
ParagraphProperties heading_pPr = new ParagraphProperties();
heading.Append(heading_pPr);
Run Run1 = new Run() { RsidRunProperties = "009531B2" };
Text Text_Run1 = new Text("THIS IS TEST RUN 1");
Run1.Append(Text_Run1);
RunProperties rpr_Run1 = new RunProperties();
rpr_Run1.RunStyle = new RunStyle() { Val = "CharacterStyle1" };
Run Run2 = new Run();
RunProperties rpr_Run2 = new RunProperties();
rpr_Run2.RunStyle = new RunStyle() { Val = "CharacterStyle2" };
Text text_Run2 = new Text("THIS IS TEST RUN 2");
Run2.Append(text_Run2);
heading.Append(Run1);
heading.Append(Run2);
body.Append(heading);
但是在运行代码之后,在 word 文件中这些运行得到了 Normal 风格。我可以对段落应用段落样式但是我不能应用字符样式运行,我的代码哪里错了?
总结:
如何将字符样式应用到运行中以及如何让段落具有不同样式的运行?
最佳答案
您需要在其属性部分中指定段落的格式,否则它将回退到文档的默认设置,在本例中为 Normal
。如果您的自定义样式未保存到文档的样式部分,也可能会发生这种情况。
将您的代码更改为:
Paragraph heading = new Paragraph();
ParagraphProperties heading_pPr = new ParagraphProperties();
heading.Append(heading_pPr);
ParagraphMarkRunProperties headingParagraphMarkRunProperties = new ParagraphMarkRunProperties();
RunStyle runStyle1 = new RunStyle(){ Val = "CharacterStyle1" };
headingParagraphMarkRunProperties.Append(runStyle1);
heading_pPr.Append(headingParagraphMarkRunProperties);
这将使您的段落采用您的自定义格式。您仍然需要将单独的样式应用于 run
元素以更改其格式,就像您在其余代码中所做的那样。
关于c# - 在 c# 中使用 openxml 进行文字处理时一行中的不同样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15679402/
我的 C# 应用程序使用 OpenXML 创建一个 MSWord 文档,其中已经包含多个表。最后一部分是添加条形图。我找不到这个案例的好例子。 谢谢你的帮助! 我正在从头开始创建文档。从...开始:
我正在使用一个模板文档,该文档使用 CustomXmlBlocks 作为占位符来放置表格和其他信息。我需要能够以某种方式将图像放入其中一个 block 中......即使它首先放入运行中。 图像以字节
我正在以编程方式将 OpenXML 段落添加到 Word 文档中,并且稍后我需要能够将该段落识别为我的段落。关于如何做到这一点有什么想法吗?我尝试插入 XML 注释和扩展属性,但是当您将文档保存在 w
我想使用 openxml 删除一列,我能够清除单元格的内容,但一直无法找到删除列的文档,以便在删除列时向左移动其他单元格。如何使用 openxml 删除列,它将单元格向左移动? 最佳答案 我发现 Op
我找不到任何可以告诉我 txBody 标签中的文本是否带有项目符号的指标,您能否请我确定我应该使用哪个指标来了解文本是项目符号还是普通文本? -谢谢 最佳答案 在 txBody 标签内,您可以查找标签
我目前正在尝试使用 PHPWord 库及其模板系统来处理 docx 文件。我已经找到并更新了这个库的某人(不记得名字,但它并不重要)的路径,该库可以使用表(复制其行,然后在每一行上使用 PHPWord
这个问题已经有答案了: 已关闭11 年前。 Possible Duplicate: Open Xml and Date format in Excel cell 我正在尝试从 DataGridView
我发现各种元素非常困惑。几乎每个元素似乎都有一个与之关联的“部分”,我不确定它们是如何粘合在一起的。 工作簿工作簿部分工作表工作表部分 我也对 DocumentFormat.OpenXml.Packa
我有一个存储在 Bitmap 对象中的图像,我想将其粘贴到 OpenXML 文档中。我尝试使用 MemoryStream 作为中间步骤,如下所示: ImagePart part = container
我试图理解 OpenXML 电子表格的内部文件内容。在一些文件中,我发现了这个字符串。其他标签具有相同的前缀。标签也可以有前缀 p: w: 等。 你能帮我理解这些前缀在标签中的含义吗? 最佳答案 您可
我的预期结果是: 你好 世界! 但是当我使用以下代码时: MainDocumentPart mainDocumentPart = package.AddMainDo
我需要将多个 .docx 文件收集到一个文件夹中,并将它们“链接”成一个将显示给用户的文档。 现在我已经阅读了 Brian Jones' article虽然听起来很有希望,但我遇到了一个问题。 当我使
我正在使用 OpenXml 生成 Excel 文件,在研究了大量不同的示例代码和 SDK Productivity Tool 后,终于得到了我想要的东西。只有一件事我无法回避。当我使用 Excel 打
我正在使用 openxml 创建 WordProcessingDocuments(工作正常,生成的 word 文档正是我想要的),现在我正在尝试使用 openxml Powertools 将这些新创建
我使用 OpenXML SDK 2.5 编写了一个 Word 文档,当我在 MS Office 中预览该文档时,该文档给出了预期的外观和格式。 现在我需要将此文档转换为 HTML 文档,我开始了解 O
我是 .net 编码员,我对 ColdFusion 真的很陌生。我编写了一个自动生成发票的 .dll 库。我需要使用 ColdFusion 应用程序中的库。我已经成功地将我的库中的类加载为 coldf
以前我发布了一个问题,如何将数据集中的数据填充到 excel 工作表中,而不是如何使用该数据创建图表。那篇文章不太走运,但现在我设法从数据集中填充数据,但也在努力根据该数据创建图表,我希望图表与我的数
快要被这个问题搞疯了。我确信它是如此简单,我只是错过了它,但我一生都无法找出如何使用 C# 中的 OpenXml SDK v2.0 更改 Word 2007 中的内容控件的内容。 我创建了一个带有纯文
我正在编写一个小应用程序,它将路径作为输入,然后获取该路径中的每个 docx 文件,用关键字替换每个超链接。 奇怪的是,我发现了两种超链接,第一种来自 WordprocessingDocument E
我有一段文字想在文档的中央出现。如何在docx4j中执行此操作?我目前正在使用: PPr paragraphProperties = factory.createPPr(); //cr
我是一名优秀的程序员,十分优秀!