前提:
导入COM库:Microsoft word 11.0 Object Library.
引用里面就增加了:



创建新Word
 

C#操作Word完全功略object oMissing = System.Reflection.Missing.Value;
C#操作Word完全功略 Word._Application oWord;
C#操作Word完全功略 Word._Document oDoc;
C#操作Word完全功略 oWord
= new Word.Application();
C#操作Word完全功略 oWord.Visible
= true;
C#操作Word完全功略 oDoc
= oWord.Documents.Add(ref oMissing, ref oMissing,
C#操作Word完全功略
ref oMissing, ref oMissing);


打开文档:
 

C#操作Word完全功略object oMissing = System.Reflection.Missing.Value;
C#操作Word完全功略 Word._Application oWord;
C#操作Word完全功略 Word._Document oDoc;
C#操作Word完全功略 oWord
= new Word.Application();
C#操作Word完全功略 oWord.Visible
= true;
C#操作Word完全功略
object fileName = @"E:\CCCXCXX\TestDoc.doc";
C#操作Word完全功略 oDoc
= oWord.Documents.Open(ref fileName,
C#操作Word完全功略
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
C#操作Word完全功略
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
C#操作Word完全功略
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);


导入模板
 

C#操作Word完全功略object oMissing = System.Reflection.Missing.Value;
C#操作Word完全功略 Word._Application oWord;
C#操作Word完全功略 Word._Document oDoc;
C#操作Word完全功略 oWord
= new Word.Application();
C#操作Word完全功略 oWord.Visible
= true;
C#操作Word完全功略
object fileName = @"E:\XXXCCX\Test.doc";
C#操作Word完全功略 oDoc
= oWord.Documents.Add(ref fileName, ref oMissing,
C#操作Word完全功略
ref oMissing, ref oMissing);



.添加新表
 

C#操作Word完全功略object oMissing = System.Reflection.Missing.Value;
C#操作Word完全功略 Word._Application oWord;
C#操作Word完全功略 Word._Document oDoc;
C#操作Word完全功略 oWord
= new Word.Application();
C#操作Word完全功略 oWord.Visible
= true;
C#操作Word完全功略 oDoc
= oWord.Documents.Add(ref oMissing, ref oMissing,
C#操作Word完全功略
ref oMissing, ref oMissing);
C#操作Word完全功略
C#操作Word完全功略
object start = 0;
C#操作Word完全功略
object end = 0;
C#操作Word完全功略 Word.Range tableLocation
= oDoc.Range(ref start, ref end);
C#操作Word完全功略 oDoc.Tables.Add(tableLocation,
3, 4, ref oMissing, ref oMissing);


.表插入行
 

C#操作Word完全功略object oMissing = System.Reflection.Missing.Value;
C#操作Word完全功略 Word._Application oWord;
C#操作Word完全功略 Word._Document oDoc;
C#操作Word完全功略 oWord
= new Word.Application();
C#操作Word完全功略 oWord.Visible
= true;
C#操作Word完全功略 oDoc
= oWord.Documents.Add(ref oMissing, ref oMissing,
C#操作Word完全功略
ref oMissing, ref oMissing);
C#操作Word完全功略
C#操作Word完全功略
object start = 0;
C#操作Word完全功略
object end = 0;
C#操作Word完全功略 Word.Range tableLocation
= oDoc.Range(ref start, ref end);
C#操作Word完全功略 oDoc.Tables.Add(tableLocation,
3, 4, ref oMissing, ref oMissing);
C#操作Word完全功略
C#操作Word完全功略 Word.Table newTable
= oDoc.Tables[1];
C#操作Word完全功略
object beforeRow = newTable.Rows[1];
C#操作Word完全功略 newTable.Rows.Add(
ref beforeRow);


.单元格合并
 

C#操作Word完全功略object oMissing = System.Reflection.Missing.Value;
C#操作Word完全功略 Word._Application oWord;
C#操作Word完全功略 Word._Document oDoc;
C#操作Word完全功略 oWord
= new Word.Application();
C#操作Word完全功略 oWord.Visible
= true;
C#操作Word完全功略 oDoc
= oWord.Documents.Add(ref oMissing, ref oMissing,
C#操作Word完全功略
ref oMissing, ref oMissing);
C#操作Word完全功略
C#操作Word完全功略
object start = 0;
C#操作Word完全功略
object end = 0;
C#操作Word完全功略 Word.Range tableLocation
= oDoc.Range(ref start, ref end);
C#操作Word完全功略 oDoc.Tables.Add(tableLocation,
3, 4, ref oMissing, ref oMissing);
C#操作Word完全功略
C#操作Word完全功略 Word.Table newTable
= oDoc.Tables[1];
C#操作Word完全功略
object beforeRow = newTable.Rows[1];
C#操作Word完全功略 newTable.Rows.Add(
ref beforeRow);
C#操作Word完全功略
C#操作Word完全功略 Word.Cell cell
= newTable.Cell(1, 1);
C#操作Word完全功略 cell.Merge(newTable.Cell(
1, 2));


.单元格分离
 

C#操作Word完全功略object oMissing = System.Reflection.Missing.Value;
C#操作Word完全功略 Word._Application oWord;
C#操作Word完全功略 Word._Document oDoc;
C#操作Word完全功略 oWord
= new Word.Application();
C#操作Word完全功略 oWord.Visible
= true;
C#操作Word完全功略 oDoc
= oWord.Documents.Add(ref oMissing, ref oMissing,
C#操作Word完全功略
ref oMissing, ref oMissing);
C#操作Word完全功略
C#操作Word完全功略
object start = 0;
C#操作Word完全功略
object end = 0;
C#操作Word完全功略 Word.Range tableLocation
= oDoc.Range(ref start, ref end);
C#操作Word完全功略 oDoc.Tables.Add(tableLocation,
3, 4, ref oMissing, ref oMissing);
C#操作Word完全功略
C#操作Word完全功略 Word.Table newTable
= oDoc.Tables[1];
C#操作Word完全功略
object beforeRow = newTable.Rows[1];
C#操作Word完全功略 newTable.Rows.Add(
ref beforeRow);
C#操作Word完全功略
C#操作Word完全功略 Word.Cell cell
= newTable.Cell(1, 1);
C#操作Word完全功略 cell.Merge(newTable.Cell(
1, 2));
C#操作Word完全功略
C#操作Word完全功略
object Rownum = 2;
C#操作Word完全功略
object Columnnum = 2;
C#操作Word完全功略 cell.Split(
ref Rownum, ref Columnnum);
C#操作Word完全功略


通过段落控制插入
 

C#操作Word完全功略object oMissing = System.Reflection.Missing.Value;
C#操作Word完全功略 oPara1.Range.InsertParagraphAfter();

相关文章:

  • 2021-11-17
  • 2022-12-23
  • 2022-02-19
  • 2021-11-28
  • 2022-02-12
  • 2021-07-28
猜你喜欢
  • 2022-01-20
  • 2022-01-09
  • 2022-12-23
相关资源
相似解决方案