OpenXml开发-向文档中添加样式
2010-07-19 17:50
260 查看
在上面插入文本的时候,有一个参数是样式ID,这个参数是怎么来的呢,我们来看下面的Xml片段
<w:style w:type="paragraph" w:styleId="MySubTitle"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:name w:val="MySubTitle" />
<w:pPr>
<w:jc w:val="center"/><!--这里定义对齐方式-->
<w:spacing w:before="200" w:after="0" />
</w:pPr>
<w:rPr>
<w:b />
<w:sz w:val="26" /> <!--这里定义字体大小-->
</w:rPr>
</w:style>
以上就是一段简单的样式定义,当然更详细的东西只能去查文档里,我也没记住多少。在定义了上面的样式后,接下来就是把这个加入到文档中去了,具体方法如下:
public void AppendStyleString(string xmlStyleString)
{
// write the styles into the style part
Uri stylesUri =
new Uri(@"/word/styles.xml", UriKind.Relative);
XmlDocument stylesXml =
package.GetWritablePart(stylesUri);
// append the styles to the document
XPathNavigator stylesNav =
stylesXml.DocumentElement.CreateNavigator();
stylesNav.AppendChild(xmlStyleString);
// write the styles back into the package part
package.SavePart(stylesUri, stylesXml);
}
通过上面的函数将样式字符串加入到文档中去之后,就可以在添加文本的时候指定它使用这个样式了。
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/sinory/archive/2009/12/04/4939146.aspx
<w:style w:type="paragraph" w:styleId="MySubTitle"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:name w:val="MySubTitle" />
<w:pPr>
<w:jc w:val="center"/><!--这里定义对齐方式-->
<w:spacing w:before="200" w:after="0" />
</w:pPr>
<w:rPr>
<w:b />
<w:sz w:val="26" /> <!--这里定义字体大小-->
</w:rPr>
</w:style>
以上就是一段简单的样式定义,当然更详细的东西只能去查文档里,我也没记住多少。在定义了上面的样式后,接下来就是把这个加入到文档中去了,具体方法如下:
public void AppendStyleString(string xmlStyleString)
{
// write the styles into the style part
Uri stylesUri =
new Uri(@"/word/styles.xml", UriKind.Relative);
XmlDocument stylesXml =
package.GetWritablePart(stylesUri);
// append the styles to the document
XPathNavigator stylesNav =
stylesXml.DocumentElement.CreateNavigator();
stylesNav.AppendChild(xmlStyleString);
// write the styles back into the package part
package.SavePart(stylesUri, stylesXml);
}
通过上面的函数将样式字符串加入到文档中去之后,就可以在添加文本的时候指定它使用这个样式了。
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/sinory/archive/2009/12/04/4939146.aspx
相关文章推荐
- Android官方开发文档Training系列课程中文版:添加ActionBar之自定义ActionBar样式
- OpenXml开发-向Excel2007文档中添加数据
- 嵌入式开发之davinci--- 8148/8168/8127 中的添加算饭scd 场景检测 文档简介
- 【HTML/XML 5】使用XSL给XML文档添加样式
- <译> SharePoint2010 Feature功能开发——为SharePoint的ECB菜单(列表项或文档的操作菜单项)添加自定义菜单栏项目
- 【Android游戏开发之七】(游戏开发中需要的样式)再次剖析游戏开发中对SurfaceView中添加组件方案!
- 使用OpenXml SDK向Word文档中添加页、段落、页眉和页脚
- 使用OpenXml SDK向Word文档中添加页、段落、页眉和页脚
- 可视化webpart基础开发——利用事件接收器实现同步操作两个文档库(添加、删除、修改文档)
- JavaScript 高级篇之DOM文档,简单封装及调用、动态添加、删除样式(六)
- 用OpenXml在文档的尾部添加一个Rich Text Content Control/Plain Text Content Control
- vue开发中,父组件添加scoped之后。解决在父组件中无法修改子组件样式问题。
- 【Android游戏开发之七】(游戏开发中需要的样式)再次剖析游戏开发中对SurfaceView中添加组件方案!
- HTML 5_为文档添加样式的方法
- SharePoint2010 Feature功能开发——为SharePoint的ECB菜单(列表项或文档的操作菜单项)添加自定义菜单栏项目
- 在主窗体Panel中添加新的窗体,实现类似于vs2010开发界面中得多窗体样式
- C# 如何给Word文档添加超链接及设置超链接的样式
- Android官方开发文档Training系列课程中文版:添加ActionBar之ActionBar浮层效果
- CAD二次开发(C#)之添加文字样式
- JavaScript 应用开发 #5:为完成的任务添加样式