做了差不多一周的导出Word,现在把代码贴出来 :
ExportWord.cs
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Web; 5 using System.Data; 6 using System.IO; 7 8 9 /// <summary> 10 ///DaoChuWord 的摘要说明 11 /// </summary> 12 public class ExportWord 13 { 14 public ExportWord() 15 { 16 // 17 //TODO: 在此处添加构造函数逻辑 18 // 19 } 20 21 public DataTable dat = null; 22 public void ProcessRequest(HttpContext context, string id,string name) 23 { 24 context.Response.ContentType = "text/plain"; 25 GetDataTable(id); 26 CreateWord(name); 27 //此处为了批量操作,把下面这个注掉 28 //context.Response.End(); 29 30 } 31 32 DataTable GetDataTable(string id) 33 { 34 string sql = " select * from hr_person where id =" + id; 35 dat = ZWL.DBUtility.MyDBHelp.GetDataTable(sql); 36 if (dat != null) 37 { 38 return dat; 39 } 40 throw new NoNullAllowedException(); 41 } 42 43 public string CreateWord(string name) 44 { 45 string uid = dat.Rows[0]["id"].ToString(); 46 string message = ""; 47 //try 48 //{ 49 Object Nothing = System.Reflection.Missing.Value; 50 //Directory.CreateDirectory("D:/JobResume"); //创建文件所在目录 51 // string name = "JobResume_" + DateTime.Now.ToString("yyyyMMddhhmmssfff") + ".doc";//文件名 52 object filename = name; //文件保存路径 53 // return filename+""; 54 //创建Word文档 55 Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.ApplicationClass(); 56 // return "34343"; 57 Microsoft.Office.Interop.Word.Document WordDoc = WordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing); 58 WordApp.Selection.PageSetup.LeftMargin = 50f; 59 WordApp.Selection.PageSetup.RightMargin = 50f; 60 WordApp.Selection.PageSetup.PageWidth = 650f; //页面宽度 61 62 WordDoc.ActiveWindow.Selection.Font.Bold = 2; 63 64 //添加页眉 65 //WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView; 66 //WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader; 67 //WordApp.ActiveWindow.ActivePane.Selection.InsertAfter(""); 68 //WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;//设置右对齐 69 //WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument;//跳出页眉设置 70 WordApp.Selection.ParagraphFormat.LineSpacing = 13f;//设置文档的行间距 71 //移动焦点并换行 72 object count = 14; 73 object WdLine = Microsoft.Office.Interop.Word.WdUnits.wdLine;//换一行; 74 WordApp.Selection.ParagraphFormat.LineSpacing = 18f; 75 // WordApp.Selection.Range.Bold = 2; 76 WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; 77 WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点 78 WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; 79 WordApp.Selection.TypeParagraph();//插入段落 80 WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft; 81 WordApp.Selection.Font.Size = 18f; 82 83 object missing = System.Reflection.Missing.Value; 84 object count2 = 14; 85 object WdLine2 = Microsoft.Office.Interop.Word.WdUnits.wdLine;//换一行; 86 WordApp.Selection.Text = "应 聘 报 名 表"; 87 WordApp.Selection.ParagraphFormat.LineSpacingRule = Microsoft.Office.Interop.Word.WdLineSpacing.wdLineSpaceSingle;//单倍行距 88 89 //WordApp.Selection.Range.Bold = 2; 90 WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; 91 WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点 92 WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; 93 WordApp.Selection.TypeParagraph();//插入段落 94 //WordApp.Selection.ParagraphFormat.LineSpacing = 22f; 95 WordApp.Selection.Font.Size = 10.5f; 96 WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft; 97 WordApp.Selection.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorBlack; 98 99 //文档中创建表格 100 Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables.Add(WordApp.Selection.Range, 19, 15, ref Nothing, ref Nothing); 101 //设置表格样式 102 WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中 103 104 //设置表格框 105 newTable.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle; 106 newTable.Columns[1].Width = 25f; 107 newTable.Columns[2].Width = 30f; 108 newTable.Columns[3].Width = 25f; 109 newTable.Columns[4].Width = 45f; 110 newTable.Columns[5].Width = 25f; 111 newTable.Columns[6].Width = 25f; 112 newTable.Columns[7].Width = 35f; 113 newTable.Columns[8].Width = 40f; 114 newTable.Columns[9].Width = 35f; 115 newTable.Columns[10].Width = 15f; 116 newTable.Columns[11].Width = 45f; 117 newTable.Columns[12].Width = 30f; 118 newTable.Columns[13].Width = 40f; 119 newTable.Columns[14].Width = 50f; 120 newTable.Columns[15].Width = 90f; 121 122 //填充表格内容 123 for (int k = 1; k < 19; k++) 124 { 125 newTable.Rows[k].Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle; 126 } 127 for (int k = 1; k < 15; k++) 128 { 129 newTable.Columns[k].Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle; 130 } 131 //垂直居中 132 object unit = Microsoft.Office.Interop.Word.WdUnits.wdLine; 133 object countjz = 1; 134 WordApp.Selection.MoveEnd(ref unit, ref countjz); 135 WordApp.Selection.Cells.VerticalAlignment = Microsoft.Office.Interop.Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;//垂直居中 136 137 //填充表格内容 第一行 138 newTable.Cell(1, 1).Range.Text = "姓名"; 139 //合并单元格 140 newTable.Cell(1, 1).Merge(newTable.Cell(1, 2)); 141 newTable.Cell(1, 2).Range.Text = dat.Rows[0]["name"].ToString(); 142 143 newTable.Cell(1, 2).Merge(newTable.Cell(1, 3)); 144 newTable.Cell(1, 3).Range.Text = "性 别"; 145 newTable.Cell(1, 3).Merge(newTable.Cell(1, 4)); 146 newTable.Cell(1, 4).Range.Text = dat.Rows[0]["sex"].ToString(); 147 newTable.Cell(1, 4).Merge(newTable.Cell(1, 5)); 148 newTable.Cell(1, 5).Range.Text = "出 生日 期"; 149 newTable.Cell(1, 5).Merge(newTable.Cell(1, 6)); 150 if (dat.Rows[0]["createdate"].ToString().Equals("")) 151 { 152 newTable.Cell(1, 6).Range.Text = ""; 153 } 154 else 155 { 156 newTable.Cell(1, 6).Range.Text = DateTime.Parse(dat.Rows[0]["createdate"].ToString()).ToString("yyyy-MM-dd"); 157 } 158 newTable.Cell(1, 6).Merge(newTable.Cell(1, 7)); 159 newTable.Cell(1, 7).Range.Text = "民 族"; 160 newTable.Cell(1, 8).Range.Text = dat.Rows[0]["minzu"].ToString(); 161 162 newTable.Cell(1, 9).Merge(newTable.Cell(3, 15)); 163 newTable.Cell(1, 9).Select();//选中一行 164 165 string FileName = "E:\\OA\\new\\web2\\upload\\" + dat.Rows[0]["touxiang"].ToString(); 166 object LinkToFile = false; 167 object SaveWithDocument = true; 168 object Anchor = WordDoc.Application.Selection.Range; 169 WordDoc.Application.ActiveDocument.InlineShapes.AddPicture(FileName, ref LinkToFile, ref SaveWithDocument, ref Anchor); 170 WordDoc.Application.ActiveDocument.InlineShapes[1].Width = 72f;//图片宽度 171 WordDoc.Application.ActiveDocument.InlineShapes[1].Height = 90f;//图片高 172 WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; 173 174 // 填充表格内容 第二行 175 newTable.Cell(2, 1).Range.Text = "籍 贯"; 176 newTable.Cell(2, 1).Merge(newTable.Cell(2, 2)); 177 newTable.Cell(2, 2).Range.Text = dat.Rows[0]["jiguan"].ToString(); 178 newTable.Cell(2, 2).Merge(newTable.Cell(2, 3)); 179 newTable.Cell(2, 3).Range.Text = "出生地"; 180 newTable.Cell(2, 3).Merge(newTable.Cell(2, 4)); 181 newTable.Cell(2, 4).Range.Text = dat.Rows[0]["chushengdi"].ToString(); 182 newTable.Cell(2, 4).Merge(newTable.Cell(2, 5)); 183 newTable.Cell(2, 5).Range.Text = "户 口所在地"; 184 newTable.Cell(2, 5).Merge(newTable.Cell(2, 6)); 185 newTable.Cell(2, 6).Range.Text = dat.Rows[0]["hukouaddress"].ToString(); 186 newTable.Cell(2, 6).Merge(newTable.Cell(2, 7)); 187 newTable.Cell(2, 7).Range.Text = "身 高"; 188 newTable.Cell(2, 8).Range.Text = dat.Rows[0]["shengao"].ToString(); 189 190 191 //填充表格内容 第三行 192 newTable.Cell(3, 1).Range.Text = "政治面貌"; 193 newTable.Cell(3, 1).Merge(newTable.Cell(3, 2)); 194 newTable.Cell(3, 2).Range.Text = dat.Rows[0]["zhengzhi"].ToString(); 195 newTable.Cell(3, 2).Merge(newTable.Cell(3, 3)); 196 newTable.Cell(3, 3).Range.Text = "入 党时 间"; 197 newTable.Cell(3, 3).Merge(newTable.Cell(3, 4)); 198 if (dat.Rows[0]["rudangdate"].ToString().Equals("")) 199 { 200 newTable.Cell(3, 4).Range.Text = ""; 201 } 202 else 203 { 204 newTable.Cell(3, 4).Range.Text = DateTime.Parse(dat.Rows[0]["rudangdate"].ToString()).ToString("yyyy-MM-dd"); 205 } 206 newTable.Cell(3, 4).Merge(newTable.Cell(3, 5)); 207 newTable.Cell(3, 5).Range.Text = "参加工作时间"; 208 newTable.Cell(3, 5).Merge(newTable.Cell(3, 6)); 209 if (dat.Rows[0]["canjiaworktime"].ToString().Equals("")) 210 { 211 newTable.Cell(3, 6).Range.Text = ""; 212 } 213 else 214 { 215 newTable.Cell(3, 6).Range.Text = DateTime.Parse(dat.Rows[0]["canjiaworktime"].ToString()).ToString("yyyy-MM-dd"); 216 } 217 newTable.Cell(3, 6).Merge(newTable.Cell(3, 7)); 218 newTable.Cell(3, 7).Range.Text = "婚姻状况"; 219 newTable.Cell(3, 8).Range.Text = dat.Rows[0]["hunyin"].ToString(); 220 221 //填充表格内容 第四行 222 newTable.Cell(4, 1).Range.Text = "移动电话"; 223 newTable.Cell(4, 1).Merge(newTable.Cell(4, 2)); 224 newTable.Cell(4, 2).Range.Text = dat.Rows[0]["phone"].ToString(); 225 newTable.Cell(4, 2).Merge(newTable.Cell(4, 3)); 226 newTable.Cell(4, 3).Range.Text = "其他联系方式"; 227 newTable.Cell(4, 3).Merge(newTable.Cell(4, 4)); 228 newTable.Cell(4, 4).Range.Text = dat.Rows[0]["qitalianxi"].ToString(); 229 newTable.Cell(4, 4).Merge(newTable.Cell(4, 5)); 230 newTable.Cell(4, 5).Range.Text = "E-mail"; 231 newTable.Cell(4, 5).Merge(newTable.Cell(4, 6)); 232 newTable.Cell(4, 6).Range.Text = dat.Rows[0]["email"].ToString(); 233 newTable.Cell(4, 6).Merge(newTable.Cell(4, 8)); 234 newTable.Cell(4, 7).Range.Text = "档 案所在地"; 235 newTable.Cell(4, 8).Range.Text = dat.Rows[0]["danganaddress"].ToString(); 236 237 //填充表格内容 第五行 238 newTable.Cell(5, 1).Range.Text = " 身份证 号 码"; 239 newTable.Cell(5, 1).Merge(newTable.Cell(5, 2)); 240 newTable.Cell(5, 2).Range.Text = dat.Rows[0]["zhengjiannum"].ToString(); 241 newTable.Cell(5, 2).Merge(newTable.Cell(5, 7)); 242 newTable.Cell(5, 3).Range.Text = "是否曾投递简历到XXXXXX:(如果是,请注明投递时间)"; 243 newTable.Cell(5, 3).Merge(newTable.Cell(5, 8)); 244 newTable.Cell(5, 4).Range.Text = dat.Rows[0]["ifcengtoudi"].ToString(); 245 246 247 //填充表格内容 第六行 248 newTable.Cell(6, 1).Range.Text = "家庭住址"; 249 newTable.Cell(6, 1).Merge(newTable.Cell(6, 2)); 250 newTable.Cell(6, 2).Range.Text = dat.Rows[0]["tongxunaddress"].ToString(); 251 newTable.Cell(6, 2).Merge(newTable.Cell(6, 6)); 252 newTable.Cell(6, 3).Range.Text = "驾龄"; 253 newTable.Cell(6, 4).Range.Text = dat.Rows[0]["jialing"].ToString(); 254 newTable.Cell(6, 5).Range.Text = "外语种类及熟练程度"; 255 newTable.Cell(6, 5).Merge(newTable.Cell(6, 6)); 256 newTable.Cell(6, 6).Range.Text = dat.Rows[0]["waiyu"].ToString(); 257 newTable.Cell(6, 6).Merge(newTable.Cell(6, 7)); 258 newTable.Cell(6, 7).Range.Text = "微机操作能力"; 259 newTable.Cell(6, 8).Range.Text = dat.Rows[0]["weiji"].ToString(); 260 261 //填充表格内容 第七行 262 newTable.Cell(7, 1).Range.Text = "收到录用通知后可到岗时间"; 263 newTable.Cell(7, 1).Merge(newTable.Cell(7, 6)); 264 if (dat.Rows[0]["daogangdate"].ToString().Equals("三天内")) 265 { 266 newTable.Cell(7, 2).Range.Text = " □三天内 √一周内 □两周内 □一个月内 "; 267 268 } 269 if (dat.Rows[0]["daogangdate"].ToString().Equals("一周内")) 270 { 271 newTable.Cell(7, 2).Range.Text = " □三天内 √一周内 □两周内 □一个月内 "; 272 273 } 274 if (dat.Rows[0]["daogangdate"].ToString().Equals("两周内")) 275 { 276 newTable.Cell(7, 2).Range.Text = " □三天内 □一周内 √两周内 □一个月内 "; 277 278 } 279 if (dat.Rows[0]["daogangdate"].ToString().Equals("一个月内")) 280 { 281 newTable.Cell(7, 2).Range.Text = " □三天内 □一周内 □两周内 √一个月内 "; 282 283 } 284 newTable.Cell(7, 2).Merge(newTable.Cell(7, 10)); 285 newTable.Cell(7, 1).Select();//选中一行 286 WordApp.Selection.ParagraphFormat.LineSpacing = 25f; 287 //填充表格内容 第八行 288 newTable.Cell(8, 1).Range.Text = "应聘信息来 源"; 289 newTable.Cell(8, 1).Merge(newTable.Cell(8, 2)); 290 291 292 if (dat.Rows[0]["xinxilaiyuan"].ToString().Equals("华商报无忧招聘")) 293 { 294 newTable.Cell(8, 2).Range.Text = "√华商报无忧招聘 □中华英才网 □智联招聘 □其他( )"; 295 } 296 if (dat.Rows[0]["xinxilaiyuan"].ToString().Equals("中华英才网")) 297 { 298 newTable.Cell(8, 2).Range.Text = "□华商报无忧招聘 √中华英才网 □智联招聘 □其他( )"; 299 } 300 if (dat.Rows[0]["xinxilaiyuan"].ToString().Equals("智联招聘")) 301 { 302 newTable.Cell(8, 2).Range.Text = "□华商报无忧招聘 □中华英才网 √智联招聘 □其他( )"; 303 } 304 if (dat.Rows[0]["xinxilaiyuan"].ToString().Equals("其他")) 305 { 306 newTable.Cell(8, 2).Range.Text = "□华商报无忧招聘 □中华英才网 □智联招聘 √其他( )"; 307 } 308 newTable.Cell(8, 2).Merge(newTable.Cell(8, 14)); 309 310 //填充表格内容 第九行 311 newTable.Cell(9, 1).Range.Text = "工作意向"; 312 newTable.Cell(9, 1).Merge(newTable.Cell(9, 2)); 313 314 315 newTable.Cell(9, 1).Merge(newTable.Cell(10, 2)); 316 317 newTable.Cell(9, 2).Range.Text = "期望的工作岗位及职务:" + dat.Rows[0]["qiwangwork"].ToString(); 318 newTable.Cell(9, 2).Merge(newTable.Cell(9, 14)); 319 newTable.Cell(9, 2).Select();//选中一行 320 WordApp.Selection.ParagraphFormat.LineSpacing = 25f; 321 //填充表格内容 第十行 322 323 newTable.Cell(10, 2).Range.Text = "期望薪资待遇:" + dat.Rows[0]["qiwangmoney"].ToString(); 324 newTable.Cell(10, 2).Merge(newTable.Cell(10, 14)); 325 newTable.Cell(10, 2).Select();//选中一行 326 WordApp.Selection.ParagraphFormat.LineSpacing = 25f; 327 328 //填充表格内容 第十一行 329 330 newTable.Cell(11, 1).Range.Text = "教育背景"; 331 newTable.Cell(11, 1).Merge(newTable.Cell(18, 1)); 332 newTable.Cell(11, 2).Range.Text = "说 明"; 333 newTable.Cell(11, 2).Merge(newTable.Cell(11, 3)); 334 newTable.Cell(11, 3).Range.Text = "学习方式:1.统招;2.电大、夜大、函授、自考、成人(教育部承认学历);3.党校; 请在“学习方式”一栏中填入。如无此教育背景则对应行信息不填。"; 335 newTable.Cell(11, 3).Merge(newTable.Cell(11, 14)); 336 337 338 //填充表格内容 第十二行 339 340 newTable.Cell(12, 2).Range.Text = "学 历"; 341 newTable.Cell(12, 2).Merge(newTable.Cell(12, 3)); 342 newTable.Cell(12, 3).Range.Text = "学 位"; 343 newTable.Cell(12, 3).Merge(newTable.Cell(12, 5)); 344 newTable.Cell(12, 4).Range.Text = "学习方式"; 345 newTable.Cell(12, 5).Range.Text = "毕业院校"; 346 newTable.Cell(12, 5).Merge(newTable.Cell(12, 8)); 347 newTable.Cell(12, 6).Range.Text = "专 业"; 348 newTable.Cell(12, 6).Merge(newTable.Cell(12, 7)); 349 newTable.Cell(12, 7).Range.Text = "就读起止时间"; 350 newTable.Cell(12, 7).Merge(newTable.Cell(12, 8)); 351 352 //填充表格内容 第13行 353 newTable.Cell(13, 2).Range.Text = "高 中/中 专"; 354 newTable.Cell(13, 2).Merge(newTable.Cell(13, 3)); 355 if (getXueLi("高中").Rows.Count > 0) 356 { 357 System.Data.DataRow dr = getXueLi("高中").Rows[0]; 358 newTable.Cell(13, 3).Range.Text = dr["xuewei"].ToString(); 359 newTable.Cell(13, 3).Merge(newTable.Cell(13, 5)); 360 newTable.Cell(13, 4).Range.Text = dr["xuexifs"].ToString(); 361 newTable.Cell(13, 5).Range.Text = dr["xuexiaoname"].ToString(); 362 newTable.Cell(13, 5).Merge(newTable.Cell(13, 8)); 363 newTable.Cell(13, 6).Range.Text = dr["zhuanye"].ToString(); 364 newTable.Cell(13, 6).Merge(newTable.Cell(13, 7)); 365 newTable.Cell(13, 7).Range.Text = DateTime.Parse(dr["t1"].ToString()).ToString("yyyy.MM") 366 + " 至 " + DateTime.Parse(dr["t2"].ToString()).ToString("yyyy.MM"); 367 368 newTable.Cell(13, 7).Merge(newTable.Cell(13, 8)); 369 } 370 else 371 { 372 newTable.Cell(13, 3).Range.Text = ""; 373 newTable.Cell(13, 3).Merge(newTable.Cell(13, 5)); 374 newTable.Cell(13, 4).Range.Text = ""; 375 newTable.Cell(13, 5).Range.Text = ""; 376 newTable.Cell(13, 5).Merge(newTable.Cell(13, 8)); 377 newTable.Cell(13, 6).Range.Text = ""; 378 newTable.Cell(13, 6).Merge(newTable.Cell(13, 7)); 379 newTable.Cell(13, 7).Range.Text = ""; 380 newTable.Cell(13, 7).Merge(newTable.Cell(13, 8)); 381 } 382 383 384 385 //填充表格内容 第14行 386 387 newTable.Cell(14, 2).Range.Text = "大 专"; 388 newTable.Cell(14, 2).Merge(newTable.Cell(14, 3)); 389 newTable.Cell(14, 2).Select();//选中一行 390 WordApp.Selection.ParagraphFormat.LineSpacing = 25f; 391 if (getXueLi("大专").Rows.Count > 0) 392 { 393 System.Data.DataRow dr = getXueLi("大专").Rows[0]; 394 newTable.Cell(14, 3).Range.Text = dr["xuewei"].ToString(); 395 newTable.Cell(14, 3).Merge(newTable.Cell(14, 5)); 396 newTable.Cell(14, 4).Range.Text = dr["xuexifs"].ToString(); 397 newTable.Cell(14, 5).Range.Text = dr["xuexiaoname"].ToString(); 398 newTable.Cell(14, 5).Merge(newTable.Cell(14, 8)); 399 newTable.Cell(14, 6).Range.Text = dr["zhuanye"].ToString(); 400 newTable.Cell(14, 6).Merge(newTable.Cell(14, 7)); 401 newTable.Cell(14, 7).Range.Text = DateTime.Parse(dr["t1"].ToString()).ToString("yyyy.MM") 402 + " 至 " + DateTime.Parse(dr["t2"].ToString()).ToString("yyyy.MM"); 403 newTable.Cell(14, 7).Merge(newTable.Cell(14, 8)); 404 } 405 else 406 { 407 newTable.Cell(14, 3).Range.Text = ""; 408 newTable.Cell(14, 3).Merge(newTable.Cell(14, 5)); 409 newTable.Cell(14, 4).Range.Text = ""; 410 newTable.Cell(14, 5).Range.Text = ""; 411 newTable.Cell(14, 5).Merge(newTable.Cell(14, 8)); 412 newTable.Cell(14, 6).Range.Text = ""; 413 newTable.Cell(14, 6).Merge(newTable.Cell(14, 7)); 414 newTable.Cell(14, 7).Range.Text = ""; 415 newTable.Cell(14, 7).Merge(newTable.Cell(14, 8)); 416 } 417 418 419 420 //填充表格内容 第15行 421 422 newTable.Cell(15, 2).Range.Text = "本 科"; 423 newTable.Cell(15, 2).Merge(newTable.Cell(15, 3)); 424 newTable.Cell(15, 2).Select();//选中一行 425 WordApp.Selection.ParagraphFormat.LineSpacing = 25f; 426 if (getXueLi("本科").Rows.Count > 0) 427 { 428 System.Data.DataRow dr = getXueLi("本科").Rows[0]; 429 newTable.Cell(15, 3).Range.Text = dr["xuewei"].ToString(); 430 newTable.Cell(15, 3).Merge(newTable.Cell(15, 5)); 431 newTable.Cell(15, 4).Range.Text = dr["xuexifs"].ToString(); 432 newTable.Cell(15, 5).Range.Text = dr["xuexiaoname"].ToString(); 433 newTable.Cell(15, 5).Merge(newTable.Cell(15, 8)); 434 newTable.Cell(15, 6).Range.Text = dr["zhuanye"].ToString(); 435 newTable.Cell(15, 6).Merge(newTable.Cell(15, 7)); 436 newTable.Cell(15, 7).Range.Text = DateTime.Parse(dr["t1"].ToString()).ToString("yyyy.MM") + 437 " 至 " + DateTime.Parse(dr["t2"].ToString()).ToString("yyyy.MM"); 438 newTable.Cell(15, 7).Merge(newTable.Cell(15, 8)); 439 } 440 else 441 { 442 newTable.Cell(15, 3).Range.Text = ""; 443 newTable.Cell(15, 3).Merge(newTable.Cell(15, 5)); 444 newTable.Cell(15, 4).Range.Text = ""; 445 newTable.Cell(15, 5).Range.Text = ""; 446 newTable.Cell(15, 5).Merge(newTable.Cell(15, 8)); 447 newTable.Cell(15, 6).Range.Text = ""; 448 newTable.Cell(15, 6).Merge(newTable.Cell(15, 7)); 449 newTable.Cell(15, 7).Range.Text = ""; 450 newTable.Cell(15, 7).Merge(newTable.Cell(15, 8)); 451 } 452 453 454 //填充表格内容 第16行 455 456 newTable.Cell(16, 2).Range.Text = "第二学士 学位班"; 457 newTable.Cell(16, 2).Merge(newTable.Cell(16, 3)); 458 if (getXueLi("第二学士学位班").Rows.Count > 0) 459 { 460 System.Data.DataRow dr = getXueLi("第二学士学位班").Rows[0]; 461 newTable.Cell(16, 3).Range.Text = dr["xuewei"].ToString(); 462 newTable.Cell(16, 3).Merge(newTable.Cell(16, 5)); 463 newTable.Cell(16, 4).Range.Text = dr["xuexifs"].ToString(); 464 newTable.Cell(16, 5).Range.Text = dr["xuexiaoname"].ToString(); 465 newTable.Cell(16, 5).Merge(newTable.Cell(16, 8)); 466 newTable.Cell(16, 6).Range.Text = dr["zhuanye"].ToString(); 467 newTable.Cell(16, 6).Merge(newTable.Cell(16, 7)); 468 newTable.Cell(16, 7).Range.Text = DateTime.Parse(dr["t1"].ToString()).ToString("yyyy.MM") + 469 " 至 " + DateTime.Parse(dr["t2"].ToString()).ToString("yyyy.MM"); 470 newTable.Cell(16, 7).Merge(newTable.Cell(16, 8)); 471 472 473 } 474 else 475 { 476 newTable.Cell(16, 3).Range.Text = ""; 477 newTable.Cell(16, 3).Merge(newTable.Cell(16, 5)); 478 newTable.Cell(16, 4).Range.Text = ""; 479 newTable.Cell(16, 5).Range.Text = ""; 480 newTable.Cell(16, 5).Merge(newTable.Cell(16, 8)); 481 newTable.Cell(16, 6).Range.Text = ""; 482 newTable.Cell(16, 6).Merge(newTable.Cell(16, 7)); 483 newTable.Cell(16, 7).Range.Text = ""; 484 newTable.Cell(16, 7).Merge(newTable.Cell(16, 8)); 485 } 486 487 488 //填充表格内容 第17行 489 490 newTable.Cell(17, 2).Range.Text = "硕 士 研究生"; 491 newTable.Cell(17, 2).Merge(newTable.Cell(17, 3)); 492 if (getXueLi("硕士研究生").Rows.Count > 0) 493 { 494 System.Data.DataRow dr = getXueLi("硕士研究生").Rows[0]; 495 newTable.Cell(17, 3).Range.Text = dr["xuewei"].ToString(); 496 newTable.Cell(17, 3).Merge(newTable.Cell(17, 5)); 497 newTable.Cell(17, 4).Range.Text = dr["xuexifs"].ToString(); 498 newTable.Cell(17, 5).Range.Text = dr["xuexiaoname"].ToString(); 499 newTable.Cell(17, 5).Merge(newTable.Cell(17, 8)); 500 newTable.Cell(17, 6).Range.Text = dr["zhuanye"].ToString(); 501 newTable.Cell(17, 6).Merge(newTable.Cell(17, 7)); 502 newTable.Cell(17, 7).Range.Text = DateTime.Parse(dr["t1"].ToString()).ToString("yyyy.MM") + 503 " 至 " + DateTime.Parse(dr["t2"].ToString()).ToString("yyyy.MM"); 504 newTable.Cell(17, 7).Merge(newTable.Cell(17, 8)); 505 506 507 } 508 else 509 { 510 newTable.Cell(17, 3).Range.Text = ""; 511 newTable.Cell(17, 3).Merge(newTable.Cell(17, 5)); 512 newTable.Cell(17, 4).Range.Text = ""; 513 newTable.Cell(17, 5).Range.Text = ""; 514 newTable.Cell(17, 5).Merge(newTable.Cell(17, 8)); 515 newTable.Cell(17, 6).Range.Text = ""; 516 newTable.Cell(17, 6).Merge(newTable.Cell(17, 7)); 517 newTable.Cell(17, 7).Range.Text = ""; 518 newTable.Cell(17, 7).Merge(newTable.Cell(17, 8)); 519 } 520 521 522 // 填充表格内容 第18行 523 524 newTable.Cell(18, 2).Range.Text = "博 士 研究生"; 525 newTable.Cell(18, 2).Merge(newTable.Cell(18, 3)); 526 if (getXueLi("博士研究生").Rows.Count > 0) 527 { 528 System.Data.DataRow dr = getXueLi("博士研究生").Rows[0]; 529 newTable.Cell(18, 3).Range.Text = dr["xuewei"].ToString(); 530 newTable.Cell(18, 3).Merge(newTable.Cell(18, 5)); 531 newTable.Cell(18, 4).Range.Text = dr["xuexifs"].ToString(); 532 newTable.Cell(18, 5).Range.Text = dr["xuexiaoname"].ToString(); 533 newTable.Cell(18, 5).Merge(newTable.Cell(18, 8)); 534 newTable.Cell(18, 6).Range.Text = dr["zhuanye"].ToString(); 535 newTable.Cell(18, 6).Merge(newTable.Cell(18, 7)); 536 newTable.Cell(18, 7).Range.Text = DateTime.Parse(dr["t1"].ToString()).ToString("yyyy.MM") + 537 " 至 " + DateTime.Parse(dr["t2"].ToString()).ToString("yyyy.MM"); 538 newTable.Cell(18, 7).Merge(newTable.Cell(18, 8)); 539 540 541 } 542 else 543 { 544 newTable.Cell(18, 3).Range.Text = ""; 545 newTable.Cell(18, 3).Merge(newTable.Cell(18, 5)); 546 newTable.Cell(18, 4).Range.Text = ""; 547 newTable.Cell(18, 5).Range.Text = ""; 548 newTable.Cell(18, 5).Merge(newTable.Cell(18, 8)); 549 newTable.Cell(18, 6).Range.Text = ""; 550 newTable.Cell(18, 6).Merge(newTable.Cell(18, 7)); 551 newTable.Cell(18, 7).Range.Text = ""; 552 newTable.Cell(18, 7).Merge(newTable.Cell(18, 8)); 553 } 554 555 556 // 填充表格内容 第19行 557 558 newTable.Cell(19, 1).Range.Text = "技术职称"; 559 newTable.Cell(19, 1).Merge(newTable.Cell(19, 2)); 560 newTable.Cell(19, 2).Range.Text = dat.Rows[0]["zhicheng"].ToString(); 561 newTable.Cell(19, 2).Merge(newTable.Cell(19, 5)); 562 newTable.Cell(19, 3).Range.Text = "职业资格"; 563 newTable.Cell(19, 3).Merge(newTable.Cell(19, 4)); 564 newTable.Cell(19, 4).Range.Text = dat.Rows[0]["renzhizige"].ToString(); 565 newTable.Cell(19, 4).Merge(newTable.Cell(19, 6)); 566 newTable.Cell(19, 5).Range.Text = "其他资质及培训证书等"; 567 newTable.Cell(19, 5).Merge(newTable.Cell(19, 6)); 568 newTable.Cell(19, 6).Range.Text = dat.Rows[0]["zhengshu"].ToString(); 569 newTable.Cell(19, 6).Merge(newTable.Cell(19, 7)); 570 571 572 WordApp.ActiveDocument.PageSetup.SectionStart = Microsoft.Office.Interop.Word.WdSectionStart.wdSectionNewPage;//节的起始位置:新建页 573 574 newTable.Cell(19, 1).Select();//选中一行 575 // WordApp.Selection.ParagraphFormat.LineSpacing = 25f; 576 object missing1 = System.Reflection.Missing.Value; 577 object count1 = 20; 578 object WdLine1 = Microsoft.Office.Interop.Word.WdUnits.wdLine;//换一行; 579 WordApp.Selection.MoveDown(ref WdLine1, ref count1, ref missing1);//光标向下移1行 580 WordApp.Selection.MoveDown(ref WdLine1, ref count1, ref missing1);//光标向下移1行 581 WordApp.Selection.TypeParagraph();//在表格外回车 582 // WordApp.Selection.TypeParagraph();//在表格外回车 583 584 //文档中创建表格 585 Microsoft.Office.Interop.Word.Table newTable1 = WordDoc.Tables.Add(WordApp.Selection.Range, 17, 9, ref Nothing, ref Nothing); 586 //设置表格样式 587 // newTable.Borders. 588 //设置表格框 589 newTable1.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle; 590 newTable1.Columns[1].Width = 25f; 591 newTable1.Columns[2].Width = 40f; 592 newTable1.Columns[3].Width = 40f; 593 newTable1.Columns[4].Width = 30f; 594 newTable1.Columns[5].Width = 50f; 595 newTable1.Columns[6].Width = 70f; 596 newTable1.Columns[7].Width = 70f; 597 newTable1.Columns[8].Width = 130f; 598 newTable1.Columns[9].Width = 90f; 599 600 newTable1.Cell(1, 1).Range.Bold = 2;//设置单元格中字体为粗体 601 602 WordApp.Selection.ParagraphFormat.LineSpacing = 10.5f; 603 604 WordApp.Selection.Cells.VerticalAlignment = Microsoft.Office.Interop.Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;//垂直居中 605 WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中 606 //填充表格内容 607 for (int i = 1; i < 15; i++) 608 { 609 newTable1.Rows.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle; 610 611 } 612 for (int i = 1; i < 9; i++) 613 { 614 newTable1.Columns.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle; 615 616 } 617 618 //垂直居中 619 //object unit = Microsoft.Office.Interop.Word.WdUnits.wdLine; 620 //object countjz = 1; 621 WordApp.Selection.MoveEnd(ref unit, ref countjz); 622 WordApp.Selection.Cells.VerticalAlignment = Microsoft.Office.Interop.Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;//垂直居中 623 624 625 //填充表格内容 第1行 626 newTable1.Cell(1, 1).Range.Text = "工作经历"; 627 newTable1.Cell(1, 1).Merge(newTable1.Cell(8, 1)); 628 newTable1.Cell(1, 2).Range.Text = "说 明"; 629 newTable1.Cell(1, 2).Merge(newTable1.Cell(1, 3)); 630 newTable1.Cell(1, 3).Range.Text = "1、请按工作时间由近至远(倒序)填写; 2、如在同一家公司因岗位、级别、地点发生变化请予以证明,详细填写。"; 631 newTable1.Cell(1, 3).Merge(newTable1.Cell(1, 8)); 632 633 //填充表格内容 第2行 634 newTable1.Cell(2, 2).Range.Text = "起止时间 (精确到月)"; 635 newTable1.Cell(2, 2).Merge(newTable1.Cell(2, 4)); 636 newTable1.Cell(2, 3).Range.Text = "单位名称"; 637 newTable1.Cell(2, 3).Merge(newTable1.Cell(2, 4)); 638 newTable1.Cell(2, 4).Range.Text = "岗 位/职 务"; 639 newTable1.Cell(2, 5).Range.Text = "主要职责(20字以内)"; 640 newTable1.Cell(2, 6).Range.Text = "证明人/联系方式"; 641 642 string sqlgz = "select * from hr_quanzhigongzuo where id in ( select top 6 " + 643 " id from hr_quanzhigongzuo where uid='" + uid + "' order by id desc ) order by id asc "; 644 DataTable datgz = ZWL.DBUtility.MyDBHelp.GetDataTable(sqlgz); 645 if (datgz.Rows.Count > 0) 646 { 647 648 for (int i = 0; i < datgz.Rows.Count; i++) 649 { 650 newTable1.Cell(i + 3, 2).Range.Text = DateTime.Parse(datgz.Rows["t1"].ToString()).ToString("yyyy.MM") + " 至 " + 651 DateTime.Parse(datgz.Rows["t2"].ToString()).ToString("yyyy.MM"); 652 newTable1.Cell(i + 3, 2).Merge(newTable1.Cell(i + 3, 4)); 653 newTable1.Cell(i + 3, 3).Range.Text = datgz.Rows["gongzuodanwei"].ToString(); 654 newTable1.Cell(i + 3, 3).Merge(newTable1.Cell(i + 3, 4)); 655 newTable1.Cell(i + 3, 4).Range.Text = datgz.Rows["zhiwu"].ToString(); 656 newTable1.Cell(i + 3, 5).Range.Text = datgz.Rows["zhuyao"].ToString(); 657 newTable1.Cell(i + 3, 6).Range.Text = datgz.Rows["zhengming"].ToString(); 658 } 659 660 for (int i = datgz.Rows.Count + 3; i < 9; i++) 661 { 662 newTable1.Cell(i, 2).Range.Text = ""; 663 newTable1.Cell(i, 2).Merge(newTable1.Cell(i, 4)); 664 newTable1.Cell(i, 2).Select();//选中一行 665 WordApp.Selection.ParagraphFormat.LineSpacing = 25f; 666 newTable1.Cell(i, 3).Range.Text = ""; 667 newTable1.Cell(i, 3).Merge(newTable1.Cell(i, 4)); 668 newTable1.Cell(i, 4).Range.Text = ""; 669 newTable1.Cell(i, 5).Range.Text = ""; 670 newTable1.Cell(i, 6).Range.Text = ""; 671 } 672 673 } 674 else 675 { 676 for (int i = 3; i < 9; i++) 677 { 678 newTable1.Cell(i, 2).Range.Text = ""; 679 newTable1.Cell(i, 2).Merge(newTable1.Cell(i, 4)); 680 newTable1.Cell(i, 2).Select();//选中一行 681 WordApp.Selection.ParagraphFormat.LineSpacing = 25f; 682 newTable1.Cell(i, 3).Range.Text = ""; 683 newTable1.Cell(i, 3).Merge(newTable1.Cell(i, 4)); 684 newTable1.Cell(i, 4).Range.Text = ""; 685 newTable1.Cell(i, 5).Range.Text = ""; 686 newTable1.Cell(i, 6).Range.Text = ""; 687 } 688 689 } 690 691 //填充表格内容 第9行 692 newTable1.Cell(9, 1).Range.Text = "家庭成员"; 693 newTable1.Cell(9, 1).Merge(newTable1.Cell(12, 1)); 694 newTable1.Cell(9, 2).Range.Text = "关 系"; 695 newTable1.Cell(9, 2).Merge(newTable1.Cell(9, 4)); 696 newTable1.Cell(9, 2).Select();//选中一行 697 WordApp.Selection.ParagraphFormat.LineSpacing = 25f; 698 //WordApp.Selection.MoveDown(ref WdLine1, ref count1, ref missing1);//光标向下移1行 699 700 701 702 newTable1.Cell(9, 3).Range.Text = "姓 名"; 703 newTable1.Cell(9, 4).Range.Text = "出生日期"; 704 newTable1.Cell(9, 5).Range.Text = "政治面貌"; 705 newTable1.Cell(9, 6).Range.Text = "工作单位及职务(如退休填写退休前单位)"; 706 newTable1.Cell(9, 6).Merge(newTable1.Cell(9, 7)); 707 708 string sqljt = " select top 3 * from hr_jiating where uid='" + uid + "' "; 709 DataTable datjt = ZWL.DBUtility.MyDBHelp.GetDataTable(sqljt); 710 711 if (datjt.Rows.Count > 0) 712 { 713 714 for (int i = 0; i < datjt.Rows.Count; i++) 715 { 716 newTable1.Cell(i + 10, 2).Range.Text = datjt.Rows["guanli"].ToString(); 717 newTable1.Cell(i + 10, 2).Merge(newTable1.Cell(i + 10, 4)); 718 newTable1.Cell(i + 10, 2).Select();//选中一行 719 WordApp.Selection.ParagraphFormat.LineSpacing = 25f; 720 newTable1.Cell(i + 10, 3).Range.Text = datjt.Rows["name"].ToString(); 721 newTable1.Cell(i + 10, 4).Range.Text = DateTime.Parse(datjt.Rows["createdate"].ToString()).ToString("yyyy.MM"); 722 newTable1.Cell(i + 10, 5).Range.Text = datjt.Rows["zhengzhi"].ToString(); 723 newTable1.Cell(i + 10, 6).Range.Text = datjt.Rows["gongzuodanwei"].ToString(); 724 newTable1.Cell(i + 10, 6).Merge(newTable1.Cell(i + 10, 7)); 725 } 726 727 for (int i = datjt.Rows.Count + 10; i < 13; i++) 728 { 729 newTable1.Cell(i, 2).Range.Text = ""; 730 newTable1.Cell(i, 2).Merge(newTable1.Cell(i, 4)); 731 newTable1.Cell(i, 2).Select();//选中一行 732 WordApp.Selection.ParagraphFormat.LineSpacing = 25f; 733 newTable1.Cell(i, 3).Range.Text = ""; 734 newTable1.Cell(i, 4).Range.Text = ""; 735 newTable1.Cell(i, 5).Range.Text = ""; 736 newTable1.Cell(i, 6).Range.Text = ""; 737 newTable1.Cell(i, 6).Merge(newTable1.Cell(i, 7)); 738 } 739 740 } 741 else 742 { 743 for (int i = 10; i < 13; i++) 744 { 745 newTable1.Cell(i, 2).Range.Text = ""; 746 newTable1.Cell(i, 2).Merge(newTable1.Cell(i, 4)); 747 newTable1.Cell(i, 2).Select();//选中一行 748 WordApp.Selection.ParagraphFormat.LineSpacing = 25f; 749 newTable1.Cell(i, 3).Range.Text = ""; 750 newTable1.Cell(i, 4).Range.Text = ""; 751 newTable1.Cell(i, 5).Range.Text = ""; 752 newTable1.Cell(i, 6).Range.Text = ""; 753 newTable1.Cell(i, 6).Merge(newTable1.Cell(i, 7)); 754 } 755 756 } 757 758 //填充表格内容 第13行 759 newTable1.Cell(13, 1).Range.Text = "自我鉴定"; 760 newTable1.Cell(13, 2).Range.Text = dat.Rows[0]["jianding"].ToString(); 761 newTable1.Cell(13, 2).Merge(newTable1.Cell(13, 9)); 762 763 //填充表格内容 第14行 764 newTable1.Cell(14, 1).Range.Text = "劳动合同签订情况"; 765 newTable1.Cell(14, 1).Merge(newTable1.Cell(14, 4)); 766 if (dat.Rows[0]["iflizhi"].ToString().Equals("1")) 767 { 768 newTable1.Cell(14, 2).Range.Text = "√目前与其他单位不存在劳动关系; " + 769 "□目前与原单位尚未解除劳动合同,但承诺最迟在到岗时可以提供解除劳动合同证明;" + 770 "□其他(请说明)"; 771 } 772 else if (dat.Rows[0]["iflizhi"].ToString().Equals("2")) 773 { 774 newTable1.Cell(14, 2).Range.Text = "□目前与其他单位不存在劳动关系; " + 775 "√目前与原单位尚未解除劳动合同,但承诺最迟在到岗时可以提供解除劳动合同证明;" + 776 "□其他(请说明)"; 777 } 778 else 779 { 780 newTable1.Cell(14, 2).Range.Text = "□目前与其他单位不存在劳动关系; " + 781 "□目前与原单位尚未解除劳动合同,但承诺最迟在到岗时可以提供解除劳动合同证明;" + 782 "√其他(" + dat.Rows[0]["iflizhi"].ToString() + ")"; 783 } 784 newTable1.Cell(14, 2).Merge(newTable1.Cell(14, 6)); 785 786 string sqlyp = " select date from hr_yingpin where uid = '" + uid + "'"; 787 string nian = ""; 788 DataTable datyp = ZWL.DBUtility.MyDBHelp.GetDataTable(sqlyp); 789 if (datyp.Rows.Count > 0) 790 { 791 nian = DateTime.Parse(datyp.Rows[0]["date"].ToString()).ToString("yyyy年MM月dd日"); 792 } 793 //填充表格内容 第15行 794 newTable1.Cell(15, 1).Range.Text = "个人声明"; 795 newTable1.Cell(15, 1).Merge(newTable1.Cell(15, 2)); 796 newTable1.Cell(15, 1).Merge(newTable1.Cell(17, 2)); 797 newTable1.Cell(15, 2).Range.Text = " 本人郑重声明,我在上述表中提的有关信息真实准确,并愿意承担因任何虚假与不实造成的一切后果;本人同意可在必要的情况下对有关信息进行核实。"; 798 newTable1.Cell(15, 2).Merge(newTable1.Cell(15, 8)); 799 800 //填充表格内容 第16行 801 802 newTable1.Cell(16, 2).Range.Text = " 此外,我清楚以下事实:如果在30天内没有接到面试通知,本次申请可能失效,个人简历将进入公司人才库,不予退回。"; 803 newTable1.Cell(16, 2).Merge(newTable1.Cell(16, 8)); 804 805 //填充表格内容 第17行 806 807 newTable1.Cell(17, 2).Range.Text = " 应聘者签名:" + dat.Rows[0]["name"].ToString() + " " + nian; 808 newTable1.Cell(17, 2).Merge(newTable1.Cell(17, 8)); 809 810 object saveOption = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges; 811 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); 812 WordDoc.Close(ref Nothing, ref Nothing, ref Nothing); 813 WordApp.Application.Quit(ref saveOption, ref Nothing, ref Nothing); 814 WordDoc = null; 815 WordApp = null; 816 killAllProcess(); 817 message = name + "文档生成成功,"; 818 //} 819 //catch 820 //{ 821 // message = "文件导出异常!"; 822 //} 823 return message; 824 } 825 public DataTable getXueLi(string xueli) 826 { 827 string sql = "select * from hr_jiaoyu where uid='" + dat.Rows[0]["id"].ToString() + "' and xueli ='" + xueli + "' "; 828 DataTable datxue = ZWL.DBUtility.MyDBHelp.GetDataTable(sql); 829 return datxue; 830 } 831 protected void killAllProcess() // 杀掉所有winword.exe进程 832 { 833 System.Diagnostics.Process[] myPs; 834 myPs = System.Diagnostics.Process.GetProcesses(); 835 foreach (System.Diagnostics.Process p in myPs) 836 { 837 if (p.Id != 0) 838 { 839 string myS = "WINWORD.EXE" + p.ProcessName + " ID:" + p.Id.ToString(); 840 try 841 { 842 if (p.Modules != null) 843 if (p.Modules.Count > 0) 844 { 845 System.Diagnostics.ProcessModule pm = p.Modules[0]; 846 myS += "\n Modules[0].FileName:" + pm.FileName; 847 myS += "\n Modules[0].ModuleName:" + pm.ModuleName; 848 myS += "\n Modules[0].FileVersionInfo:\n" + pm.FileVersionInfo.ToString(); 849 if (pm.ModuleName.ToLower() == "winword.exe") 850 p.Kill(); 851 } 852 } 853 catch 854 { } 855 finally 856 { 857 } 858 } 859 } 860 } 861 public bool IsReusable 862 { 863 get 864 { 865 return false; 866 } 867 } 868 869 }
调用方法:
1 private void Export(string id) 2 { 3 string wjname =DateTime.Now.ToString("yyyyMMddhhmmssfff"); 4 string filepath = Server.MapPath("./ReportFile/") + wjname; 5 Directory.CreateDirectory(filepath); //创建文件所在目录 6 ExportWord dao = new ExportWord(); 7 if (id.IndexOf(',') > -1) 8 { 9 10 string[] strs = id.Split(','); 11 for (int i = 0; i < strs.Length; i++) 12 { 13 string sql = " select name from hr_person where id =" + strs; 14 DataTable dat = ZWL.DBUtility.MyDBHelp.GetDataTable(sql); 15 dao.ProcessRequest(Context, strs, filepath + "/" + dat.Rows[0]["name"].ToString() +i+ ".doc"); 16 } 17 18 DirectoryToZip(filepath, Server.MapPath("./ReportFile/" + wjname + ".zip")); 19 Response.Write("<script>window.location='ReportFile/" + wjname + ".zip'</script>"); 20 21 } 22 else 23 { 24 string sql = " select name from hr_person where id =" + id; 25 DataTable dat = ZWL.DBUtility.MyDBHelp.GetDataTable(sql); 26 dao.ProcessRequest(Context, id, filepath + "/" +dat.Rows[0]["name"].ToString() + ".doc"); 27 Response.Write("<script>window.location='ReportFile/" + wjname+"/" + dat.Rows[0]["name"].ToString() + ".doc'</script>"); 28 29 } 30 31 } 32 //【filepath想要压缩文件的地址】 33 //【zippath输出压缩文件的地址】 34 private void DirectoryToZip(string path, string address) 35 { 36 //获取当前文件夹中所有的文件 37 string[] filenames = Directory.GetFiles(path); 38 Crc32 crc = new Crc32(); 39 //创建输出文件(ZIP格式的文件) 40 ZipOutputStream zos = new ZipOutputStream(File.Create(address)); 41 zos.SetLevel(6); 42 //遍历所有的文件 43 foreach (string name in filenames) 44 { 45 FileStream fs = File.OpenRead(name); 46 byte[] buffer = new byte[fs.Length]; 47 //读取文件 48 fs.Read(buffer, 0, Convert.ToInt32(fs.Length)); 49 //获取文件的文件名称和后缀名 50 string file = Path.GetFileName(name); 51 //输出文件的名称 52 ZipEntry entry = new ZipEntry(file); 53 crc.Reset(); 54 crc.Update(buffer); 55 entry.Crc = crc.Value; 56 zos.PutNextEntry(entry); 57 zos.Write(buffer, 0, Convert.ToInt32(fs.Length)); 58 fs.Close(); 59 } 60 zos.Finish(); 61 zos.Close(); 62 }
有什么问大家可以讨论,讨论,我也只是研究了,一周,有许多都是 ,网上找其他人的,效果如图片
Tencent\Users\516383992\QQ\WinTemp\RichOle\8UU6$%1V65@UC~)N16NS6$3.jpg" alt="" />