首页 技术 正文
技术 2022年11月23日
0 收藏 770 点赞 4,860 浏览 3000 个字

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

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,965
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,486
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,331
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,114
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,747
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,781