解决用Aspose.Words,在word文档中创建表格的实现方法
程序员文章站
2023-12-17 23:45:46
代码如下所示:复制代码 代码如下: //open document and create documentbuilder aspose.words....
代码如下所示:
//open document and create documentbuilder
aspose.words.document doc = new aspose.words.document("demo.doc");
documentbuilder builder = new documentbuilder(doc);
//set table formating
//set borders
builder.cellformat.borders.linestyle = linestyle.single;
builder.cellformat.borders.color = color.red;
//set left indent
builder.rowformat.leftindent = 100;
// etc...
//move documentbuilder cursor to the bookmark
builder.movetobookmark("mybookmark");
//insert some table
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
builder.insertcell();
builder.write("this is cell");
}
builder.endrow();
}
builder.endtable();
//save output document
doc.save("demo2.doc");
复制代码 代码如下:
//open document and create documentbuilder
aspose.words.document doc = new aspose.words.document("demo.doc");
documentbuilder builder = new documentbuilder(doc);
//set table formating
//set borders
builder.cellformat.borders.linestyle = linestyle.single;
builder.cellformat.borders.color = color.red;
//set left indent
builder.rowformat.leftindent = 100;
// etc...
//move documentbuilder cursor to the bookmark
builder.movetobookmark("mybookmark");
//insert some table
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
builder.insertcell();
builder.write("this is cell");
}
builder.endrow();
}
builder.endtable();
//save output document
doc.save("demo2.doc");