日韩欧美人妻无码精品白浆,www.大香蕉久久网,狠狠的日狠狠的操,日本好好热在线观看

LOGO OA教程 ERP教程 模切知識(shí)交流 PMS教程 CRM教程 開(kāi)發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

C# 動(dòng)態(tài)生成word文檔

admin
2025年5月19日 8:59 本文熱度 910

本文以一個(gè)簡(jiǎn)單的小例子,簡(jiǎn)述利用C#語(yǔ)言開(kāi)發(fā)word表格相關(guān)的知識(shí),僅供學(xué)習(xí)分享使用,如有不足之處,還請(qǐng)指正。

在工程中引用word的動(dòng)態(tài)庫(kù)

在項(xiàng)目中,點(diǎn)擊項(xiàng)目名稱右鍵-->管理NuGet程序包,打開(kāi)NuGet包管理器窗口,進(jìn)行搜索下載即可,如下圖所示:

涉及知識(shí)點(diǎn)

  1. _Application:表示word應(yīng)用程序的接口,對(duì)應(yīng)的實(shí)現(xiàn)類是Application類。

  2. _Document:表示一個(gè)word文檔,通過(guò)_Application對(duì)應(yīng)的文檔接口進(jìn)行創(chuàng)建。

  3. Paragraph:表示一個(gè)段落,通過(guò)_Document對(duì)象的相關(guān)方法進(jìn)行創(chuàng)建。

  4. Table:表示一個(gè)表格,通過(guò)_Document對(duì)象的相關(guān)方法進(jìn)行創(chuàng)建。

  5. Range:表示一個(gè)區(qū)域,可以是一個(gè)段落,也可以是一個(gè)表格,也可以是一個(gè)單元格,可以Range.select()將光標(biāo)移動(dòng)到當(dāng)前區(qū)域。

  6. 移動(dòng)焦點(diǎn):wordApp.Selection.MoveDown(ref wdLine, ref ncount, ref oMissing);//移動(dòng)焦點(diǎn)

生成文檔效果圖

核心代碼


using Microsoft.Office.Interop.Word; using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace ETWord {     public class WordHelper     {         public static void CreateWordFile(string filePath)         {                         try             {                 CreateFile(filePath);                 //                 MessageFilter.Register();                 object wdLine = WdUnits.wdLine;                 object oMissing = Missing.Value;                 object fileName = filePath;                 object heading2 = WdBuiltinStyle.wdStyleHeading2;                 object heading3 = WdBuiltinStyle.wdStyleHeading3;                                 _Application wordApp = new Application();                 wordApp.Visible = true;                 _Document wordDoc = wordApp.Documents.Open(ref fileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);                 System.Data.DataTable dtDepts = DatabaseHelper.getDept();                 int ii = 0;                 foreach (DataRow dr in dtDepts.Rows)                 {                     string dept = dr["dept"].ToString();                     Paragraph oPara0 = wordDoc.Content.Paragraphs.Add(ref oMissing);                     oPara0.Range.Text = string.Format("{0}-{1}", ii + 1, dept);                     //oPara0.Range.Font.Bold = 1;                     //oPara0.Format.SpaceAfter = 5;                     oPara0.Range.Select();                     oPara0.set_Style(ref heading2);                     oPara0.Range.InsertParagraphAfter();                     System.Data.DataTable dtTemplate = DatabaseHelper.getTemplateByDept(dept);                     int jj = 0;                     foreach (DataRow dr1 in dtTemplate.Rows)                     {                         string template = dr1["template"].ToString();                         string user1 = dr1["user1"].ToString();                         string remark = dr1["remark"].ToString();                         System.Data.DataTable dtData = DatabaseHelper.getDataByDeptAndTemplate(dept, template);                         int count = dtData.Rows.Count;                         int row = count + 4;                         int column = 5;                         object ncount = 1;                         wordApp.Selection.MoveDown(ref wdLine, ref ncount, ref oMissing);                         wordApp.Selection.TypeParagraph();                         Paragraph oPara1 = wordDoc.Content.Paragraphs.Add(ref oMissing);                         oPara1.Range.Select();                         oPara1.Range.Text = string.Format("{0}-{1}、{2}", ii + 1, jj + 1, template);                         //oPara1.Range.Font.Bold = 1;                         //oPara1.Format.SpaceAfter = 5;                         oPara1.set_Style(ref heading3);                         oPara1.Range.InsertParagraphAfter();                         wordApp.Selection.MoveDown(ref wdLine, ref ncount, ref oMissing);                         wordApp.Selection.TypeParagraph();                         //設(shè)置表格                         Table table = wordDoc.Tables.Add(wordApp.Selection.Range, row, column, ref oMissing, ref oMissing);                                                 table.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleSingle;                         table.Borders.InsideLineStyle = WdLineStyle.wdLineStyleSingle;                         table.Range.Font.Bold = 0;                         table.PreferredWidthType = WdPreferredWidthType.wdPreferredWidthAuto;                         table.Columns[1].Width = 60f;                         table.Columns[2].Width = 100f;                         table.Columns[3].Width = 100f;                         table.Columns[4].Width = 60f;                         table.Columns[5].Width = 100f;                         //列的合并                         Cell cell = table.Cell(1, 2);                         cell.Merge(table.Cell(1, 5));                         Cell cell2 = table.Cell(2, 2);                         cell2.Merge(table.Cell(2, 5));                         Cell cell3 = table.Cell(3, 2);                         cell3.Merge(table.Cell(3, 5));                         //賦值                         table.Cell(1, 1).Range.Text = "流程名稱:";                         table.Cell(2, 1).Range.Text = "使用人:";                         table.Cell(3, 1).Range.Text = "流程說(shuō)明:";                         table.Cell(4, 1).Range.Text = "節(jié)點(diǎn)";                         table.Cell(4, 2).Range.Text = "節(jié)點(diǎn)名";                         table.Cell(4, 3).Range.Text = "處理人員";                         table.Cell(4, 4).Range.Text = "處理方式";                         table.Cell(4, 5).Range.Text = "跳轉(zhuǎn)信息";                         table.Cell(1, 2).Range.Text = template;                         table.Cell(2, 2).Range.Text = user1;                         table.Cell(3, 2).Range.Text = remark;                         int kk = 5;                         foreach (DataRow dr2 in dtData.Rows)                         {                             table.Cell(kk, 1).Range.Text = (kk - 4).ToString();                             table.Cell(kk, 2).Range.Text = dr2["NodeName"].ToString();                             table.Cell(kk, 3).Range.Text = dr2["DoName"].ToString();                             table.Cell(kk, 4).Range.Text = dr2["DoType"].ToString();                             table.Cell(kk, 5).Range.Text = string.Empty;                             kk++;                         }                         table.Cell(kk - 1, 5).Range.Select();                         wordApp.Selection.MoveDown(ref wdLine, ref ncount, ref oMissing);//移動(dòng)焦點(diǎn)                         wordApp.Selection.TypeParagraph();//插入段落                         jj++;                     }                     ii++;                 }                 //保存                 wordDoc.Save();                 wordDoc.Close(ref oMissing, ref oMissing, ref oMissing);                 wordApp.Quit(ref oMissing, ref oMissing, ref oMissing);                 MessageFilter.Revoke();             }             catch (Exception e)             {                 Console.WriteLine(e.Message);                 Console.WriteLine(e.StackTrace);             }         }         private static void CreateFile(string filePath)         {             if (!File.Exists(filePath))             {                 using (FileStream fs = File.Create(filePath))                 {                 }             }         }     } }


關(guān)于word開(kāi)發(fā)中字體大小

滿足中文出版中使用字號(hào)作為字體大小的單位的需要,它允許用戶同時(shí)使用“號(hào)”和 “磅”作為字體大小的單位。

磅值與字號(hào)之間的換算關(guān)系如下:

word中設(shè)置寬度時(shí),采用磅為單位,磅與厘米之間的換算關(guān)系如下:

 

備注

  1.  插入多個(gè)表格時(shí),表格容易嵌套,主要是由于往下移動(dòng)的行數(shù)不對(duì),后來(lái)通過(guò)選中表格右下角的單元格,將光標(biāo)移動(dòng)到表格右下角,然后再往下移動(dòng)兩行,即可解決表格嵌套的問(wèn)題。

  2. 單元格合并問(wèn)題,當(dāng)單元格合并時(shí),單元格的位置也隨之改變,如:水平方向第二,三兩個(gè)單元格合并,則原來(lái)的第四個(gè)單元格的坐標(biāo)就會(huì)變成第三個(gè)單元格。

  3. 開(kāi)發(fā)運(yùn)行需要在電腦上安裝office組件,或者也可以安裝wps。

關(guān)于源碼下載鏈接https://files.cnblogs.com/files/hsiang/ETWord.rar?


閱讀原文:原文鏈接


該文章在 2025/5/19 10:05:24 編輯過(guò)
關(guān)鍵字查詢
相關(guān)文章
正在查詢...
點(diǎn)晴ERP是一款針對(duì)中小制造業(yè)的專業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國(guó)內(nèi)大量中小企業(yè)的青睞。
點(diǎn)晴PMS碼頭管理系統(tǒng)主要針對(duì)港口碼頭集裝箱與散貨日常運(yùn)作、調(diào)度、堆場(chǎng)、車(chē)隊(duì)、財(cái)務(wù)費(fèi)用、相關(guān)報(bào)表等業(yè)務(wù)管理,結(jié)合碼頭的業(yè)務(wù)特點(diǎn),圍繞調(diào)度、堆場(chǎng)作業(yè)而開(kāi)發(fā)的。集技術(shù)的先進(jìn)性、管理的有效性于一體,是物流碼頭及其他港口類企業(yè)的高效ERP管理信息系統(tǒng)。
點(diǎn)晴WMS倉(cāng)儲(chǔ)管理系統(tǒng)提供了貨物產(chǎn)品管理,銷(xiāo)售管理,采購(gòu)管理,倉(cāng)儲(chǔ)管理,倉(cāng)庫(kù)管理,保質(zhì)期管理,貨位管理,庫(kù)位管理,生產(chǎn)管理,WMS管理系統(tǒng),標(biāo)簽打印,條形碼,二維碼管理,批號(hào)管理軟件。
點(diǎn)晴免費(fèi)OA是一款軟件和通用服務(wù)都免費(fèi),不限功能、不限時(shí)間、不限用戶的免費(fèi)OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved

91中文欧美日韩| 大鸡吧插逼爽| 人妻热九九| 久久婷婷综合网站| 欧洲日韩成人在线观看| 日韩男女午夜网站在线观看| 麻豆精品无码国产一区二区| 欧美日本一区二区三区无广告| 人人操叉人人摸人人爽| 黄色小说免費看| 亚洲精品成人无码在线视频观看| 欧日韩视频精选二区| 国产久久久av青草| 欧美淫秽影院一区二区三区| 久久久无码精品亚洲日韩蜜臀网| 日本超污网站一区二区三区| 黑人大鸡吧超大粗视频免费观看| 这里只有精品欧美韩| 中文字幕久久精品亚洲| 精品一区二区三区四区禁| 国产受爱视频| 97干在线播放| 唯美激情传媒在线| 大香蕉调教| 用鸡巴插美女的逼码垛免费观看| 精品一区二区三区四| 黄色成人视频麻豆| 草b日b搞bc干bc| 日韩制服丝袜高清无码一区二区| 少妇aⅤ一区二区| 欧美护士激情第一欧美精品| 熟女视频一区综合网| 亚洲肛交免费性欲视频 | 搜索欧美第一级黄片| 国产粉嫩美女无套久久久| 蜜月二区在线视频| 二三四级片| 一区二区图片区视频区在线资源| 久热在线116| 国产一区二区三区三区在线观看| 亚洲热久久|