Aspose.Words 总结
生成答题卡
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;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理