|
|
@@ -27,9 +27,6 @@ public class ExportWord
|
|
27
|
27
|
//context.Response.End();
|
|
28
|
28
|
|
|
29
|
29
|
}
|
|
30
|
|
-
|
|
31
|
|
-
|
|
32
|
|
-
|
|
33
|
30
|
public string CreateWord(string name)
|
|
34
|
31
|
{
|
|
35
|
32
|
string message = "";
|
|
|
@@ -65,12 +62,8 @@ public class ExportWord
|
|
65
|
62
|
WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
|
|
66
|
63
|
WordApp.Selection.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorBlack;
|
|
67
|
64
|
//文档中创建表格
|
|
68
|
|
- Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables.Add(WordApp.Selection.Range, 19, 9, ref Nothing, ref Nothing);
|
|
|
65
|
+ Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables.Add(WordApp.Selection.Range, 18, 9, ref Nothing, ref Nothing);
|
|
69
|
66
|
//设置表格样式
|
|
70
|
|
- WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
|
|
71
|
|
- //设置表格框
|
|
72
|
|
- // newTable.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
|
|
73
|
|
-
|
|
74
|
67
|
for (int i = 1; i < 10; i ++)
|
|
75
|
68
|
{
|
|
76
|
69
|
newTable.Columns[i].Width = 60f;
|
|
|
@@ -83,121 +76,73 @@ public class ExportWord
|
|
83
|
76
|
newTable.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
|
|
84
|
77
|
//表格内线
|
|
85
|
78
|
newTable.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
|
|
86
|
|
- ////填充表格内容
|
|
87
|
|
- //for (int k = 1; k< 19; k++)
|
|
88
|
|
- // {
|
|
89
|
|
- // newTable.Rows[k].Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
|
|
90
|
|
- // }
|
|
91
|
|
-
|
|
92
|
|
- // for (int k = 1; k< 15; k++)
|
|
93
|
|
- // {
|
|
94
|
|
- // newTable.Columns[k].Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
|
|
95
|
|
- // }
|
|
96
|
79
|
//垂直居中
|
|
97
|
80
|
object unit = Microsoft.Office.Interop.Word.WdUnits.wdLine;
|
|
98
|
81
|
object countjz = 1;
|
|
99
|
82
|
WordApp.Selection.MoveEnd(ref unit, ref countjz);
|
|
100
|
|
- WordApp.Selection.Cells.VerticalAlignment = Microsoft.Office.Interop.Word.WdCellVerticalAlignment.wdCellAlignVerticalBottom;//垂直居中
|
|
101
|
|
- //填充表格内容 第一行
|
|
|
83
|
+ WordApp.Selection.Cells.VerticalAlignment = Microsoft.Office.Interop.Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;//垂直居中
|
|
|
84
|
+ //填充表格内容 第一行
|
|
102
|
85
|
newTable.Cell(1, 1).Range.Text = "事项编号";
|
|
103
|
|
- //合并单元格
|
|
104
|
|
- // newTable.Cell(1, 1).Merge(newTable.Cell(1, 1));
|
|
105
|
86
|
newTable.Cell(1, 1).Merge(newTable.Cell(2, 1));
|
|
106
|
87
|
newTable.Cell(1, 2).Range.Text ="";//工单编号
|
|
107
|
88
|
newTable.Cell(1, 2).Merge(newTable.Cell(2, 3));
|
|
108
|
89
|
newTable.Cell(1, 3).Range.Text = "工单来源";
|
|
109
|
|
- // newTable.Cell(1, 3).Merge(newTable.Cell(1, 4));
|
|
110
|
90
|
newTable.Cell(1, 4).Range.Text = "";
|
|
111
|
|
- // newTable.Cell(1, 4).Merge(newTable.Cell(1, 5));
|
|
112
|
91
|
newTable.Cell(1, 5).Range.Text = "办理时限";
|
|
113
|
|
- // newTable.Cell(1, 5).Merge(newTable.Cell(1, 6));
|
|
114
|
92
|
newTable.Cell(1, 6).Range.Text = "";
|
|
115
|
|
- // newTable.Cell(1, 6).Merge(newTable.Cell(1, 7));
|
|
116
|
93
|
newTable.Cell(1, 7).Range.Text = "联系电话";
|
|
117
|
|
-
|
|
118
|
|
- // newTable.Cell(1, 9).Merge(newTable.Cell(3, 15));
|
|
119
|
|
- // newTable.Cell(1, 9).Select();//选中一行
|
|
120
|
|
- // string FileName = "E:\\OA\\new\\web2\\upload\\" + dat.Rows[0]["touxiang"].ToString();
|
|
121
|
|
- //object LinkToFile = false;
|
|
122
|
|
- // object SaveWithDocument = true;
|
|
123
|
|
- //object Anchor = WordDoc.Application.Selection.Range;
|
|
124
|
|
- // WordDoc.Application.ActiveDocument.InlineShapes.AddPicture(FileName, ref LinkToFile, ref SaveWithDocument, ref Anchor);
|
|
125
|
|
- // WordDoc.Application.ActiveDocument.InlineShapes[1].Width = 72f;//图片宽度
|
|
126
|
|
- // WordDoc.Application.ActiveDocument.InlineShapes[1].Height = 90f;//图片高
|
|
127
|
|
- // WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
|
|
128
|
|
-
|
|
129
|
|
- // 填充表格内容 第二行
|
|
130
|
|
-
|
|
131
|
94
|
newTable.Cell(2, 3).Range.Text = "签收时间";
|
|
132
|
|
-
|
|
133
|
95
|
newTable.Cell(2, 4).Range.Text = "";
|
|
134
|
|
-
|
|
135
|
96
|
newTable.Cell(2, 5).Range.Text = "办理时间";
|
|
136
|
|
-
|
|
137
|
97
|
newTable.Cell(2, 6).Range.Text = "";
|
|
138
|
|
-
|
|
139
|
|
- newTable.Cell(2, 7).Range.Text = "来电人";
|
|
140
|
|
- //填充表格内容 第三行
|
|
141
|
|
- newTable.Cell(3, 1).Range.Text = "事项区域";
|
|
142
|
|
- // newTable.Cell(3, 1).Merge(newTable.Cell(3, 3));
|
|
|
98
|
+ newTable.Cell(2, 7).Range.Text = "来电人";
|
|
|
99
|
+ newTable.Cell(3, 1).Range.Text = "事项区域";
|
|
143
|
100
|
newTable.Cell(3, 2).Range.Text = "";
|
|
144
|
101
|
newTable.Cell(3, 2).Merge(newTable.Cell(3, 9));
|
|
145
|
102
|
//填充表格内容 第四行
|
|
146
|
103
|
newTable.Cell(4, 1).Range.Text = "内容摘要";
|
|
147
|
104
|
newTable.Cell(4, 1).Merge(newTable.Cell(7, 1));
|
|
148
|
|
- newTable.Cell(4, 2).Range.Text ="";
|
|
|
105
|
+ newTable.Cell(4, 2).Range.Text =" ";
|
|
149
|
106
|
newTable.Cell(4, 2).Merge(newTable.Cell(7, 9));
|
|
150
|
|
-
|
|
151
|
|
- newTable.Cell(8, 1).Range.Text = "承办单位";
|
|
152
|
|
- newTable.Cell(8, 2).Range.Text = "";
|
|
153
|
|
- newTable.Cell(8, 2).Merge(newTable.Cell(8, 4));
|
|
154
|
|
- newTable.Cell(8, 3).Range.Text = "协办单位";
|
|
155
|
|
- newTable.Cell(8, 4).Range.Text = "";
|
|
156
|
|
- // newTable.Cell(8, 7).Merge(newTable.Cell(8, 9));
|
|
157
|
|
-
|
|
158
|
|
- newTable.Cell(9, 1).Range.Text = "调度意见";
|
|
159
|
|
- newTable.Cell(9, 1).Merge(newTable.Cell(11, 1));
|
|
160
|
|
-
|
|
161
|
|
- newTable.Cell(9, 2).Range.Text = "";
|
|
162
|
|
- newTable.Cell(9, 2).Merge(newTable.Cell(11, 9));
|
|
163
|
|
- // newTable.Cell(10, 2).Merge(newTable.Cell(10, 10));
|
|
164
|
|
- // newTable.Cell(11, 2).Merge(newTable.Cell(11, 7));
|
|
165
|
|
- newTable.Cell(12, 1).Range.Text = "承办意见";
|
|
166
|
|
- newTable.Cell(12, 1).Merge(newTable.Cell(13, 1));
|
|
167
|
|
- newTable.Cell(12, 2).Range.Text = "";
|
|
168
|
|
- newTable.Cell(12, 2).Merge(newTable.Cell(13, 9));
|
|
169
|
|
- // newTable.Cell(13, 2).Merge(newTable.Cell(13, 7));
|
|
170
|
|
-
|
|
171
|
|
- newTable.Cell(14, 1).Range.Text = "领导批示";
|
|
172
|
|
- newTable.Cell(14, 1).Merge(newTable.Cell(15, 1));
|
|
173
|
|
- newTable.Cell(14, 2).Range.Text = "";
|
|
174
|
|
- newTable.Cell(14, 2).Merge(newTable.Cell(15, 9));
|
|
175
|
|
- //newTable.Cell(15, 2).Merge(newTable.Cell(15, 7));
|
|
176
|
|
-
|
|
177
|
|
- newTable.Cell(16, 1).Range.Text = "处理结果";
|
|
178
|
|
- newTable.Cell(16, 1).Merge(newTable.Cell(18, 1));
|
|
179
|
|
-
|
|
180
|
|
- newTable.Cell(16, 2).Range.Text = "";
|
|
181
|
|
- newTable.Cell(16, 2).Merge(newTable.Cell(18, 9));
|
|
182
|
|
- // newTable.Cell(17, 2).Merge(newTable.Cell(17, 10));
|
|
183
|
|
- // newTable.Cell(18, 2).Merge(newTable.Cell(18, 7));
|
|
|
107
|
+ newTable.Cell(5, 1).Range.Text = "承办单位";
|
|
|
108
|
+ newTable.Cell(5, 2).Range.Text = " ";
|
|
|
109
|
+ newTable.Cell(5, 2).Merge(newTable.Cell(5, 4));
|
|
|
110
|
+ newTable.Cell(5, 3).Range.Text = "协办单位";
|
|
|
111
|
+ newTable.Cell(5, 4).Range.Text = " ";
|
|
|
112
|
+ newTable.Cell(5, 4).Merge(newTable.Cell(5, 7));
|
|
|
113
|
+ newTable.Cell(6, 1).Range.Text = "调度意见";
|
|
|
114
|
+ newTable.Cell(6, 1).Merge(newTable.Cell(8, 1));
|
|
|
115
|
+ newTable.Cell(6, 2).Range.Text = " ";
|
|
|
116
|
+ newTable.Cell(6, 2).Merge(newTable.Cell(8, 9));
|
|
|
117
|
+ newTable.Cell(7, 1).Range.Text = "承办意见";
|
|
|
118
|
+ newTable.Cell(7, 1).Merge(newTable.Cell(8, 1));
|
|
|
119
|
+ newTable.Cell(7, 2).Range.Text = " ";
|
|
|
120
|
+ newTable.Cell(7, 2).Merge(newTable.Cell(8, 9));
|
|
|
121
|
+ newTable.Cell(8, 1).Range.Text = "领导批示";
|
|
|
122
|
+ newTable.Cell(8, 1).Merge(newTable.Cell(9, 1));
|
|
|
123
|
+ newTable.Cell(8, 2).Range.Text = "";
|
|
|
124
|
+ newTable.Cell(8, 2).Merge(newTable.Cell(9, 9));
|
|
|
125
|
+ newTable.Cell(9, 1).Range.Text = "处理结果";
|
|
|
126
|
+ newTable.Cell(9, 1).Merge(newTable.Cell(12, 1));
|
|
|
127
|
+ newTable.Cell(9, 2).Range.Text = " ";
|
|
|
128
|
+ newTable.Cell(9, 2).Merge(newTable.Cell(12, 9));
|
|
|
129
|
+ string FileName = "/Upload/Word/" + "/word.png";
|
|
|
130
|
+ FileName = HttpContext.Current.Server.MapPath("..") + FileName;
|
|
|
131
|
+ newTable.Cell(6, 2).Select();//选中一行
|
|
|
132
|
+ object LinkToFile = false;
|
|
|
133
|
+ object SaveWithDocument = true;
|
|
|
134
|
+ object Anchor = WordDoc.Application.Selection.Range;
|
|
|
135
|
+ WordDoc.Application.ActiveDocument.InlineShapes.AddPicture(FileName, ref LinkToFile, ref SaveWithDocument, ref Anchor);
|
|
|
136
|
+ WordDoc.Application.ActiveDocument.InlineShapes[1].Width = 110f;//图片宽度
|
|
|
137
|
+ WordDoc.Application.ActiveDocument.InlineShapes[1].Height =100f;//图片高
|
|
|
138
|
+ WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;
|
|
|
139
|
+ //将图片设置浮动在文字上方
|
|
|
140
|
+ WordDoc.Application.ActiveDocument.InlineShapes[1].ConvertToShape().WrapFormat.Type = Microsoft.Office.Interop.Word.WdWrapType.wdWrapBehind;
|
|
|
141
|
+ WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
|
|
184
|
142
|
object unite = MSWord.WdUnits.wdStory;
|
|
185
|
143
|
WordApp.Selection.EndKey(ref unite, ref Nothing); //将光标移动到文档末尾
|
|
186
|
144
|
WordDoc.Content.InsertAfter("联系电话:" + ""+" "
|
|
187
|
|
- +"审核员"+""+" " +"调度员");
|
|
188
|
|
- //object saveOption = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;
|
|
189
|
|
- // WordDoc.SaveAs(ref filename, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
|
|
190
|
|
- // WordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
|
|
191
|
|
- // WordApp.Application.Quit(ref saveOption, ref Nothing, ref Nothing);
|
|
192
|
|
- // WordDoc = null;
|
|
193
|
|
- // WordApp = null;
|
|
194
|
|
- // killAllProcess();
|
|
195
|
|
- // message = name + "文档生成成功,";
|
|
196
|
|
- //}
|
|
197
|
|
- //catch
|
|
198
|
|
- //{
|
|
199
|
|
- // message = "文件导出异常!";
|
|
200
|
|
- //}
|
|
|
145
|
+ +" 审核员"+""+" " +" 调度员");
|
|
201
|
146
|
//WdSaveFormat为Word 2003文档的保存格式
|
|
202
|
147
|
object format = MSWord.WdSaveFormat.wdFormatDocument;// office 2007就是wdFormatDocumentDefault
|
|
203
|
148
|
object path;
|
|
|
@@ -210,55 +155,8 @@ public class ExportWord
|
|
210
|
155
|
}
|
|
211
|
156
|
//将wordDoc文档对象的内容保存为doc文档
|
|
212
|
157
|
WordDoc.SaveAs(ref path, ref format, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
|
|
213
|
|
- //关闭wordDoc文档对象
|
|
214
|
|
- //看是不是要打印
|
|
215
|
|
- //wordDoc.PrintOut();
|
|
216
|
158
|
WordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
|
|
217
|
|
- //关闭wordApp组件对象
|
|
218
|
159
|
WordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
|
|
219
|
|
- //Console.WriteLine(path + " 创建完毕!");
|
|
220
|
|
- //Console.ReadKey();
|
|
221
|
|
- //我还要打开这个文档玩玩
|
|
222
|
|
-
|
|
223
|
|
- return message;
|
|
|
160
|
+ return message;
|
|
224
|
161
|
}
|
|
225
|
|
-
|
|
226
|
|
- protected void killAllProcess() // 杀掉所有winword.exe进程
|
|
227
|
|
- {
|
|
228
|
|
- System.Diagnostics.Process[] myPs;
|
|
229
|
|
- myPs = System.Diagnostics.Process.GetProcesses();
|
|
230
|
|
- foreach (System.Diagnostics.Process p in myPs)
|
|
231
|
|
- {
|
|
232
|
|
- if (p.Id != 0)
|
|
233
|
|
- {
|
|
234
|
|
- string myS = "WINWORD.EXE" + p.ProcessName + " ID:" + p.Id.ToString();
|
|
235
|
|
- try
|
|
236
|
|
- {
|
|
237
|
|
- if (p.Modules != null)
|
|
238
|
|
- if (p.Modules.Count > 0)
|
|
239
|
|
- {
|
|
240
|
|
- System.Diagnostics.ProcessModule pm = p.Modules[0];
|
|
241
|
|
- myS += "\n Modules[0].FileName:" + pm.FileName;
|
|
242
|
|
- myS += "\n Modules[0].ModuleName:" + pm.ModuleName;
|
|
243
|
|
- myS += "\n Modules[0].FileVersionInfo:\n" + pm.FileVersionInfo.ToString();
|
|
244
|
|
- if (pm.ModuleName.ToLower() == "winword.exe")
|
|
245
|
|
- p.Kill();
|
|
246
|
|
- }
|
|
247
|
|
- }
|
|
248
|
|
- catch
|
|
249
|
|
- { }
|
|
250
|
|
- finally
|
|
251
|
|
- {
|
|
252
|
|
- }
|
|
253
|
|
- }
|
|
254
|
|
- }
|
|
255
|
|
- }
|
|
256
|
|
- public bool IsReusable
|
|
257
|
|
- {
|
|
258
|
|
- get
|
|
259
|
|
- {
|
|
260
|
|
- return false;
|
|
261
|
|
- }
|
|
262
|
|
- }
|
|
263
|
|
-
|
|
264
|
|
- }
|
|
|
162
|
+}
|