使用OpenXml向空白文档添加一个带表格线的表(转)
来源:互联网 发布:淘宝店聚划算入口 编辑:程序博客网 时间:2024/06/14 08:22
using System;using System.Collections.Generic;using System.IO;using System.IO.Packaging;using System.Linq;using System.Text;using System.Xml;using DocumentFormat.OpenXml;using DocumentFormat.OpenXml.Wordprocessing;using DocumentFormat.OpenXml.Packaging;namespace HelloDocx{class Program{static void Main(string[] args){using(WordprocessingDocument doc = WordprocessingDocument.Create("D:\\Test.docx", WordprocessingDocumentType.Document)){MainDocumentPart mainPart = doc.AddMainDocumentPart();mainPart.Document = new Document();Body body = mainPart.Document.AppendChild(new Body());Paragraph p = mainPart.Document.Body.AppendChild(new Paragraph());p.AppendChild(new Run(new Text("Test")));CreateTable(doc);}}private static bool CreateTable(WordprocessingDocument doc){bool result = false;Table tab = new Table();TableProperties tbps = new TableProperties();TableWidth tbwidth = new TableWidth(){Width = "0",Type = TableWidthUnitValues.Auto};TableBorders tbbs = new TableBorders();TopBorder tpb = new TopBorder(){Val = BorderValues.Single};BottomBorder tbb = new BottomBorder(){Val = BorderValues.Single};RightBorder trb = new RightBorder(){Val = BorderValues.Single};LeftBorder tlb = new LeftBorder(){Val = BorderValues.Single};InsideHorizontalBorder tihb = new InsideHorizontalBorder(){Val = BorderValues.Single};InsideVerticalBorder tivb = new InsideVerticalBorder(){Val = BorderValues.Single};tbbs.Append(tpb);tbbs.Append(tbb);tbbs.Append(trb);tbbs.Append(tlb);tbbs.Append(tihb);tbbs.Append(tivb);tbps.Append(tbbs);tbps.Append(tbwidth);TableGrid TG = new TableGrid();GridColumn GC1 = new GridColumn() { Width = "3192" };GridColumn GC2 = new GridColumn() { Width = "3192" };GridColumn GC3 = new GridColumn() { Width = "3192" };TG.Append(GC1);TG.Append(GC2);TG.Append(GC3);TableRow TR1 = new TableRow();TableCell TC1 = new TableCell();AddTableCellProperty(TC1);Paragraph P1 = new Paragraph();TC1.Append(P1);TableCell TC2 = new TableCell();AddTableCellProperty(TC2);Paragraph P2 = new Paragraph();TC2.Append(P2);TableCell TC3 = new TableCell();AddTableCellProperty(TC3);Paragraph P3 = new Paragraph();TC3.Append(P3);TR1.Append(TC1);TR1.Append(TC2);TR1.Append(TC3);tab.Append(tbps);tab.Append(TG);tab.Append(TR1);doc.MainDocumentPart.Document.Body.Append(tab);result = true;return result;}private static void AddTableCellProperty(TableCell TC){TableCellProperties TCP = new TableCellProperties();TableCellWidth TCW = new TableCellWidth(){Width = "3192",Type = TableWidthUnitValues.Dxa};TCP.Append(TCW);TC.Append(TCP);}}}
转自:http://blog.csdn.net/songpengpeng20100202/article/details/7426733
ps:调用处与原文稍微变动,但创建表的函数无修改
阅读全文
0 0
- 使用OpenXml向空白文档添加一个带表格线的表(转)
- 使用OpenXml向空白文档添加一个带表格线的表
- 使用OpenXML更新Word文档中的表格
- 使用OpenXML更新Word文档中的表格
- 使用OpenXml SDK向Word文档中添加页、段落、页眉和页脚
- 使用OpenXml SDK向Word文档中添加页、段落、页眉和页脚
- 使用OpenXml SDK向Word文档中添加页、段落、页眉和页脚
- 用OpenXml在文档的尾部添加一个Rich Text Content Control/Plain Text Content Control
- 使用OpenXml 2.0向Excel文档加入自定义Ribbon
- 使用OpenXml为Excel表格添加合计行
- 用CLR C++ 创建一个Word文档并画一张带表格线的表
- 向文档里添加带色彩的文字
- 如何使用C#向Word文档中添加表格和嵌套表格
- 一个word文档中,多个表格的批量调整(根据窗口调整表格和添加表格水平线)
- 使用OpenXml SDK 给Word文档添加样式并应用于文本
- OpenXml SDK 2.0 创建Word 2010文档(不带[Compatibility])最简代码
- 使用OPENXML(Using OpenXML)
- 向空白web中添加table对象的方法
- ActiveMq深入学习 第一波
- Linux下的延迟函数sleep()
- Bluetooth之BluetoothSocket
- Kafka命令详解(一)---topic相关
- mongo在shell中操作命令
- 使用OpenXml向空白文档添加一个带表格线的表(转)
- Android N(API level 24.)废弃了Html.fromHtml(String)
- 友元
- java android 将 List中元素互换位置
- 谁让APP工程师产生了泡沫?
- Java_面向对象_类
- BGABanner-Android 引导、图片轮播控件
- 使用Jekyll搭建自己的博客
- Linux:Mysql,phpmyadmin密码忘了怎么办