aspose word导出表格
[HttpGet]
[Route("GetPurchaseItemWord")]
public IHttpActionResult Get_PurchaseItemWord(string id)
{
#region 文件流
var model = _purchaseRepository.Get(id);
var purchaseDetail = _purchasedetailRepository.GetDetails(model.id);
ItemPurchaseViewModel purchaseVM = new ItemPurchaseViewModel();
purchaseVM = Mapper.Map<im_purchase, ItemPurchaseViewModel>(model);
purchaseVM.itemList = purchaseDetail;
var predicateTrail = Predicates.Field<wf_flow_trail>(f => f.business_id, Operator.Eq, model.id);
var flow_trail = _trailRepository.GetList(predicateTrail).OrderBy(a => a.create_date).ToList();
IList<ISort> sort = new List<ISort>()
{
Predicates.Sort<wf_flow_node>(x => x.create_date)
};
var flow_node = _nodeRepository.GetList(Predicates.Field<wf_flow_node>(x => x.flow_id, Operator.Eq, "14e84dba-8546-46b0-989e-0ee1312345ad"), sort).ToList();
flow_node = flow_node.Where(a => a.id != "20").ToList();
purchaseVM.flow_node = Mapper.Map<List<wf_flow_node>, List<flow_node>>(flow_node); try
{
string Path = AppDomain.CurrentDomain.RelativeSearchPath + "\\" + "Templet";
Path = Path.Replace("\\bin\\", "\\");
string templatePath = Path + "\\impurchaseTml.doc"; //自己做好的word
Document WordDoc = new Document(templatePath); DocumentBuilder builder = new DocumentBuilder(WordDoc);
builder.MoveToBookmark("impurchase");
if (WordDoc.Range.Bookmarks["impurchase"] != null)
{
var table = builder.StartTable();
//设置文本垂直居中
builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
//设置字体大小
Aspose.Words.Font f = builder.Font;
f.Size = 12;
builder.InsertCell();
builder.CellFormat.Width = 35; builder.Write("序号");
builder.InsertCell();
builder.CellFormat.Width = 100; builder.Write("名称");
builder.InsertCell();
builder.CellFormat.Width = 70; builder.Write("规格型号");
builder.InsertCell();
builder.CellFormat.Width = 40; builder.Write("数量");
builder.InsertCell();
builder.CellFormat.Width = 45; builder.Write("单价");
builder.InsertCell();
builder.CellFormat.Width = 70; builder.Write("总计");
builder.InsertCell();
builder.CellFormat.Width = 112; builder.Write("备注");
builder.EndRow();
decimal? money = 0;
foreach (var item in purchaseDetail)
{
builder.InsertCell();
builder.CellFormat.Width = 35; builder.Write((purchaseDetail.IndexOf(item)+1).ToString());
builder.InsertCell();
builder.CellFormat.Width = 100; builder.Write(item.name);
builder.InsertCell();
builder.CellFormat.Width = 70; builder.Write(item.specification != null ? item.specification : "");
builder.InsertCell();
builder.CellFormat.Width = 40; builder.Write(item.quantity.ToString());
builder.InsertCell();
builder.CellFormat.Width = 45; builder.Write(item.price.ToString());
builder.InsertCell();
builder.CellFormat.Width = 70; builder.Write((item.quantity*item.price).ToString());
builder.InsertCell();
builder.CellFormat.Width = 112; builder.Write(item.remark != null ? item.remark : "");
money += item.price * item.quantity;
builder.EndRow();
}
f.Size = 16;
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.First;//合并单元格开始
builder.CellFormat.Width = 35; builder.Write("预计总额");
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.CellFormat.Width = 100;
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.None; //合并单元格结束
builder.CellFormat.HorizontalMerge = CellMerge.First;
builder.CellFormat.Width = 70; builder.Write(money.ToString());
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.CellFormat.Width = 40;
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.CellFormat.Width = 45;
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.CellFormat.Width = 70;
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.CellFormat.Width = 112;
builder.EndRow();
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.First;
builder.CellFormat.Width = 35; builder.Write("使用说明");
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.CellFormat.Width = 100;
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.None; builder.CellFormat.HorizontalMerge = CellMerge.First;
builder.CellFormat.Width = 70; builder.Write(model.remark);
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.CellFormat.Width = 40;
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.CellFormat.Width = 45;
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.CellFormat.Width = 70;
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.CellFormat.Width = 112;
builder.EndRow(); builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.First;
builder.CellFormat.Width = 35; builder.Write("申请人");
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.CellFormat.Width = 100;
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.None; builder.CellFormat.HorizontalMerge = CellMerge.First;
builder.CellFormat.Width = 70; builder.Write(model.create_user);
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.CellFormat.Width = 40;
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.First;
builder.CellFormat.Width = 45; builder.Write("申请时间");
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.CellFormat.Width = 70;
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.None;
builder.CellFormat.Width = 112; builder.Write(Convert.ToDateTime(model.create_date).ToString("yyyy年MM月dd日"));
builder.EndRow(); builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.First;
builder.CellFormat.Width = 35; builder.Write("申请部门");
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.CellFormat.Width = 100;
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.None; builder.CellFormat.HorizontalMerge = CellMerge.First;
builder.CellFormat.Width = 70; builder.Write(model.dept_name);
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.CellFormat.Width = 40;
foreach (var nodeitem in purchaseVM.flow_node)
{
var trail= flow_trail.Where(a => a.next_node_id == nodeitem.next_node).OrderByDescending(a => a.create_date).FirstOrDefault();
var filepath = (AppDomain.CurrentDomain.RelativeSearchPath).Replace("\\bin", "\\");
if (nodeitem.name== "后勤部门意见")
{
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.First;
builder.CellFormat.Width = 45; builder.Write("部门意见");
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.CellFormat.Width = 70;
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.None;
builder.CellFormat.Width = 112;
if (trail != null)
{
builder.Write(trail.approval != null ? trail.approval : "");
if (File.Exists(filepath + trail.sign_path))
{
builder.InsertImage(filepath + trail.sign_path, RelativeHorizontalPosition.Margin, 1, RelativeVerticalPosition.Margin, 1, 100, 40, WrapType.Square);//插入图片
}
}
builder.EndRow();
}
else
{
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.First;
builder.CellFormat.Width = 35; builder.Write(nodeitem.name);
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.CellFormat.Width = 100;
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.None; builder.CellFormat.HorizontalMerge = CellMerge.First;
builder.CellFormat.Width = 70;
if (trail != null)
{
builder.Write(trail.approval != null ? trail.approval : "");
if (File.Exists(filepath + trail.sign_path))
{
builder.InsertImage(filepath + trail.sign_path, RelativeHorizontalPosition.Margin, 1, RelativeVerticalPosition.Margin, 1, 100, 40, WrapType.Square);
}
} builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.CellFormat.Width = 40;
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.CellFormat.Width = 45;
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.CellFormat.Width = 70;
builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.CellFormat.Width = 112;
builder.EndRow();
}
}
table.AutoFit(AutoFitBehavior.FixedColumnWidths);
builder.EndTable(); table.Alignment = TableAlignment.Center;
//表格居中、固定宽高
} string sPath = AppDomain.CurrentDomain.RelativeSearchPath + "\\" + "UploadFile";
sPath = sPath.Replace("\\bin\\", "\\");
var fileName = "物品采购单" + DateTime.Now.ToString("yyyy-MM-dd") + ".doc";
fileName = HttpUtility.UrlEncode(fileName);
string filePath = sPath + "\\" + fileName;
WordDoc.Save(filePath);
var stream = FileToStream(filePath);
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
result.Content = new StreamContent(stream);
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.ms-excel");
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
result.Content.Headers.ContentDisposition.FileName = fileName;
return ResponseMessage(result); }
catch (Exception e)
{
//return new HttpResponseMessage(HttpStatusCode.NoContent);
return Json(new { success = false, message = "导出有误,请联系管理员!" });
}
#endregion
}
aspose word导出表格的更多相关文章
- Aspose.Word 输出表格后空格字符丢失的解决方法
将datatable输出到word,执行如下代码. doc.MailMerge.ExecuteWithRegions(outDt); 执行完后发现第一列含前缀空格的字段值,空格字符被自动清除了. 解决 ...
- Aspose.Words导出图片 表格 Interop.Word
先定义一个WORD 模板, 然后替换文本.域 ,定位开始表格 文本和段落 // Specify font formatting Aspose.Words.Font font = builder.Fon ...
- 利用Aspose.Word控件和Aspose.Cell控件,实现Word文档和Excel文档的模板化导出
我们知道,一般都导出的Word文档或者Excel文档,基本上分为两类,一类是动态生成全部文档的内容方式,一种是基于固定模板化的内容输出,后者在很多场合用的比较多,这也是企业报表规范化的一个体现. 我的 ...
- C#通过模板导出Word(文字,表格,图片)
C#通过模板导出Word(文字,表格,图片) C#导出Word,Excel的方法有很多,这次因为公司的业务需求,需要导出内容丰富(文字,表格,图片)的报告,以前的方法不好使,所以寻找新的导出方法, ...
- 通过Aspose.Word和ZXING生成复杂的WORD表格
1.前言 这是我之前做的一个项目中要求的功能模块,它的需求是生成一个WORD文档,需要每页一个表格并且表格中需要插入文字.条形码和二维码等信息,页数可控制.具体的效果如下图所示: 可以看到有以下几点是 ...
- 利用Aspose.Word控件实现Word文档的操作
Aspose系列的控件,功能都挺好,之前一直在我的Winform开发框架中用Aspose.Cell来做报表输出,可以实现多样化的报表设计及输出,由于一般输出的内容比较正规化或者多数是表格居多,所以一般 ...
- 黄聪:利用Aspose.Word控件实现Word文档的操作(转)
撰写人:伍华聪 http://www.iqidi.com Aspose系列的控件,功能都挺好,之前一直在我的Winform开发框架中用Aspose.Cell来做报表输出,可以实现多样化的报表设计及 ...
- 关于ASPOSE.WORD使用上的一个小问题
最近实习期间负责了公司某个项目的一个功能模块里面的word导出功能,使用的是ASPOSE.WORD类库,但是经常导出时候会遇到图中的问题,大概意思就是两个表格不能跨在一起,调试了好几次还是没发现具体的 ...
- aspose.word 使用简单方法
aspose.word使用简单方法 概念介绍 使用aspose生成word报表步骤: 加载word模板 提供数据源 填充 加载模板 提供了4种重载方法 1 2 3 4 5 public Documen ...
- Aspose.Word 的常见使用(2018-12-26 更新版)
Aspose.Word 的常见使用 起因 因项目需要,而且使用html转Word的时候,样式不兼容问题,于是只能使用Aspose.Word通过代码生成.下面是通过DocumentBuilder来设计W ...
随机推荐
- 靶场练习2:cloudantvirus
靶场链接 https://www.vulnhub.com/entry/boredhackerblog-cloud-av,453/ 信息收集 练习1用了arp-scan,这种工具有可能会被防火墙流量监测 ...
- pip国内镜像永久
一.Windows下永久设置pip镜像使用:# windows系统使用cmd(最好使用管理员权限运行)快速设置 pip install pip -U # 升级pip到最新版本 pip config s ...
- C# 生成二维码方法(QRCoder)
前言 二维码很多地方都有使用到.如果是静态的二维码还是比较好处理的,通过在线工具就可以直接生成一张二维码图片,比如:草料二维码. 但有的时候是需要动态生成的(根据动态数据生成),这个使用在线就工具就无 ...
- vue3 门户网站搭建2-ngnix
路由配好了,需要调试下 build 后是否可用,这时我们需要一个服务端来运行静态网页. 官网直接下载一个 windows 版本的 ngnix 即可: http://nginx.org/en/downl ...
- 00_k8s_learn
10本 Kubernetes 学习书籍推荐 - 知乎 https://zhuanlan.zhihu.com/p/468291559 Helm 的安装使用 · 从 Docker 到 Kubernetes ...
- top单核与32C--CPU爆表
linux的cpu使用频率是根据cpu个数和核数决定的 top, 然后你按一下键盘的1,这就是单个核心的负载,不然是所有核心的负载相加,自然会超过100 单核为100%,服务器是32核的,下面基本用了 ...
- vscode 中前端代码不能通过ctrl+鼠标左键点击跳转(亲测可行)
1.ctrl+p 查找 jsconfig.json文件.如果没有,就在根目录下新建jsconfig.json 2.若已经有文件,如下图新增paths 若没有,复制下面内容到jsconfig.json ...
- ls access.log.?.gz
因为日志文件每天都会打包, 所以昨天的问题可能就在今天的access.log/error.log文件里找不到了.如何找出个位数的log文件呢? 这里就有两种不同的匹配符号, *匹配多个, ?匹配一个, ...
- ubuntu - 程序运行的一些基础知识
1.指定编码格式 -finput-charset=GB2312 指定 C 程序的编码方式为 GB2312,不指定时默认编码方式为 UTF-8 -fexec-charset=GB2312 指定 可执行程 ...
- (转载)私人问卷收集系统-Surveyking问卷收集系统
前言 但凡提及问卷收集系统,问卷星与腾讯问卷通常都为大家首选问卷调查系统. 担心数据安全,海量问卷管理不便,工作流创建困难?快速部署自有问卷调查系统开始你的问卷调查之旅. 无论是问卷调查,考试系统,公 ...