Aspose.Words使用代码插入表格
Aspose.Words是一款功能强大的word文档处理控件,在不需要安装word的条件下,可进行word的创建,修改,转换等操作。
Aspose.Words可以简单使用该产品提供的DocumentBuilder类库进行Word表格的插入。
DocumentBuilder.StartTable 开始构建一个新的表格
DocumentBuilder.InsertCell 插入新的行和单元格到表格
DocumentBuilder.Writeln 为当前单元格写入文本
DocumentBuilder.EndRow用于指示结束当前行,并且开始新的一行
DocumentBuilder.EndTable 表示表格构建完成
下面的代码,展示了如何插入一个简单无格式的表格到word:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// We call this method to start building the table.
builder.StartTable();
builder.InsertCell();
builder.Write("Row 1, Cell 1 Content.");
// Build the second cell
builder.InsertCell();
builder.Write("Row 1, Cell 2 Content.");
// Call the following method to end the row and start a new row.
builder.EndRow();
// Build the first cell of the second row.
builder.InsertCell();
builder.Write("Row 2, Cell 1 Content");
// Build the second cell.
builder.InsertCell();
builder.Write("Row 2, Cell 2 Content.");
builder.EndRow();
// Signal that we have finished building the table.
builder.EndTable();
// Save the document to disk.
doc.Save(MyDir + "DocumentBuilder.CreateSimpleTable Out.doc");
下面代码展示了,如何使用代码插入格式化的表格到word:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.StartTable();
// Make the header row.
builder.InsertCell();
// Set the left indent for the table. Table wide formatting must be applied after
// at least one row is present in the table.
table.LeftIndent = 20.0;
// Set height and define the height rule for the header row.
builder.RowFormat.Height = 40.0;
builder.RowFormat.HeightRule = HeightRule.AtLeast;
// Some special features for the header row.
builder.CellFormat.Shading.BackgroundPatternColor = Color.FromArgb(198, 217, 241);
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.Font.Size = 16;
builder.Font.Name = "Arial";
builder.Font.Bold = true;
builder.CellFormat.Width = 100.0;
builder.Write("Header Row,\n Cell 1");
// We don't need to specify the width of this cell because it's inherited from the previous cell.
builder.InsertCell();
builder.Write("Header Row,\n Cell 2");
builder.InsertCell();
builder.CellFormat.Width = 200.0;
builder.Write("Header Row,\n Cell 3");
builder.EndRow();
// Set features for the other rows and cells.
builder.CellFormat.Shading.BackgroundPatternColor = Color.White;
builder.CellFormat.Width = 100.0;
builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
// Reset height and define a different height rule for table body
builder.RowFormat.Height = 30.0;
builder.RowFormat.HeightRule = HeightRule.Auto;
builder.InsertCell();
// Reset font formatting.
builder.Font.Size = 12;
builder.Font.Bold = false;
// Build the other cells.
builder.Write("Row 1, Cell 1 Content");
builder.InsertCell();
builder.Write("Row 1, Cell 2 Content");
builder.InsertCell();
builder.CellFormat.Width = 200.0;
builder.Write("Row 1, Cell 3 Content");
builder.EndRow();
builder.InsertCell();
builder.CellFormat.Width = 100.0;
builder.Write("Row 2, Cell 1 Content");
builder.InsertCell();
builder.Write("Row 2, Cell 2 Content");
builder.InsertCell();
builder.CellFormat.Width = 200.0;
builder.Write("Row 2, Cell 3 Content.");
builder.EndRow();
builder.EndTable();
doc.Save(MyDir + "DocumentBuilder.CreateFormattedTable Out.doc");
试用版下载:http://www.componentcn.com/html/wbbjkj_281_3926.html
联系方式:846631466
Aspose.Words使用代码插入表格的更多相关文章
- C# 操作Word文本框——插入表格/读取表格/删除表格
在文本框中,我们可以操作很多元素,如文本.图片.表格等,在本篇文章中将着重介绍如何插入表格到文本框,插入的表格我们可以对表格进行格式化操作来丰富表格内容.此外,对于文本框中的表格内容,我们也可以根据需 ...
- Ueditor 1.4.3 插入表格后无边框无颜色,不能正常显示
在使用Ueditor 插入表格的功能时,发现插入时正常. 但保存到后台后再取出来,表格不能正常显示.查看保存的html代码,发现保存时并未给table 添加border属性.以致于再次取出来时,不能正 ...
- 用Twebbrowser做可控编辑器与MSHTML(插入表格)
在插入表格问题上出现与结果想象不一样的问题.看代码 <table border="1" cellpadding="0" width="100%& ...
- markdown插入表格语法
markdown插入表格语法 举例 如表格标题为,姓名,班级,成绩 标题内的内容为,yang,a班,100 我们要在markdow文件中插入表格 如 姓名|班级|成绩 -|-|- yang|a班|10 ...
- 地图中插入表格——ArcMap篇
在制作专题图的过程中,不但要有地理要素表示空间位置,经常还要在图的周围制作一些表格数据.这里对ArcMap中的插入方法进行总结. 方法一:插入对象 利用菜单中的"插入"-" ...
- Word里插入表格不带左右边框
插入表格后选中,然后开始-----段落------选择右下角的边框设置,选择无左右边框.
- richTextBox插入表格
附件:http://files.cnblogs.com/xe2011/richTextBox_InsertTable.rar 插入表格 /// <summary> /// 插入表格 /// ...
- 13LaTeX学习系列之---LaTeX插入表格
目录 目录 前言 (一)插入表格的基础语法 1.说明 2.源代码 3.输出效果 (二)查看文档 目录 本系列是有关LaTeX的学习系列,共计19篇,本章节是第13篇. 前一篇:12LaTeX学习系列之 ...
- 获取刚刚插入表格的这条信息的自增ID
获取刚刚插入表格的这条信息的自增ID var conn=getConnection(); var msql="INSERT INTO " + table +" (&quo ...
随机推荐
- Vue 打印预览功能
需求有几种情况: 1.直接在HTML写页面,将页面上的东西用A4纸打印出来: 2.后台传回PDF文件,前台浏览器预览并打印: 3.后台做好要打印的,传回图片,如base64编码,前台浏览器 预览并打印 ...
- robotframe处理日志中文问题
unicode('${addr1.text}',"utf-8")
- 快学UiAutomator创建第一个实例
工具准备 一.准备好java环境(JDK)和安卓环境(SDK.ADT)jdk1.6+ \eclipse\SDK \ADT详情百度,安装java环境 二.打开eclipse 三.创建步骤: 右键新建== ...
- WPF显示尺寸与设备无关问题
WPF单位 WPF窗口以及其中的所有元素都是用与设备无关的单位进行度量.一个与设备无关的单位被定义为1/96英寸.WPF程序统一用下面一个公式来定义物理单位尺寸: [ 物理单位尺寸(像素)] = [ ...
- NLP.TM | GloVe模型及其Python实现
在进行自然语言处理中,需要对文章的中的语义进行分析,于是迫切需要一些模型去描述词汇的含义,很多人可能都知道word2vector算法,诚然,word2vector是一个非常优秀的算法,并且被广泛运用, ...
- KVM 重命名虚机
KVM 重命名虚机 1. 查看虚机列表 [root@bjape01-kvm1 ~]# virsh list --all Id 名称 状态 --- ...
- bzoj5183 [Baltic2016]Park
题目描述: bz luogu 题解: 把坐标系看反了持续$WA$系列. 对偶图+并查集维护. 先处理出树对树.树对墙的空隙,然后把人和空隙按从小到大排序. 用并查集维护四面墙之间是否能互相隔断. 代码 ...
- (45)zabbix报警媒介:SMS
介绍 服务器安装串口GSM短信猫之后,zabbix可以使用它来发送短信通知给管理员,如下注意事项: 串行设备速度要与GSM猫相匹配(linux下默认为/dev/ttyS0),zabbix无法设置设置串 ...
- js中小数精度问题
js中小数的取值为近似值,可能比实际值大,也可能比实际值小,进行“四舍五入”得到的 例如:alert(0.1+0.2);值为0.300000004 alert(0.2+0.7);值为1.899 ...
- 《C/C++工程师综合练习卷》之小试牛刀
第一套练习之感受 刚刚注册了牛客网的账号,准备在此衡量一下水平,好好磨练一番.看到推荐练习<C/C++工程师综合练习卷>,oh,20道题,2个小时.由于木有经验,好一番紧张~ 结果用了20 ...