欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

C#操作word封裝

系統(tǒng) 2110 0

在項(xiàng)目中添加Microsoft.Office.Interop.Word.dll引用

Code
public ?? class ??WordAPI
{
????
private ? object ?_template;
????
private ? object ?_newWord;
????
private ?Microsoft.Office.Interop.Word.Application?wordApp;
????
private ?Microsoft.Office.Interop.Word.Document?_wordDocument;
????
private ? object ?defaultV? = ?System.Reflection.Missing.Value;
????
private ? object ?documentType;
????
/// ? <summary>
????
/// ?構(gòu)造函數(shù)
????
/// ? </summary>
????
/// ? <param?name="template"> 模板文件位置 </param>
????
/// ? <param?name="newWord"> 保存位置 </param>
???? public ?WordAPI( string ?template, string ?newWord)
????{
????????
this ._template? = ?template;
????????
this ._newWord? = ?newWord;
????????wordApp?
= ? new ?Application();
????????documentType?
= ?Microsoft.Office.Interop.Word.WdDocumentType.wdTypeDocument;
????????_wordDocument?
= ?wordApp.Documents.Add( ref ?_template,? ref ?defaultV,? ref ?documentType,? ref ?defaultV);
????}
????
/// ? <summary>
????
/// ?設(shè)置默認(rèn)一頁行數(shù)
????
/// ? </summary>
????
/// ? <param?name="size"></param>
???? public ? void ?SetLinesPage( int ?size)
????{
????????wordApp.ActiveDocument.PageSetup.LinesPage?
= ? 40 ;
????}
????
/// ? <summary>
????
/// ?設(shè)置書簽的值
????
/// ? </summary>
????
/// ? <param?name="markName"> 書簽名 </param>
????
/// ? <param?name="markValue"> 書簽值 </param>
???? public ? void ?SetBookMark( string ?markName,? string ?markValue)
????{
????????
object ?_markName? = markName;
????????
try
????????{
????????????_wordDocument.Bookmarks.get_Item(
ref ?_markName).Range.Text? = ?markValue;
????????}
????????
catch
????????{
????????????
throw ? new ?Exception(markName? + ? " 未找到!! " );
????????}
????}
????
/// ? <summary>
????
/// ?設(shè)置添加頁眉
????
/// ? </summary>
????
/// ? <param?name="context"> 內(nèi)容 </param>
???? public ? void ?SetPageHeader( string ?context)
????{
????????wordApp.ActiveWindow.View.Type?
= ?WdViewType.wdOutlineView;
????????wordApp.ActiveWindow.View.SeekView?
= ?WdSeekView.wdSeekPrimaryHeader;
????????wordApp.ActiveWindow.ActivePane.Selection.InsertAfter(context);
????????wordApp.Selection.ParagraphFormat.Alignment?
= WdParagraphAlignment.wdAlignParagraphCenter;
????????
// 跳出頁眉設(shè)置????
????????wordApp.ActiveWindow.View.SeekView? = ?WdSeekView.wdSeekMainDocument;???
????}
????
/// ? <summary>
????
/// ?當(dāng)前位置處插入文字
????
/// ? </summary>
????
/// ? <param?name="context"> 文字內(nèi)容 </param>
????
/// ? <param?name="fontSize"> 字體大小 </param>
????
/// ? <param?name="fontColor"> 字體顏色 </param>
????
/// ? <param?name="fontBold"> 粗體 </param>
????
/// ? <param?name="familyName"> 字體 </param>
????
/// ? <param?name="align"> 對齊方向 </param>
???? public ? void ?InsertText( string ?context,? int ?fontSize,?WdColor?fontColor,? int ?fontBold, string ?familyName,?WdParagraphAlignment?align)
????{
????????
// 設(shè)置字體樣式以及方向????
????????wordApp.Application.Selection.Font.Size? = ?fontSize;
????????wordApp.Application.Selection.Font.Bold?
= ?fontBold;
????????wordApp.Application.Selection.Font.Color?
= ?fontColor;
????????wordApp.Selection.Font.Name?
= ?familyName;
????????wordApp.Application.Selection.ParagraphFormat.Alignment?
= ?align;
????????wordApp.Application.Selection.TypeText(context);???

????}
????
/// ? <summary>
????
/// ?翻頁
????
/// ? </summary>
???? public ? void ?ToNextPage()
????{
????????
object ?breakPage? = ?Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;
????????wordApp.Selection.InsertBreak(
ref ?breakPage);???
????}
????
/// ? <summary>
????
/// ?焦點(diǎn)移動count段落
????
/// ? </summary>
????
/// ? <param?name="count"></param>
???? public ? void ?MoveParagraph( int ?count)
????{
????????
object ?_count? = ?count;
????????
object ?wdP = ?WdUnits.wdParagraph; // 換一段落
????????wordApp.Selection.Move( ref ?wdP,? ref ?_count);
????}
????
/// ? <summary>
????
/// ?焦點(diǎn)移動count行
????
/// ? </summary>
????
/// ? <param?name="count"></param>
???? public ? void ?MoveRow( int ?count)
????{
????????
object ?_count? = ?count;
????????
object ?WdLine? = WdUnits.wdLine; // 換一行
????????wordApp.Selection.Move( ref ?WdLine,? ref ?_count);
????}
????
/// ? <summary>
????
/// ?焦點(diǎn)移動字符數(shù)
????
/// ? </summary>
????
/// ? <param?name="count"></param>
???? public ? void ?MoveCharacter( int ?count)
????{
????????
object ?_count? = ?count;
????????
object ?wdCharacter? = ?WdUnits.wdCharacter;
????????wordApp.Selection.Move(
ref ?wdCharacter,? ref ?_count);
????}
????
/// ? <summary>
????
/// ?插入段落
????
/// ? </summary>
???? public ? void ?ToNextParagraph()
????{
????????wordApp.Selection.TypeParagraph();
// 插入段落
????}

????
/// ? <summary>
????
/// ?回車換行
????
/// ? </summary>
???? public ? void ?ToNextLine()
????{
????????wordApp.Selection.TypeParagraph();?????????
????}
????
/// ? <summary>
????
/// ?當(dāng)前位置插入圖片
????
/// ? </summary>
????
/// ? <param?name="picture"></param>
???? public ? void ?InsertPicture( string ?picture)
????{?????????
????????
// 圖片居中顯示????
????????wordApp.Selection.ParagraphFormat.Alignment? = ?WdParagraphAlignment.wdAlignParagraphCenter;
????????wordApp.Application.Selection.InlineShapes.AddPicture(picture,?
ref ?defaultV,? ref ?defaultV,? ref ?defaultV);
????}
????
/// ? <summary>
????
/// ?添加表格
????
/// ? </summary>
????
/// ? <param?name="rowNum"></param>
????
/// ? <param?name="cellNum"></param>
????
/// ? <returns></returns>
???? public ?Table?CreatTable( int ?rowNum, int ?cellNum)
????{
??????
return ?? this ._wordDocument.Tables.Add(wordApp.Selection.Range,?rowNum,?cellNum,? ref ?defaultV,? ref ?defaultV);
????}
????
/// ? <summary>
????
/// ?設(shè)置列寬
????
/// ? </summary>
????
/// ? <param?name="widths"></param>
???? public ? void ?SetColumnWidth( float ?[]?widths,Table?tb)
????{
????????
if ?(widths.Length? > ? 0 )
????????{
????????????
int ?len? = widths.Length;
????????????
for ?( int ?i? = ? 0 ;?i? < ?len;?i ++ )
????????????{
????????????????tb.Columns[i].Width?
= ?widths[i];
????????????}
????????}
????}
????
/// ? <summary>
????
/// ?合并單元格
????
/// ? </summary>
????
/// ? <param?name="tb"></param>
????
/// ? <param?name="cells"></param>
???? public ? void ?MergeColumn(Table?tb,?Cell[]?cells)
????{
????????
if ?(cells.Length? > ? 1 )
????????{
????????????Cell?c?
= ?cells[ 0 ];
????????????
int ?len? = ?cells.Length;
????????????
for ?( int ?i? = ? 1 ;?i? < ?len;?i ++ )
????????????{
???????????????c.Merge(cells[i]);
????????????}
????????}
????????wordApp.Selection.Cells.VerticalAlignment?
= ?WdCellVerticalAlignment.wdCellAlignVerticalCenter;

????}
????
/// ? <summary>
????
/// ?設(shè)置單元格內(nèi)容
????
/// ? </summary>
????
/// ? <param?name="_c"></param>
????
/// ? <param?name="v"></param>
????
/// ? <param?name="align"> 對齊方式 </param>
???? public ? void ?SetCellValue(Cell?_c,? string ?v,?WdParagraphAlignment?align)
????{
????????wordApp.Selection.ParagraphFormat.Alignment?
= ?align;
????????_c.Range.Text?
= ?v;
????}

????
/// ? <summary>
????
/// ?保存新文件
????
/// ? </summary>
???? public ? void ?SaveAsWord()
????{
????????
object ?doNotSaveChanges? = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;
????????
try
????????{
????????????
object ?fileFormat? = ?WdSaveFormat.wdFormatRTF;
????????????_wordDocument.SaveAs(
ref ?_newWord,? ref ?fileFormat,? ref ?defaultV,? ref ?defaultV,? ref ?defaultV,? ref ?defaultV,? ref ?defaultV,? ref ?defaultV,? ref ?defaultV,
????????????????
ref ?defaultV,? ref ?defaultV,? ref ?defaultV,? ref ?defaultV,? ref ?defaultV,? ref ?defaultV,? ref ?defaultV);????????????
????????}
????????
catch ?(Exception?e)
????????{
????????????
throw ? new ?Exception(e.Message);
???????????
????????}
????????
finally
????????{
????????????disponse();
????????}
????}
????
/// ? <summary>
????
/// ?釋放資源
????
/// ? </summary>
???? private ? void ?disponse()
????{
????????
object ?missingValue? = ?Type.Missing;
????????
object ?doNotSaveChanges? = ?Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;
????????_wordDocument.Close(
ref ?doNotSaveChanges,? ref ?missingValue,? ref ?missingValue);
????????wordApp.Application.Quit(
ref ?defaultV,? ref ?defaultV,? ref ?defaultV);
????????_wordDocument?
= ? null ;
????????wordApp?
= ? null ;
????}

C#操作word封裝


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。。?/p>

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 日本成人在线网站 | 日韩免费观看视频 | 欧美电影精品久久久久 | 久久综合狠狠综合狠狠 | 久久黄色 | 91xxx在线观看 | 一区二区精品 | 久久久九九精品国产毛片A片 | 欧美福利一区二区三区 | 欧美精品18videosex性俄罗斯 | 农村寡妇偷人高潮A片小说 午夜爱爱爱爱爽爽爽网站免费 | 免费黄色日韩电影 | 亚洲国产欧美在线观看 | 97国产精品最新 | 草的爽免费视频 | 久久久久国产一区二区三区四区 | 中文字幕免费在线观看 | 国产精品久久久久久吹潮 | 日本高清视频www夜色资源网 | 成人夜晚看av | 久久久久久91香蕉国产 | 成人激情视频在线观看 | 日本精品一二三区 | 日韩日韩日韩日韩 | 日韩黄色在线视频 | 色播在线播放 | 国产成人综合网在线观看 | 国产va免费精品观看精品 | 久久草视频这里只精品99 | 色播欧美| 青草九九 | 天天躁日日躁aaaa视频 | 国产一区二区久久久 | 国产超碰人人做人人爱 | 91看片入口| 国产精品久久久爽爽爽麻豆色哟哟 | 欧美精品亚洲一区二区在线播放 | 亚洲一区二区三区在线播放 | 高清在线不卡 | 91在线视频观看 | 亚洲欧洲精品成人久久奇米网 |