分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

Aspose.Words导出图片 表格

发布时间:2023-09-06 01:14责任编辑:胡小海关键词:暂无标签

先定义一个WORD 模板, 然后替换文本、域 ,定位开始表格

单元格

 ???????/// <summary> ???????/// 添加单元格 ???????/// </summary> ???????/// <param name="builder"></param> ???????/// <param name="data"></param> ???????/// <param name="width"></param> ???????public static void InsertCell(DocumentBuilder builder, string data, double width) ???????{ ???????????builder.InsertCell(); ???????????builder.RowFormat.Height = 22; ???????????builder.CellFormat.Width = width; ???????????builder.CellFormat.Borders.LineStyle = LineStyle.Single; ???????????builder.CellFormat.Borders.Color = System.Drawing.Color.Black; ???????????builder.CellFormat.VerticalMerge = CellMerge.None; ???????????builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; ???????????builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;//水平居中 ???????????builder.Font.Size = 8; ???????????//builder.Font.Bold = true; ???????????builder.Write(data); ???????}
View Code

图片单元格

 ???????/// <summary> ???????/// 添加带图片的单元格 ???????/// </summary> ???????/// <param name="doc">word文档</param> ???????/// <param name="builder"></param> ???????/// <param name="strUrl">图片路径</param> ???????/// <param name="width">单元格宽度</param> ???????/// <param name="height">单元格高度</param> ???????/// <param name="tableIndex">表索引</param> ???????/// <param name="rowIndex">行索引</param> ???????/// <param name="columnIndex">列索引</param> ???????private static void InsertCellWithImage(Document doc, DocumentBuilder builder, string strUrl, double width, double height, int rowIndex, int columnIndex) ???????{ ???????????builder.InsertCell(); ???????????builder.RowFormat.Height = height; ???????????builder.CellFormat.Width = width; ???????????builder.CellFormat.Borders.LineStyle = LineStyle.Single; ???????????builder.CellFormat.Borders.Color = System.Drawing.Color.Black; ???????????builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; ???// 垂直居中 ???????????builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; ?// 水平居中 ???????????if (File.Exists(HttpContext.Current.Server.MapPath(strUrl))) ???????????{ ???????????????// 向此单元格中插入图片 ???????????????Shape shape = new Shape(doc, ShapeType.Image); ???????????????shape.ImageData.SetImage(HttpContext.Current.Server.MapPath(strUrl)); ???????????????shape.Width = width - 5; ???????????????shape.Height = height-5; ???????????????shape.HorizontalAlignment = HorizontalAlignment.Center; ???????????????shape.VerticalAlignment = VerticalAlignment.Center; ???????????????builder.InsertNode(shape); ???????????} ???????}
View Code

表格--书签位置

 ???????????DocumentBuilder builder = new DocumentBuilder(doc); ???????????????????????builder.MoveToBookmark("table"); //移动到书签 ???????????builder.StartTable(); ???????????builder.CellFormat.Shading.BackgroundPatternColor = Color.Yellow; ???????????InsertCell(builder, "测试", 235); ???????????builder.EndRow(); ???????????builder.CellFormat.Shading.BackgroundPatternColor = Color.White; ???????????builder.EndTable(); ???????????
View Code

替换:  插入-文本部件-域

 ???????????string[] fieldNames = { ?"Test01","Test02"}; ???????????object[] fieldValues = { ?"Test01","Test02"}; ???????????fieldValues[0]="测试01"; ???????????fieldValues[1]="测试02"; ???????????
View Code
 ???????????doc.MailMerge.Execute(fieldNames, fieldValues); ???????????doc.MailMerge.DeleteFields(); ?????????????string strPhysicsPath = HttpContext.Current.Server.MapPath(DocPath); ???????????if (!Directory.Exists(strPhysicsPath)) ???????????{ ???????????????Directory.CreateDirectory(strPhysicsPath); ???????????} ???????????string tempUrl = "/" + strProjName + filename + ".doc"; ???????????strPhysicsPath = strPhysicsPath.TrimEnd(‘\\‘) + tempUrl; ???????????if (Directory.Exists(strPhysicsPath)) ???????????{ ???????????????File.Delete(strPhysicsPath); ???????????} ???????????doc.Save(strPhysicsPath, SaveFormat.Docx); ???????????return ?tempUrl; ?????????????
View Code

 用Aspose.Words把word转成图片

Document doc = new Document("f:\\333.doc");ImageSaveOptions iso = new ?????????ImageSaveOptions(SaveFormat.Jpeg);iso.Resolution = 128;iso.PrettyFormat = true;iso.UseAntiAliasing = true;for (int i = 0; i < doc.PageCount; i++){ ???????iso.PageIndex = i; ????????doc.Save("D:/test/test" + i + ".jpg", iso);}
View Code

    

Aspose.Words导出图片 表格

原文地址:http://www.cnblogs.com/love201314/p/7612100.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved