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使用代码插入表格的更多相关文章

  1. C# 操作Word文本框——插入表格/读取表格/删除表格

    在文本框中,我们可以操作很多元素,如文本.图片.表格等,在本篇文章中将着重介绍如何插入表格到文本框,插入的表格我们可以对表格进行格式化操作来丰富表格内容.此外,对于文本框中的表格内容,我们也可以根据需 ...

  2. Ueditor 1.4.3 插入表格后无边框无颜色,不能正常显示

    在使用Ueditor 插入表格的功能时,发现插入时正常. 但保存到后台后再取出来,表格不能正常显示.查看保存的html代码,发现保存时并未给table 添加border属性.以致于再次取出来时,不能正 ...

  3. 用Twebbrowser做可控编辑器与MSHTML(插入表格)

    在插入表格问题上出现与结果想象不一样的问题.看代码 <table border="1" cellpadding="0" width="100%& ...

  4. markdown插入表格语法

    markdown插入表格语法 举例 如表格标题为,姓名,班级,成绩 标题内的内容为,yang,a班,100 我们要在markdow文件中插入表格 如 姓名|班级|成绩 -|-|- yang|a班|10 ...

  5. 地图中插入表格——ArcMap篇

    在制作专题图的过程中,不但要有地理要素表示空间位置,经常还要在图的周围制作一些表格数据.这里对ArcMap中的插入方法进行总结. 方法一:插入对象 利用菜单中的"插入"-" ...

  6. Word里插入表格不带左右边框

    插入表格后选中,然后开始-----段落------选择右下角的边框设置,选择无左右边框.

  7. richTextBox插入表格

    附件:http://files.cnblogs.com/xe2011/richTextBox_InsertTable.rar 插入表格 /// <summary> /// 插入表格 /// ...

  8. 13LaTeX学习系列之---LaTeX插入表格

    目录 目录 前言 (一)插入表格的基础语法 1.说明 2.源代码 3.输出效果 (二)查看文档 目录 本系列是有关LaTeX的学习系列,共计19篇,本章节是第13篇. 前一篇:12LaTeX学习系列之 ...

  9. 获取刚刚插入表格的这条信息的自增ID

    获取刚刚插入表格的这条信息的自增ID var conn=getConnection(); var msql="INSERT INTO " + table +" (&quo ...

随机推荐

  1. C#入门(2)

    C#入门(2) Exception 基本异常的核心成员: System.Exception Property Meaning Data read-only,实现了IDirectory接口的一些键值对, ...

  2. 剑指offer——把字符串转换成整数(c++)

    题目描述请你写一个函数StrToInt,实现把字符串转换成整数这个功能.当然,不能使用atoi或者其他类似的库函数. 示例 1:输入: " -42"输出: -42解释: 第一个非空 ...

  3. 2010: C语言实验——逆置正整数

    2010: C语言实验——逆置正整数 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 949  Solved: 691[Submit][Status][We ...

  4. myna代码

    https://github.com/TalkingData/Myna/tree/master/Dataset https://github.com/TalkingData/Myna

  5. CPP-基础:strcpy之于C++(

    以下对strcpy函数错误的是? char atr1[]="string"; ]; char *str3; char *str4="sting"; A.strc ...

  6. shell脚本,计算从0+2+4+6+....100的结果是多少?

    [root@localhost wyb]# cat evenjia.sh #!/bin/bash #从0++++...100的结果 i= ` do sum=$(($sum+i)) i=$(($i+)) ...

  7. Codeforces Round #510 #A

    http://codeforces.com/contest/1042/problem/A 题目大意就是: 现在公园里有n个长椅(要多长有多长),第i个长椅上有a[i]个人(泰山崩于前而不乱),现在又有 ...

  8. (43)zabbix报警媒介介绍

    zabbix触发器到了要发送通知的情况下,需要一个中间介质来接收并传递它的消息给运维们,以往用nagios,通常用脚本发送邮件或者发送飞信来达到报警.这个脚本实际上就是一个媒介了. zabbix有如下 ...

  9. The US in understimating Huawei, says founder Ren zhengfei

    Huawei Founder Ren Zhengfei has downplayed the impact of the US executive order that cripple Huawei' ...

  10. Template--模板

    模板引擎的支持 配置 模板引擎配置为TEMPLATES设置.这是一个配置列表,每个引擎一个,默认值为空.这是settings.py生成的,通过startproject命令定义了一个更有用的值: TEM ...