C#操作Word表的实例浅析

C#操作Word之添加新表

 
 
 
  1. object oMissing = System.Reflection.Missing.Value;  
  2.  
  3. Word._Application oWord;  
  4.  
  5. Word._Document oDoc;  
  6.  
  7. oWord = new Word.Application();  
  8.  
  9. oWord.Visible = true;  
  10.  
  11. oDoc = oWord.Documents.Add(ref oMissing, ref oMissing,  
  12.     ref oMissing, ref oMissing);  
  13.  
  14. object start = 0;  
  15.  
  16. object end = 0;  
  17.  
  18. Word.Range tableLocation = oDoc.Range(ref start, ref end);  
  19.  
  20. oDoc.Tables.Add(tableLocation, 3, 4, ref oMissing, ref oMissing); 

C#操作Word之表插入行

 
 
 
  1. object oMissing = System.Reflection.Missing.Value;  
  2.  
  3. Word._Application oWord;  
  4.  
  5. Word._Document oDoc;  
  6.  
  7. oWord = new Word.Application();  
  8.  
  9. oWord.Visible = true;  
  10.  
  11. oDoc = oWord.Documents.Add(ref oMissing, ref oMissing,  
  12.     ref oMissing, ref oMissing);  
  13.  
  14. object start = 0;  
  15.  
  16. object end = 0;  
  17.  
  18. Word.Range tableLocation = oDoc.Range(ref start, ref end);  
  19.  
  20. oDoc.Tables.Add(tableLocation, 3, 4, ref oMissing, ref oMissing);  
  21.  
  22. Word.Table newTable = oDoc.Tables[1];  
  23.  
  24. object beforeRow = newTable.Rows[1];  
  25.  
  26. newTable.Rows.Add(ref beforeRow); 

C#操作Word之单元格合并

 
 
 
  1. object oMissing = System.Reflection.Missing.Value;  
  2.  
  3. Word._Application oWord;  
  4.  
  5. Word._Document oDoc;  
  6.  
  7. oWord = new Word.Application();  
  8.  
  9. oWord.Visible = true;  
  10.  
  11. oDoc = oWord.Documents.Add  
  12. (ref oMissing, ref oMissing,  
  13. ref oMissing, ref oMissing);  
  14.  
  15. object start = 0;  
  16.  
  17. object end = 0;  
  18.  
  19. Word.Range tableLocation = oDoc.Range(ref start, ref end); 

C#操作Word的基本内容就向你介绍到这里,希望对你了解和学习C#操作Word有所帮助。

【编辑推荐】

  1. C# 操作XML的全过程实例浅析
  2. C#操作xml文件实例详解
  3. C#操作符重载应用的一点体会
  4. C#操作符重载特点实例浅析
  5. C#操作Word书签实例浅析
THE END