c# - Copy all content from a word table cell into the end of a word document -
i need info migration of thousands of word documents. source documents contains tables cell content (text, images, objects etc). contents of tables specific header needs copied end of specific word document. in cases content copied new file, in case tables related have contents copied same file, hence need know how paste end of file well.
i writing c# console programme this. need how re-create , paste content (not text) table end of word document.
i can open relevant documents , select table cell, stuck @ copying content over. main routine doing copying.
foreach (table table in document.tables) { (int row = 1; row <= table.rows.count; row++) { var header = table.cell(row, 1); var headertext = header.range.text; for(int j = 0; j < 3; j++) { // if contains header, write new file if (headertext.startswith(tableheaders[j])) { // new numbered file name string filename = getfilename(targetdir, file, j + 1); console.writeline(filename); //create new document document newdocument = application.documents.add(ref missing, ref missing, ref missing, ref missing); // table cell re-create from: table.cell(row + 1, 1) // document re-create into: newdocument // stuck here // save file newdocument.saveas2(filename); newdocument.close(); } } } }
this worked me:
if (headertext.startswith(tableheaders[j])) { // file name string filename = getfilename(targetdir, file, j + 1); //create new document document newdocument = application.documents.add(ref missing, ref missing, ref missing, ref missing); var copyfrom = table.cell(row + 1, 1).range; int start = newdocument.content.end - 1; int end = newdocument.content.end; var copyto = newdocument.range(start, end); copyfrom.moveend(wdunits.wdcharacter, -1); copyto.formattedtext = copyfrom.formattedtext; // save file newdocument.saveas2(filename); newdocument.close(); }
c# ms-word
No comments:
Post a Comment