麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

c#(.net) 導出 word表格

2019-11-17 01:47:55
字體:
來源:轉載
供稿:網友

c#(.net) 導出 Word表格

做了差不多一周的導出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          49             Object Nothing = System.Reflection.Missing.Value; 50             52             object filename = name;  //文件保存路徑   53          54             //創建Word文檔  55             Microsoft.Office.Interop.Word.application WordApp = new Microsoft.Office.Interop.Word.ApplicationClass(); 56            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              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              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             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              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             else155             {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(n
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 欧美成人午夜精品久久久 | 亚洲精品v天堂中文字幕 | 精品视频在线免费看 | 午夜精品老牛av一区二区三区 | 看黄在线观看 | 精品一区二区三区免费视频 | 日本免费不卡一区二区 | 鲁丝一区二区二区四区 | 青青草国产在线视频 | 国产精品一区2区3区 | av不卡毛片| 黄色片免费在线 | 久久久久亚洲视频 | 国产亚洲精品久久午夜玫瑰园 | 嗯~啊~弄嗯~啊h高潮视频 | 免费观看视频网站 | 精品视频 久久久 | 看免费的毛片 | 狠狠久久伊人中文字幕 | 99影视在线视频免费观看 | www.精品视频 | 最新中文字幕在线视频 | 羞羞草视频 | 亚洲午夜天堂吃瓜在线 | 日韩视频一二三 | 91久久综合| 黄色视屏免费观看 | 成年人黄色免费电影 | 国产成人高清成人av片在线看 | 竹内纱里奈和大战黑人 | 欧洲精品视频在线观看 | 爽爽淫人综合网网站 | 亚洲精品无码不卡在线播放he | 激情在线视频 | 天天看夜夜爽 | 久草视频国产在线 | av在线播放网址 | 国产精品久久久久久影视 | 久久影院一区二区三区 | 免费国产成人高清在线看软件 | 欧美人的天堂一区二区三区 |