-
C#教程之C#教程之使用aspose.word 第三方的插件实现导出wo
本站最新发布 C#从入门到精通
试听地址 https://www.xin3721.com/eschool/CSharpxin3721/
试听地址 https://www.xin3721.com/eschool/CSharpxin3721/
使用aspose.word 第三方的插件实现服务器端无需安装office组件导出word的功能
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
#region 生成的excel文件命名和确保文件的唯一性 Random rd = new Random(); DateTime dtime = DateTime.Now; string Filename = "培训需求表" + dtime.Year.ToString() + dtime.Month.ToString() + dtime.Day.ToString() + dtime.Hour.ToString() + dtime.Minute.ToString() + dtime.Second.ToString() + Convert.ToString(rd.Next(99) * 97 + 100) + ".doc" ; #endregion #region 定义变量 //建立Document物件,调用模块对word字体和table格式设置 string serverpath = Constants.GetAppSettingValue( "LocalLogicPath" ) + Constants.GetAppSettingValue( "LocalTemplate" ) + "px_xqjh_tx.doc" ; Document doc = new Document(serverpath); //建立DocumentBuilder物件 DocumentBuilder builder = new DocumentBuilder(doc); #endregion #region 页面设置,设置页面为横向布局,设置纸张类型为A4纸或通过页面的宽度设置 //设置纸张布局 builder.PageSetup.PaperSize = PaperSize.A4; //builder.PageSetup.Orientation = Aspose.Words.Orientation.Landscape; #endregion #region 设置word全局的字体样式和字体大小 builder.RowFormat.Borders.LineStyle = LineStyle.Thick; builder.RowFormat.HeightRule = HeightRule.Auto; builder.RowFormat.Alignment = RowAlignment.Center; //builder.Font.Name = "仿宋-GB2312"; builder.Font.Name = "宋体" ; builder.Font.Size = 10.5; //五号 #endregion List< double > widthList = new List< double >(); double remarkWidth = 0; for ( int k = 0; k < 18; k++) { builder.MoveToCell(0, 1, k, 0); //移动单元格 double width = builder.CellFormat.Width; //获取单元格宽度 widthList.Add(width); remarkWidth += width; //Universal.ExceptionLog(k.ToString(), width.ToString()); } DataTable dtable = GetQuestionList(); if (dtable != null && dtable.Rows.Count > 0) { #region 绘制表格以及设置--------- 开头 doc.Range.Bookmarks[ "tbdw" ].Text = this .lblcom.Text; builder.MoveToBookmark( "pxtx" ); //开始添加值 Aspose.Words.Tables.Table table = builder.StartTable(); builder.RowFormat.HeadingFormat = true ; builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; #endregion #region 数据集 for ( int i = 0; i < dtable.Rows.Count; i++) { for ( int j = 0; j < dtable.Columns.Count - 3; j++) { #region 列 builder.InsertCell(); // 添加一个单元格 builder.CellFormat.Borders.LineStyle = LineStyle.Single; builder.CellFormat.Borders.Color = System.Drawing.Color.Black; builder.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.FromArgb(255, 255, 255); builder.CellFormat.Width = widthList[j]; builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None; builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Top; //垂直居中对齐 builder.ParagraphFormat.Alignment = ParagraphAlignment.Left; //水平居中对齐 builder.Write(dtable.Rows[i][j].ToString().Trim()); //Universal.ExceptionLog((i + 1).ToString() + "*" + (j + 1).ToString(), dtable.Rows[i][j].ToString().Trim()); #endregion } builder.EndRow(); } #endregion #region 备注列 builder.InsertCell(); // 添加一个单元格 builder.CellFormat.Borders.LineStyle = LineStyle.Single; builder.CellFormat.Borders.Color = System.Drawing.Color.Black; builder.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.FromArgb(255, 255, 255); builder.CellFormat.Width = remarkWidth; builder.RowFormat.Height = 50; builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None; builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Top; //垂直居中对齐 builder.ParagraphFormat.Alignment = ParagraphAlignment.Left; //水平居中对齐 builder.Write( "备注:" ); builder.EndRow(); #endregion #region 绘制表格以及设置--------- 结尾 builder.EndTable(); doc.Range.Bookmarks[ "pxtx" ].Text = "" ; // 清掉标示 #endregion #region 计划编制和审批人 doc.Range.Bookmarks[ "writername" ].Text = dtable.Rows[0][ "reg_staff_name" ].ToString(); doc.Range.Bookmarks[ "checkname" ].Text = dtable.Rows[0][ "check_man_name" ].ToString(); #endregion } dtable.Dispose(); #region 保存数据. doc.Save(Filename, SaveFormat.Doc, SaveType.OpenInWord, Response); //保存为doc,并打开 #endregion |
栏目列表
最新更新
如何使用OS模块中的stat方法
Python os 模块
seek() 方法
python打开文件实例1
Python写入文件
什么是流?
文件操作如何进制逐行读取
Python相对路径
with创建临时运行环境
Python文件操作
.Net Standard(.Net Core)实现获取配置信息
Linux PXE + Kickstart 自动装机
Shell 编程 基础
Shell 编程 条件语句
CentOS8-网卡配置及详解
Linux中LVM逻辑卷管理
1.数码相框-相框框架分析(1)
Ubuntu armhf 版本国内源
Linux中raid磁盘阵列
搭建简易网站
access教程之Access简介
mysql 安装了最新版本8.x版本后的报错:
Mysql空间数据&空间索引(spatial)
如何远程连接SQL Server数据库的图文教程
复制SqlServer数据库的方法
搜索sql语句
sql中返回参数的值
sql中生成查询的模糊匹配字符串
数据定义功能
数据操作功能