///word應用對象///privateMicrosoft.Office.Interop.Word.Applicatio" />

日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

c#生成word文檔

系統(tǒng) 2247 0

? ? ?參考:http://blog.163.com/zhouchunping_99/blog/static/7837998820085114394716/

  1. 生成word文檔??

?

生成word文檔

view plain copy to clipboard print ?

?

  1. public?class?BiultReportForm ??
  2. ???{ ??
  3. ???????///?<SUMMARY></SUMMARY> ??
  4. ???????///?word?應用對象 ??
  5. ???????///? ??
  6. ???????private?Microsoft.Office.Interop.Word.Application?_wordApplication; ??
  7. ??
  8. ???????///?<SUMMARY></SUMMARY> ??
  9. ???????///?word?文件對象 ??
  10. ???????///? ??
  11. ???????private?Microsoft.Office.Interop.Word.Document?_wordDocument; ??
  12. ??
  13. ??
  14. ??
  15. ???????///?<SUMMARY></SUMMARY> ??
  16. ???????///?創(chuàng)建文檔 ??
  17. ???????///? ??
  18. ???????public?void?CreateAWord() ??
  19. ???????{ ??
  20. ???????????//實例化word應用對象 ??
  21. ???????????this._wordApplication?=?new?Microsoft.Office.Interop.Word.ApplicationClass(); ??
  22. ???????????Object?myNothing?=?System.Reflection.Missing.Value; ??
  23. ??
  24. ???????????this._wordDocument?=?this._wordApplication.Documents.Add(ref?myNothing,?ref?myNothing,?ref?myNothing,?ref?myNothing); ??
  25. ???????} ??
  26. ??
  27. ??
  28. ???????///?<SUMMARY></SUMMARY> ??
  29. ???????///?添加頁眉 ??
  30. ???????///? ??
  31. ???????///?<PARAM?name="pPageHeader"?/> ??
  32. ???????public?void?SetPageHeader(string?pPageHeader) ??
  33. ???????{ ??
  34. ???????????//添加頁眉 ??
  35. ???????????this._wordApplication.ActiveWindow.View.Type?=Microsoft?.Office?.Interop?.Word.WdViewType.wdOutlineView; ??
  36. ???????????this._wordApplication.ActiveWindow.View.SeekView?=?Microsoft.Office.Interop.Word.WdSeekView.wdSeekPrimaryHeader; ??
  37. ???????????this._wordApplication.ActiveWindow.ActivePane.Selection.InsertAfter(pPageHeader); ??
  38. ???????????//設置中間對齊 ??
  39. ???????????this._wordApplication.Selection.ParagraphFormat.Alignment?=Microsoft?.Office?.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; ??
  40. ???????????//跳出頁眉設置 ??
  41. ???????????this._wordApplication.ActiveWindow.View.SeekView?=?Microsoft.Office.Interop.Word.WdSeekView.wdSeekMainDocument; ??
  42. ???????} ??
  43. ??
  44. ??
  45. ??
  46. ???????///?<SUMMARY></SUMMARY> ??
  47. ???????///?插入文字 ??
  48. ???????///? ??
  49. ???????///?<PARAM?name="pText"?/>文本信息 ??
  50. ???????///?<PARAM?name="pFontSize"?/>字體打小 ??
  51. ???????///?<PARAM?name="pFontColor"?/>字體顏色 ??
  52. ???????///?<PARAM?name="pFontBold"?/>字體粗體 ??
  53. ???????///?<PARAM?name="ptextAlignment"?/>方向 ??
  54. ???????public?void?InsertText(string?pText,?int?pFontSize,?Microsoft.Office.Interop.Word.WdColor?pFontColor,?int?pFontBold,?Microsoft.Office.Interop.Word.WdParagraphAlignment?ptextAlignment) ??
  55. ???????{ ??
  56. ???????????//設置字體樣式以及方向 ??
  57. ???????????this._wordApplication.Application.Selection.Font.Size?=?pFontSize; ??
  58. ???????????this._wordApplication.Application.Selection.Font.Bold?=?pFontBold; ??
  59. ???????????this._wordApplication.Application.Selection.Font.Color=?pFontColor; ??
  60. ???????????this._wordApplication.Application.Selection.ParagraphFormat.Alignment?=?ptextAlignment; ??
  61. ???????????this._wordApplication.Application.Selection.TypeText(pText); ??
  62. ???????} ??
  63. ??
  64. ??
  65. ???????///?<SUMMARY></SUMMARY> ??
  66. ???????///?換行 ??
  67. ???????///? ??
  68. ???????public?void?NewLine() ??
  69. ???????{ ??
  70. ???????????//換行 ??
  71. ???????????this._wordApplication.Application.Selection.TypeParagraph(); ??
  72. ???????} ??
  73. ??
  74. ??
  75. ??
  76. ???????///?<SUMMARY></SUMMARY> ??
  77. ???????///?插入一個圖片 ??
  78. ???????///? ??
  79. ???????///?<PARAM?name="pPictureFileName"?/> ??
  80. ???????public?void?InsertPicture(string?pPictureFileName) ??
  81. ???????{ ??
  82. ???????????object?myNothing?=?System.Reflection.Missing.Value; ??
  83. ???????????//圖片居中顯示 ??
  84. ???????????this._wordApplication.Selection.ParagraphFormat.Alignment?=?Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; ??
  85. ???????????this._wordApplication.Application.Selection.InlineShapes.AddPicture(pPictureFileName,?ref?myNothing,?ref?myNothing,?ref?myNothing); ??
  86. ???????} ??
  87. ??
  88. ??
  89. ??
  90. ???????///?<SUMMARY></SUMMARY> ??
  91. ???????///?保存文件? ??
  92. ???????///? ??
  93. ???????///?<PARAM?name="pFileName"?/>保存的文件名 ??
  94. ???????public?void?SaveWord(string?pFileName) ??
  95. ???????{ ??
  96. ???????????object?myNothing?=?System.Reflection.Missing.Value; ??
  97. ???????????object?myFileName?=?pFileName; ??
  98. ???????????object?myWordFormatDocument?=Microsoft?.Office?.Interop?.Word.WdSaveFormat.wdFormatDocument; ??
  99. ???????????object?myLockd?=?false; ??
  100. ???????????object?myPassword?=?""; ??
  101. ???????????object?myAddto?=?true; ??
  102. ??
  103. ???????????try??
  104. ???????????{ ??
  105. ???????????????this._wordDocument.SaveAs(ref?myFileName,?ref?myWordFormatDocument,?ref?myLockd,?ref?myPassword,?ref?myAddto,?ref?myPassword, ??
  106. ???????????????????ref?myLockd,?ref?myLockd,?ref?myLockd,?ref?myLockd,?ref?myNothing,?ref?myNothing,?ref?myNothing,? ??
  107. ???????????????????ref?myNothing,?ref?myNothing,?ref?myNothing); ??
  108. ???????????} ??
  109. ???????????catch??
  110. ???????????{ ??
  111. ???????????????throw?new?Exception("導出word文檔失敗!"); ??
  112. ???????????} ??
  113. ???????} ??
  114. ???} ?

c#生成word文檔


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

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

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

【本文對您有幫助就好】

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

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 邮箱| 嵩明县| 长丰县| 报价| 镇坪县| 凌源市| 西丰县| 阳曲县| 湟中县| 中方县| 阳城县| 丘北县| 克东县| 江达县| 高密市| 正定县| 扎赉特旗| 江油市| 志丹县| 明水县| 冷水江市| 高陵县| 霍林郭勒市| 固原市| 叶城县| 侯马市| 唐海县| 万荣县| 奇台县| 大理市| 宜黄县| 洪泽县| 且末县| 重庆市| 清远市| 承德县| 旅游| 伊川县| 乐亭县| 株洲县| 枣阳市|