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 ...
随机推荐
- 关于JWT中RSA数据加密协议在.net中应用
加密协议有哪些 加密协议分为对称加密和非对称加密. 对称加密就是将信息使用一个密钥进行加密,解密时使用同样的密钥,同样的算法进行解密. 非对称加密,又称公开密钥加密,是加密和解密使用不同密钥的算法,广 ...
- tesseract-ocr 安装、语言库、使用 随记
前几日才听说ocr的图片识别功能.觉得很有意思.先体验一下. 地址: GitHub - tesseract-ocr/tesseract: Tesseract Open Source OCR Engin ...
- 继承方式创建线程(继承Thread类)
步骤: 用类继承Thread类 重写run()方法 在测试类中创建Thread的子类对象 通过此对象调用Start //1.类继承Thread public class AAA extends Thr ...
- FTP主动模式(Port)和被动模式(Passive)的区别
1.FTP的PORT(主动模式): PORT中文称为主动模式,工作的原理: FTP客户端(1024以上端口)连接到FTP服务器的21端口,发送用户名和密码登录, 登录成功后要list列表或者读取数据时 ...
- 使用ts二次封装storage(sessionStorage/localStorage)
export class LocalCache { setCache<T = any>(key: string, value: T): boolean; setCache<T = a ...
- Winfrom ComboBox中的性能探索
在为Control维护元素列表的过程中,会不可避免的造成性能损耗,我们接下来要探究的就是哪种方式才是我们的最优解. 方案比较 以ComboBox为例,常见的方式一共有两种:Add.AddRange. ...
- MAYA专用卸载工具,完全彻底卸载删除干净maya各种残留注册表和文件的方法和步骤
maya专用卸载工具,完全彻底卸载删除干净maya各种残留注册表和文件的方法和步骤.如何卸载maya呢?有很多同学想把maya卸载后重新安装,但是发现maya安装到一半就失败了或者显示maya已安装或 ...
- 《Python深度学习》《卷积神经网络的可视化》精读
对于大多数深度学习模型,模型学到的表示都难以用人类可以理解的方式提取和呈现.但对于卷积神经网络来说,我们可以很容易第提取模型学习到的表示形式,并以此加深对卷积神经网络模型运作原理的理解. 这篇文章的内 ...
- ES得分
一.概念 1.ES主要用于搜索 2.搜索要把更有相关性的结果展示出来 3.对一个文档评分,相关性越大,评分越高 4.打分的本质是排序 二.评分规则 1.ES5之前,默认评分规则是TF-IDF,这是信息 ...
- Redis缓存雪崩,击穿和穿透
这三个问题的发生,会导致大量的请求直接积压到数据库,如果并发量很大,则可能会导致数据库宕机或故障. 缓存雪崩 描述:大量的请求无法在redis缓存中进行处理而被发送到数据库,导致数据库压力陡增. ...