前提:
匯入com庫:microsoft word 11.0 object library.
引用裡面就增加了:
建立新word
objectomissing = system.reflection.missing.value;word._document odoc;
oword.visible =true;
odoc = oword.documents.add(refomissing,refomissing,refomissing,refomissing);
開啟文件:
objectomissing = system.reflection.missing.value;word._document odoc;
oword.visible =true;objectfilename =@"e:cccxcxxtestdoc.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._document odoc;
oword.visible =true;objectfilename =@"e:***ccxtest.doc";
odoc = oword.documents.add(reffilename,refomissing,refomissing,refomissing);
新增新錶
objectomissing = system.reflection.missing.value;word._document odoc;
oword.visible =true;
odoc = oword.documents.add(refomissing,refomissing,refomissing,refomissing);objectstart = 0;objectend = 0;
word.range tablelocation = odoc.range(refstart,refend);
odoc.tables.add(tablelocation, 3, 4,refomissing,refomissing);
表插入行
objectomissing = system.reflection.missing.value;word._document odoc;
oword.visible =true;
odoc = oword.documents.add(refomissing,refomissing,refomissing,refomissing);objectstart = 0;objectend = 0;
word.range tablelocation = odoc.range(refstart,refend);
odoc.tables.add(tablelocation, 3, 4,refomissing,refomissing);
word.table newtable = odoc.tables[1];objectbeforerow = newtable.rows[1];
newtable.rows.add(refbeforerow);
單元格合併
objectomissing = system.reflection.missing.value;word._document odoc;
oword.visible =true;
odoc = oword.documents.add(refomissing,refomissing,refomissing,refomissing);objectstart = 0;objectend = 0;
word.range tablelocation = odoc.range(refstart,refend);
odoc.tables.add(tablelocation, 3, 4,refomissing,refomissing);
word.table newtable = odoc.tables[1];objectbeforerow = newtable.rows[1];
newtable.rows.add(refbeforerow);
word.cell cell = newtable.cell(1, 1);
cell.merge(newtable.cell(1, 2));
單元格分離
objectomissing = system.reflection.missing.value;word._document odoc;
oword.visible =true;
odoc = oword.documents.add(omissing,refomissing,refomissing);objectstart = 0;objectend = 0;
word.range tablelocation = odoc.range(refstart,refend);
odoc.tables.add(tablelocation, 3, 4,refomissing,refomissing);
word.table newtable = odoc.tables[1];objectbeforerow = newtable.rows[1];
newtable.rows.add(refbeforerow);
word.cell cell = 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";/* endofdoc is a predefined bookmark *///start word and create a new document.word._document odoc;
oword.visible =true;
odoc = oword.documents.add(refomissing,refomissing,refomissing,refomissing);//insert a paragraph at the beginning of the document.word.paragraph opara1;
opara1 = odoc.content.paragraphs.add(refomissing);
opara1.range.text ="heading 1";
opara1.range.font.bold = 1;
opara1.format.spaceafter = 24;//24 pt spacing after paragraph.opara1.range.insertparagraphafter();
C 操作Word完全功略
前提 匯入com庫 microsoft word 11.0 object library.引用裡面就增加了 建立新word object newtrue odoc oword.documents.add refomissing,refomissing,refomissing,refomissing ...
C 操作word的方法示例
region 讀取word 讀取word所有文字內容 不包含 word中的字元內容 純文字 publickggoxatq string readallfromword textstring textstring.replace a 替換空串為空。word中 a代表空串,但在c 中,代表響鈴 暈 否則...
c 操作word文件
最近由於工作需要,做了一些關於c 操作word文件方面的工作 主要是對word中 的操作,以下是部分 關於操作不規則 的 using system using system.collections using system.componentmodel using system.data using...