首頁>Club>
4
回覆列表
  • 1 # 使用者2331358883338

    前提:

    匯入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();

  • 中秋節和大豐收的關聯?
  • 平面和網頁設計有什麼區別?