public ResultResponse<string[]> PrintStudyRecords([FromBody]StudyInfo info)
{
ResultResponse<string[]> ret = new ResultResponse<string[]>();
if (info.ProjectId <= )
{
ret.Flag = false;
return ret;
}
var project = ProjectContract.GetFilterProject(p => p.Id == info.ProjectId).FirstOrDefault();
if (project == null)
{
ret.Flag = false;
return ret;
}
var trainTarget = TrainTargetContract.GetFilterTrainTargets(t => t.Id == project.TrainTargetId).FirstOrDefault();
var studyRecords = StudyRecordsContract.GetList(s => s.ProjectId == info.ProjectId && s.IsFinish && !s.IsDelete).ToList();
Document doc;
using (var stream = System.IO.File.OpenRead(HttpContext.Current.Server.MapPath("/Content/学时记录.docx")))
{
doc = new Document(stream);
}
doc.Range.Replace(string.Format("${0}$", "Name"), LoginUser.Name, false, false);
doc.Range.Replace(string.Format("${0}$", "PersonalId"), LoginUser.PersonalId, false, false);
doc.Range.Replace(string.Format("${0}$", "Sex"), string.IsNullOrWhiteSpace(LoginUser.Sex) ? "" : LoginUser.Sex, false, false);
doc.Range.Replace(string.Format("${0}$", "PhoneNum"), string.IsNullOrWhiteSpace(LoginUser.Tel) ? "" : LoginUser.Tel, false, false);
doc.Range.Replace(string.Format("${0}$", "Company"), string.IsNullOrWhiteSpace(project.Company) ? "" : project.Company, false, false);
doc.Range.Replace(string.Format("${0}$", "TrainTargetName"), trainTarget != null ? trainTarget.TrainName : "", false, false);
doc.Range.Replace(string.Format("${0}$", "AllHours"), studyRecords.Count().ToString(), false, false);
        //获取指定表格 2指的是表格下标,一共有三个,我需要改变内容的是第三个表格
Table tableRecord = (Table)doc.GetChild(NodeType.Table, , true);
if (tableRecord == null)
{
var op = new ImageSaveOptions(SaveFormat.Jpeg);
op.PrettyFormat = true;
ret.Result = new string[doc.PageCount];
for (var page = ; page < doc.PageCount; page++)
{
op.PageIndex = page;
using (var ms = new MemoryStream())
{
doc.Save(ms, op);
ret.Result[page] = "data:image/jpeg;base64," + Convert.ToBase64String(ms.GetBuffer());
}
}
ret.Flag = false;
return ret;
}
if (studyRecords.Count() > )
{
for (int i = ; i < studyRecords.Count - ; i++)
{
//克隆指定行
Row clonedRow = (Row)tableRecord.LastRow.Clone(true);
//在指定位置插入克隆行
tableRecord.AppendChild(clonedRow);
}
}
var rowIndex = ;
ZhuJian.Entity.TrainManage.StudyRecord studyRecord = null;
for (int i = ; i < studyRecords.Count; i++)
{
studyRecord = studyRecords[i];
rowIndex = i + ;
var row = tableRecord.Rows[rowIndex]; var cell0 = row.Cells[];
Paragraph pg0 = new Paragraph(doc);
pg0.AppendChild(new Run(doc, rowIndex + ""));
cell0.RemoveAllChildren();
cell0.AppendChild(pg0); var cell1 = row.Cells[];
Paragraph pg1 = new Paragraph(doc);
pg1.AppendChild(new Run(doc, studyRecord.StartTime.ToString("yyyy/MM/dd") + "-" + (studyRecord.EndTime.HasValue ? studyRecord.EndTime.Value.ToString("yyyy/MM/dd") : "")));
cell1.RemoveAllChildren();
cell1.AppendChild(pg1); var cell2 = row.Cells[];
Paragraph pg2 = new Paragraph(doc);
pg2.AppendChild(new Run(doc, studyRecord.ResourceName));
cell2.RemoveAllChildren();
cell2.AppendChild(pg2); var cell3 = row.Cells[];
Paragraph pg3 = new Paragraph(doc);
pg3.AppendChild(new Run(doc, studyRecord.IsFinish ? "" : ""));
cell3.RemoveAllChildren();
cell3.AppendChild(pg3);
}
var option = new ImageSaveOptions(SaveFormat.Jpeg);
option.PrettyFormat = true;
ret.Result = new string[doc.PageCount];
for (var page = ; page < doc.PageCount; page++)
{
option.PageIndex = page;
using (var ms = new MemoryStream())
{
doc.Save(ms, option);
ret.Result[page] = "data:image/jpeg;base64," + Convert.ToBase64String(ms.GetBuffer());
}
}
ret.Flag = true;
return ret;
}

C# Aspose.Words 数据写入到word,模板样式复杂(转换指定内容并返回多张图片)的更多相关文章

  1. 将excel中的数据填入word模板中-VBA

    首先将word模板中需要填写excel中数据的空白处用自己独特的字符串标记,比如   数据001  什么的.如下图: 这样,就可以用vba搜寻这些自己独特的标记来根据excel内容填充word了. 第 ...

  2. Python中 将数据插入到Word模板并生成一份Word

    搬运出处: https://blog.csdn.net/DaShu0612/article/details/82912064

  3. c#读取Word模板,利用书签替换内容包括表格

    //生成WORD程序对象和WORD文档对象 Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Inter ...

  4. Java将数据写入word文档(.doc)

    Java可用org.apache.poi包来操作word文档.org.apache.poi包可于官网上下载,解压后各jar作用如下图所示: 可根据需求导入对应的jar. 一.HWPFDocument类 ...

  5. 读取word模板,填充数据后导出

    一.需求说明 定期生成word报告,报告中含有文本.表格.图表等元素,依次获取进行替换,保留原有样式,生成新的word文档 二.引入依赖 <dependency> <groupId& ...

  6. java通过word模板生成word文档

    介绍 上次公司项目需要一个生成word文档的功能,有固定的模板根据业务填充数据即可,由于从来没做过,项目也比较着急于是去网上找有没有合适的工具类,找了好几种,看到其中有freeMark模板生成比较靠谱 ...

  7. 把数据输出到Word (非插件形式)

    项目开发过程中,我们要把数据以各种各样的形式展现给客户.把数据以文档的形式展现给客户相信是一种比较头疼的问题,如果没有好的方法会 使得我的开发繁琐,而且满足不了客户的需求.接下来我会通过两种开发方式介 ...

  8. 前端数据渲染及mustache模板引擎的简单实现

    早期数据渲染的几种方式 在模板引擎没有诞生之前,为了用JS把数据渲染到页面上,诞生了一系列数据渲染的方式. 最最基础的,莫过于直接使用DOM接口创建所有节点. <div id="roo ...

  9. POI往word模板中写入数据

    转: POI往word模板中写入数据 2018年03月24日 16:00:22 乄阿斗同學 阅读数:2977  版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn ...

随机推荐

  1. Git--03 git分支

    目录 Git分支 1.新建testing分支 2.合并分支 3.合并冲突 4.删除分支 Git标签使用 1.查看标签 02.删除标签 Git分支 ​ 分支即是平行空间,假设你在为某个手机系统研发拍照功 ...

  2. poland 波兰 时区

    http://www.timeofdate.com/country/Poland 2019年 ~ 2020年波兰夏令时开始结束时间 年份 日期 类型 2019 2019-3-31 夏令时开始   20 ...

  3. Mystery——团队作业——系统设计

    这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass1 这个作业要求在哪里 https://edu.cnblo ...

  4. Sass函数-值列表index

    ndex() 函数类似于索引一样,主要让你找到某个值在列表中所处的位置.在 Sass 中,第一个值就是1,第二个值就是 2,依此类推: >> index(1px solid red, 1p ...

  5. canvas 图片反色

    代码实例: <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <tit ...

  6. javascript 回到顶部效果的实现

    demo.js window.onload=function() { var timer=null; var obtn=document.getElementById('btn'); var isTo ...

  7. python3 变量格式化转换成字符串

    num=3 str='I am %f years old' % (num) print(str) 输出 I am 3.000000 years old

  8. python 利用subprocess调用cmd命令程序,并正确输出控制台的输出中文

    平台Python3.7 1.利用控制台运行程序后在控制台会输出中文提示,但是用python调用subprocess.run函数后返回的输出是乱码,于是,解决方法是用subprocess.check_o ...

  9. python代码整体左移或右移

    IDE 是  PyCharm 选中代码块: 1)右移:直接 Tab 2)左移:Shift + Tab

  10. CDH6.3 Centos7

    按照官方文档安装即可 CentOS7 上搭建 CDH(6.3.0) 官方文档:https://docs.cloudera.com/documentation/enterprise/6/6.3/topi ...