Aspose.Words 总结

时间:2024-10-21 09:04:02

生成答题卡

try
{
string tempPath = @"D:\moban\ttt.doc";

//Open document and create Documentbuilder
//Aspose.Words.Document doc = new Aspose.Words.Document();
//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;
//builder.MoveToCell(0, 2, i, 0); //移动单元格
// etc...
//Move documentBuilder cursor to the bookmark
//builder.MoveToBookmark("myBookmark");
//Insert some table

//builder.RowFormat.Height = 20;
//builder.CellFormat.Width = 10;
//builder.InsertCell();
//builder.EndTable();

string t1 = "D:\\moban\\temp1.doc";
string t2 = "D:\\moban\\temp2.doc";
Document dstDoc = new Document(t1);

DocumentBuilder builder = new DocumentBuilder(dstDoc);
for (int i = 0; i < 5; i++)
{
Document edite = new Document(t2);
String[] key = new String[] { "titles" };
Object[] value = new Object[] { i + "(5分)" };
//合并模版,相当于页面的渲染
edite.MailMerge.Execute(key, value);

edite.FirstSection.PageSetup.SectionStart = SectionStart.Continuous;
dstDoc.AppendDocument(edite, ImportFormatMode.KeepSourceFormatting);
}

//使用域的方式填充数据
String[] fieldNames = new String[] { "dtkname", "d01", "d02", "d03", "d04", "d05", "d06", "d07", "d08", "d09", "d10", "d11", "d12", "d13", "d14", "d15", "d01a", "d02a", "d03a", "d04a", "d05a", "d06a", "d07a", "d08a", "d09a", "d10a", "d11a", "d12a", "d13a", "d14a", "d15a", "titles" };
Object[] fieldValues = new Object[] { "物理月考试卷", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "", "abcd", "abcd", "abcd", "abcd", "abcd", "abcd", "abcd", "abcd", "abcd", "abcd", "abcd", "abcd", "abcd", "abcd", "", "3(5分)" };
//合并模版,相当于页面的渲染
dstDoc.MailMerge.Execute(fieldNames, fieldValues);
dstDoc.Save(tempPath);

}
catch (Exception)
{

throw;
}