2009年12月4日
摘要: //开始一个新行 public static void WriteStartRow(XmlWriter writer, int row) { writer.WriteStartElement(Prefixes.SpreadsheetML, "row", Namespaces.SpreadsheetML); writer.WriteAttributeString("r", row.ToString()); } //添加内容为文本的单元格 public static void WriteStringCell(XmlWriter writer, string 阅读全文
posted @ 2009-12-04 12:46 James Cheung 阅读(432) 评论(0) 推荐(0)
摘要: public static void Run() { // 打开Excel2007模板文档 using (PackageHelper package = new PackageHelper(Properties.Resources.BaseSpreadsheetML)) { // 加载sheet1内容到一个XmlDocument Uri sheet1Uri = new Uri(@"/xl/worksheets/sheet1.xml", UriKind.Relative); XmlDocument sheet1Xml = package.GetWritablePart(she 阅读全文
posted @ 2009-12-04 12:46 James Cheung 阅读(794) 评论(0) 推荐(0)
摘要: /// <summary> /// 通过书签定位 /// </summary> /// <param name="documentXml">原始文档</param> /// <param name="bookMark">对应的书签名</param> /// <param name="overwrite"></param> /// <returns></returns> /// <remarks>通过已经在 阅读全文
posted @ 2009-12-04 12:44 James Cheung 阅读(2935) 评论(2) 推荐(0)
摘要: public void RenderTableV(XmlWriter writer, System.Data.DataTable dtInput, string tableStyleName) { // 添加一个表 writer.WriteStartElement(Prefixes.WordprocessingML, "tbl", Namespaces.WordprocessingML); if (tableStyleName != "") ApplyTableStyle(writer, tableStyleName); //为每列添加一行 foreac 阅读全文
posted @ 2009-12-04 12:02 James Cheung 阅读(1252) 评论(0) 推荐(0)
摘要: #region Insert Images public string InsertImage(XmlWriter writer, string imageType, string imageUrl) { // create the new image part if (File.Exists(imageUrl)) { FileInfo fi = new FileInfo(imageUrl); Uri imageUri = new Uri("/word/media/" + fi.Name, UriKind.Relative); package.CreateNewPart(i 阅读全文
posted @ 2009-12-04 12:01 James Cheung 阅读(2987) 评论(0) 推荐(0)
摘要: 在上面插入文本的时候,有一个参数是样式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"/> 阅读全文
posted @ 2009-12-04 11:59 James Cheung 阅读(959) 评论(0) 推荐(0)
摘要: public partial class WordprocessingDoc { private PackageHelper package; public PackageHelper Package { get { return package; } set { package = value; } } public WordprocessingDoc() { //Properties.Resources.BaseWordDocument为已经添加到资源中的一个空洞docx文档,这里也 package = new PackageHelper(Properties.Resources.Base 阅读全文
posted @ 2009-12-04 11:57 James Cheung 阅读(604) 评论(0) 推荐(0)
摘要: 这个类PackageHelper ,是微软在发布OpenXML SDK之前给出的操作OpenXml的例子里的一个类,这个是操作word文档的那个,基本没有做什么修改,如果要操作Word文档的话,这个类基本是可以直接用的。public class PackageHelper : IDisposable { #region 私有变量 private MemoryStream m_packageData; private Package m_package; #endregion #region 构造函数 /// <summary> /// 用给定数据创建一个Package对象的实例 / 阅读全文
posted @ 2009-12-04 11:56 James Cheung 阅读(1992) 评论(0) 推荐(0)
摘要: 3privateXmlDocumentxmlDoc;4//loadxmlfile5privatevoidLoadXml()6{7xmlDoc=newXmlDocument();8xmlDoc.Load("User.xml");9}10//添加节点11privatevoidAddElement()12{13LoadXml();14XmlNodexmldocSelect=xmlDoc.SelectSingleNode("user");15XmlElementel=xmlDoc.CreateElement("person");//添加per 阅读全文
posted @ 2009-12-04 11:55 James Cheung 阅读(407) 评论(0) 推荐(0)
摘要: XmlNamespaceManager类用来解析集合的命名空间、向集合添加命名空间和从集合中移除命名空间,以及提供对这些命名空间的范围管理。 该 类包含以下方法: AddNamespace 将给定的命名空间添加到集合。 GetEnumerator 返回一个枚举数,将使用该枚举数循环访问 XmlNamespaceManager 集合中的命名空间。 GetNamespacesInScope 获取被前缀键控的可用于枚举当前范围内的命名空间的命名空间名称集合。 HasNamespace 获取一个值,该值指示所提供的前缀是否具有为当前推到的范围定义的命名空间。 LookupNamespace 获取指定前 阅读全文
posted @ 2009-12-04 11:54 James Cheung 阅读(906) 评论(0) 推荐(0)