最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#生成Word文檔代碼示例

 更新時間:2015年06月04日 15:05:55   投稿:junjie  
這篇文章主要介紹了C#生成Word文檔代碼示例,本文直接給出代碼實例,需要的朋友可以參考下
public bool CreateWordFile(string _filename, "數(shù)據(jù)List或者你C#要寫的數(shù)據(jù)")
    {
            #region 開始生成Word
      try
      {

        string strtitle = "任務(wù)導(dǎo)出";
        object oEndOfDoc = "http://endofdoc";
        Object Nothing = System.Reflection.Missing.Value;
        Object filename = _filename;
        //創(chuàng)建Word文檔

        Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
        Microsoft.Office.Interop.Word.Document WordDoc = WordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);


        //設(shè)置頁眉
        WordApp.ActiveWindow.View.Type = Microsoft.Office.Interop.Word.WdViewType.wdOutlineView;
        WordApp.ActiveWindow.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekPrimaryHeader;
        WordApp.ActiveWindow.ActivePane.Selection.InsertAfter("WPFOA任務(wù)導(dǎo)出");
        WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;//設(shè)置右對齊
        WordApp.ActiveWindow.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekMainDocument;//跳出頁眉設(shè)置
        //任務(wù)導(dǎo)出------名字
        Word.Paragraph oPara1;
        oPara1 = WordDoc.Content.Paragraphs.Add(ref Nothing);
        oPara1.Range.Text = strtitle;
        oPara1.Range.Font.Bold = 1;
        oPara1.Range.Font.Name = "宋體";
        oPara1.Range.Font.Size = 20;
        oPara1.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
        oPara1.Format.SpaceAfter = 5;  //24 pt spacing after paragraph.
        oPara1.Range.InsertParagraphAfter();
        #region 循環(huán)每個表

        foreach (var v in lst_task)
        {
          #region 循環(huán)每一個列,產(chǎn)生一行數(shù)據(jù)
          //描述信息
          Word.Paragraph oPara3;
          object oRng = WordDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
          oPara3 = WordDoc.Content.Paragraphs.Add(ref oRng);
          oPara3.Range.Text = "";
          oPara3.Range.Font.Bold = 0;
          oPara3.Range.Font.Name = "宋體";
          oPara3.Range.Font.Size = 9;
          oPara3.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
          oPara3.Format.SpaceBefore = 1;
          oPara3.Format.SpaceAfter = 1;
          oPara3.Range.InsertParagraphAfter();

          //插入表格     
          Word.Table newTable;
          Word.Range wrdRng = WordDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
          newTable = WordDoc.Tables.Add(wrdRng, 5, 4, ref Nothing, ref Nothing);
          newTable.Columns[1].Width = 60;
          newTable.Columns[2].Width = 145;
          newTable.Columns[3].Width = 80;
          newTable.Columns[4].Width = 145;
          newTable.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
          newTable.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;

          //填充表格內(nèi)容
          newTable.Cell(1, 1).Range.Text = "項目名稱";
          newTable.Cell(1, 2).Range.Text = "1";
          newTable.Cell(1, 3).Range.Text = "模塊名稱";
          newTable.Cell(1, 4).Range.Text = "2";
          newTable.Cell(2, 1).Range.Text = "負(fù)責(zé)人名";
          newTable.Cell(2, 2).Range.Text = "3";
          newTable.Cell(2, 3).Range.Text = "狀態(tài)";
          newTable.Cell(2, 4).Range.Text = "4";
          newTable.Cell(3, 1).Range.Text = "發(fā)布時間";
          newTable.Cell(3, 2).Range.Text = "5";
          newTable.Cell(3, 3).Range.Text = "要求完成時間";
          newTable.Cell(3, 4).Range.Text = "6";
          newTable.Cell(4, 1).Range.Text = "完成時間";
          newTable.Cell(4, 2).Range.Text = "7";
          newTable.Cell(4, 3).Range.Text = "分配人";
          newTable.Cell(4, 4).Range.Text = "8";
          newTable.Cell(5, 1).Range.Text = "任務(wù)描述";
          newTable.Cell(5, 2).Merge(newTable.Cell(5, 4));
          newTable.Cell(5, 2).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
          newTable.Cell(5, 2).Range.Text = "12313213123213";
          #endregion
        }


        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);

        WordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
        WordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
        #endregion
        //關(guān)閉WinWord進(jìn)程
        System.Diagnostics.Process[] MyProcess = System.Diagnostics.Process.GetProcessesByName("WINWORD");
        MyProcess[0].Kill();
        return true;

      }
      catch
      {

        System.Diagnostics.Process[] MyProcess = System.Diagnostics.Process.GetProcessesByName("WINWORD");
        MyProcess[0].Kill();
        return false;
      }
      #endregion
    }


相關(guān)文章

最新評論

兰坪| 黑山县| 乌鲁木齐市| 邹城市| 苏尼特左旗| 孝义市| 三明市| 汝城县| 革吉县| 陕西省| 哈密市| 新乐市| 通州市| 长丰县| 微山县| 德兴市| 桐城市| 望奎县| 肥乡县| 江华| 湟中县| 尉犁县| 宝坻区| 通州区| 乃东县| 屏山县| 潢川县| 泰州市| 静海县| 平乐县| 郯城县| 枝江市| 临城县| 旺苍县| 宝清县| 贡嘎县| 宁化县| 独山县| 金湖县| 乡城县| 东乌珠穆沁旗|