标签:jpg nes pre 添加 alignment shape val test cal
先定义一个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); }
图片单元格
/// <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); } }
表格--书签位置
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();
替换: 插入-文本部件-域
string[] fieldNames = { "Test01","Test02"}; object[] fieldValues = { "Test01","Test02"}; fieldValues[0]="测试01"; fieldValues[1]="测试02";
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;
用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); }
标签:jpg nes pre 添加 alignment shape val test cal
原文地址:http://www.cnblogs.com/love201314/p/7612100.html