前提:
匯入COM庫:Microsoftword11.0ObjectLibrary.
引用裡面就增加了:
建立新Word
objectoMissing=System.Reflection.Missing.Value;
Word._ApplicationoWord;
Word._DocumentoDoc;
oWord=newWord.Application();
oWord.Visible=true;
oDoc=oWord.Documents.Add(refoMissing,refoMissing,
refoMissing,refoMissing);
開啟文件:
objectfileName=@"E:\CCCXCXX\TestDoc.doc";
oDoc=oWord.Documents.Open(reffileName,
refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,
refoMissing,refoMissing,refoMissing,refoMissing,refoMissing);
匯入模板
objectfileName=@"E:\XXXCCX\Test.doc";
oDoc=oWord.Documents.Add(reffileName,refoMissing,
.新增新表
objectstart=0;
objectend=0;
Word.RangetableLocation=oDoc.Range(refstart,refend);
oDoc.Tables.Add(tableLocation,3,4,refoMissing,refoMissing);
.表插入行
Word.TablenewTable=oDoc.Tables[1];
objectbeforeRow=newTable.Rows[1];
newTable.Rows.Add(refbeforeRow);
.單元格合併
Word.Cellcell=newTable.Cell(1,1);
cell.Merge(newTable.Cell(1,2));
.單元格分離
objectRownum=2;
objectColumnnum=2;
cell.Split(refRownum,refColumnnum);
透過段落控制插入
objectoEndOfDoc="\\endofdoc";/**//*\endofdocisapredefinedbookmark*/
//StartWordandcreateanewdocument.
//Insertaparagraphatthebeginningofthedocument.
Word.ParagraphoPara1;
oPara1=oDoc.Content.Paragraphs.Add(refoMissing);
oPara1.Range.Text="Heading1";
oPara1.Range.Font.Bold=1;
oPara1.Format.SpaceAfter=24;//24ptspacingafterparagraph.
oPara1.Range.InsertParagraphAfter();
前提:
匯入COM庫:Microsoftword11.0ObjectLibrary.
引用裡面就增加了:
建立新Word
objectoMissing=System.Reflection.Missing.Value;
Word._ApplicationoWord;
Word._DocumentoDoc;
oWord=newWord.Application();
oWord.Visible=true;
oDoc=oWord.Documents.Add(refoMissing,refoMissing,
refoMissing,refoMissing);
開啟文件:
objectoMissing=System.Reflection.Missing.Value;
Word._ApplicationoWord;
Word._DocumentoDoc;
oWord=newWord.Application();
oWord.Visible=true;
objectfileName=@"E:\CCCXCXX\TestDoc.doc";
oDoc=oWord.Documents.Open(reffileName,
refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,
refoMissing,refoMissing,refoMissing,refoMissing,refoMissing,
refoMissing,refoMissing,refoMissing,refoMissing,refoMissing);
匯入模板
objectoMissing=System.Reflection.Missing.Value;
Word._ApplicationoWord;
Word._DocumentoDoc;
oWord=newWord.Application();
oWord.Visible=true;
objectfileName=@"E:\XXXCCX\Test.doc";
oDoc=oWord.Documents.Add(reffileName,refoMissing,
refoMissing,refoMissing);
.新增新表
objectoMissing=System.Reflection.Missing.Value;
Word._ApplicationoWord;
Word._DocumentoDoc;
oWord=newWord.Application();
oWord.Visible=true;
oDoc=oWord.Documents.Add(refoMissing,refoMissing,
refoMissing,refoMissing);
objectstart=0;
objectend=0;
Word.RangetableLocation=oDoc.Range(refstart,refend);
oDoc.Tables.Add(tableLocation,3,4,refoMissing,refoMissing);
.表插入行
objectoMissing=System.Reflection.Missing.Value;
Word._ApplicationoWord;
Word._DocumentoDoc;
oWord=newWord.Application();
oWord.Visible=true;
oDoc=oWord.Documents.Add(refoMissing,refoMissing,
refoMissing,refoMissing);
objectstart=0;
objectend=0;
Word.RangetableLocation=oDoc.Range(refstart,refend);
oDoc.Tables.Add(tableLocation,3,4,refoMissing,refoMissing);
Word.TablenewTable=oDoc.Tables[1];
objectbeforeRow=newTable.Rows[1];
newTable.Rows.Add(refbeforeRow);
.單元格合併
objectoMissing=System.Reflection.Missing.Value;
Word._ApplicationoWord;
Word._DocumentoDoc;
oWord=newWord.Application();
oWord.Visible=true;
oDoc=oWord.Documents.Add(refoMissing,refoMissing,
refoMissing,refoMissing);
objectstart=0;
objectend=0;
Word.RangetableLocation=oDoc.Range(refstart,refend);
oDoc.Tables.Add(tableLocation,3,4,refoMissing,refoMissing);
Word.TablenewTable=oDoc.Tables[1];
objectbeforeRow=newTable.Rows[1];
newTable.Rows.Add(refbeforeRow);
Word.Cellcell=newTable.Cell(1,1);
cell.Merge(newTable.Cell(1,2));
.單元格分離
objectoMissing=System.Reflection.Missing.Value;
Word._ApplicationoWord;
Word._DocumentoDoc;
oWord=newWord.Application();
oWord.Visible=true;
oDoc=oWord.Documents.Add(refoMissing,refoMissing,
refoMissing,refoMissing);
objectstart=0;
objectend=0;
Word.RangetableLocation=oDoc.Range(refstart,refend);
oDoc.Tables.Add(tableLocation,3,4,refoMissing,refoMissing);
Word.TablenewTable=oDoc.Tables[1];
objectbeforeRow=newTable.Rows[1];
newTable.Rows.Add(refbeforeRow);
Word.Cellcell=newTable.Cell(1,1);
cell.Merge(newTable.Cell(1,2));
objectRownum=2;
objectColumnnum=2;
cell.Split(refRownum,refColumnnum);
透過段落控制插入
objectoMissing=System.Reflection.Missing.Value;
objectoEndOfDoc="\\endofdoc";/**//*\endofdocisapredefinedbookmark*/
//StartWordandcreateanewdocument.
Word._ApplicationoWord;
Word._DocumentoDoc;
oWord=newWord.Application();
oWord.Visible=true;
oDoc=oWord.Documents.Add(refoMissing,refoMissing,
refoMissing,refoMissing);
//Insertaparagraphatthebeginningofthedocument.
Word.ParagraphoPara1;
oPara1=oDoc.Content.Paragraphs.Add(refoMissing);
oPara1.Range.Text="Heading1";
oPara1.Range.Font.Bold=1;
oPara1.Format.SpaceAfter=24;//24ptspacingafterparagraph.
oPara1.Range.InsertParagraphAfter();