自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

C#操作Word表格的常見操作

開發(fā) 后端
C#操作Word表格的常見操作是什么呢?C#操作Word表格的常見操作需要注意什么呢?那么本文就向你介紹這方面的內(nèi)容。

幾種常見C#操作Word表格操作有哪些呢?讓我們來看看具體的實(shí)例演示:

  1. bool saveChange = false;  
  2.  //C#操作Word表格操作
  3. object missing = System.Reflection.Missing.Value;  
  4.  
  5. object template = (object)templateFilePath;  
  6.  
  7. object filename = (object)saveFilePath;    
  8. object isVisible = missing;  
  9. object readOnly = missing;  
  10. object breakType = Word.WdBreakType.wdSectionBreakNextPage;  
  11. object isSaveChange = (object)saveChange;  
  12. Word.Document doc = null;  
  13.  
  14. //定義一個(gè)Word.Application 對(duì)象  
  15.  
  16. Word.Application WordApp = new Word.ApplicationClass();  
  17.  
  18. //C#操作Word表格操作之打開文檔  
  19. doc = WordApp.Documents.Open(ref template,   
  20. ref missing,ref readOnly,ref missing,   
  21. ref missing, ref missing, ref missing,   
  22. ref missing, ref missing,ref missing,   
  23. ref missing, ref isVisible, ref missing,   
  24. ref missing, ref missing, ref missing);  
  25.  
  26. //C#操作Word表格操作之設(shè)置頁眉文本  
  27.  
  28. WordApp.ActiveWindow.ActivePane.View.SeekView =  
  29.  Word.WdSeekView.wdSeekCurrentPageHeader;  
  30. WordApp.Selection.WholeStory();  
  31. WordApp.Selection.TypeText( this.m_titleText );  
  32. WordApp.ActiveWindow.ActivePane.View.SeekView =   
  33. Word.WdSeekView.wdSeekMainDocument;  
  34.  
  35. //頁面設(shè)置,設(shè)置頁面為縱向布局,設(shè)置紙張類型為A4紙  
  36.  
  37. doc.PageSetup.Orientation = Word.WdOrientation.wdOrientLandscape;  
  38. doc.PageSetup.PageWidth = WordApp.CentimetersToPoints(29.7F);  
  39. doc.PageSetup.PageHeight = WordApp.CentimetersToPoints(21F);  
  40.  
  41. //C#操作Word表格操作之創(chuàng)建表格及設(shè)置表格和單元格屬性  
  42.  
  43. object autoFitBehavior = Word.WdAutoFitBehavior.wdAutoFitWindow;  
  44. doc.Content.Tables.Add(  
  45. WordApp.Selection.Range, totalCount + 1,   
  46. totalField - keyCount_1, ref missing,   
  47. ref autoFitBehavior);  
  48.  
  49. //C#操作Word表格操作之合并單元隔  
  50.  
  51. doc.Content.Tables[1].Cell(i+1,j).Select();  
  52. object moveUnit = Word.WdUnits.wdLine;  
  53. object moveCount = 1;  
  54. object moveExtend = Word.WdMovementType.wdExtend;  
  55. WordApp.Selection.MoveUp(ref moveUnit,  
  56.  ref moveCount, ref moveExtend);  
  57. WordApp.Selection.Cells.Merge();  
  58. WordApp.Selection.Cells.VerticalAlignment =   
  59. Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;  
  60.  
  61. doc.Content.Tables[1].Cell(i+1,1).Range.Text = “單元格內(nèi)容填充”  
  62.  
  63. //添加表格行  
  64.  
  65. doc.Content.Tables[0].Rows.Add(ref beforeRow);  
  66.  
  67. //C#操作Word表格操作之添加表格列  
  68.  
  69. doc.Content.Tables[0].Columns.Add(ref beforeColumn);  
  70.  
  71. //文本居中  
  72. WordApp.Selection.ParagraphFormat.Alignment =  
  73. Word.WdParagraphAlignment.wdAlignParagraphCenter;  
  74. WordApp.Selection.Cells.VerticalAlignment =   
  75. Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;  
  76.  
  77. //C#操作Word表格操作之選中單元格文字垂直居中  
  78.  
  79. oDoc.Tables.Add(tableLocation, 3, 4, ref oMissing, ref oMissing);  
  80.  
  81. Word.Table newTable = oDoc.Tables[1];  
  82. object beforeRow = newTable.Rows[1];  
  83. newTable.Rows.Add(ref beforeRow);  
  84.  
  85. Word.Cell cell = newTable.Cell(1, 1);  
  86. cell.Merge(newTable.Cell(1, 2)); 

C#操作Word表格操作的基本內(nèi)容就向你介紹到這里,希望對(duì)你了解和學(xué)習(xí)C#操作Word表格操作有所幫助。

【編輯推薦】

  1. C#操作xml文件實(shí)例詳解
  2. C#操作XML文件學(xué)習(xí)綜合體會(huì)
  3. C#操作符重載學(xué)習(xí)的一點(diǎn)總結(jié)
  4. C#操作Word書簽實(shí)例淺析
  5. C#操作Word表的實(shí)例淺析
責(zé)任編輯:仲衡 來源: 博客園
相關(guān)推薦

2009-08-19 10:46:48

C#操作Word表格

2009-08-19 10:16:15

C#操作Word

2009-08-19 10:25:14

C#操作Word

2009-08-19 11:34:06

C#操作Word

2009-08-19 11:13:49

C#操作Word

2009-08-19 09:42:52

C#操作Word書簽

2009-09-01 11:21:02

C#讀取word內(nèi)容

2009-08-19 11:23:12

C#操作Word

2009-08-28 15:25:38

C#線程操作

2009-08-19 11:28:41

C#操作Word

2024-04-16 11:46:51

C#Redis數(shù)據(jù)庫

2009-08-19 12:58:19

C#操作Word

2009-08-17 13:34:02

C#異步操作

2009-08-12 15:43:02

操作C# Datase

2009-08-25 15:59:28

C#串口操作

2009-09-02 17:07:06

C#數(shù)組操作

2009-08-31 15:34:45

常用操作C# TreeView

2009-08-18 18:06:54

C#操作符重載

2009-08-18 16:20:09

C# 操作Excel

2009-08-18 16:14:05

C# 操作Excel
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)