ms word - c# msoffice office error 0x80010108 -
this code work perfect on win7 + office 2007, on win8 + office 2013 got error 0x80010108 rpc_e_diconnected object invoked has disconnected clients.
any idea?
hello everybody
this code work perfect on win7 + office 2007, on win8 + office 2013 got error 0x80010108 rpc_e_diconnected object invoked has disconnected clients.
any idea?
public void printdoc() { try { system.windows.forms.cursor.current = cursors.waitcursor; exportxmldocument = new xmldocument(); wordapp = new microsoft.office.interop.word.application(); //msword.document newmaindoc = null; object missing = system.reflection.missing.value; var ni = new nodeinfo(); ni = (nodeinfo)tvxml.nodes[0].tag; xmlelement xe = exportxmldocument.createelement(tvxml.nodes[0].text); xe.setattribute("name", ni.name); xe.setattribute("type", ni.doctype); xe.setattribute("path", ni.path); xe.setattribute("filename", ni.filename); exportxmldocument.appendchild(xe); //riempie l' oggetto xml recursivetoxml(tvxml.nodes[0], xe); wordapp.application.visible = true; if (globalvar.usetemplate || file.exists(globalvar.templatename)) { object otemplate = globalvar.templatename; maindoc = wordapp.documents.add(ref otemplate, ref missing, ref missing, ref missing); } else { maindoc = wordapp.documents.add(); } // stampa recursivetoprint(exportxmldocument.childnodes); maindoc.activewindow.activate(); exportxmldocument = null; system.windows.forms.cursor.current = cursors.default; } catch (xmlexception xmlex) { messagebox.show(xmlex.message); } catch (exception ex) { messagebox.show(ex.message); } } void recursivetoprint(xmlnodelist nodes) { foreach (xmlnode childxmlnode in nodes) { // var ni = new nodeinfo(); ni.name = ((xmlelement)childxmlnode).name; ni.doctype = ((xmlelement)childxmlnode).getattribute("type"); ni.path = ((xmlelement)childxmlnode).getattribute("path"); ni.filename = ((xmlelement)childxmlnode).getattribute("filename"); if (ni == null) return; object missing = system.reflection.missing.value; switch (ni.doctype) { case "doc": case "docx": object objfullfilename = ni.path + "\\" + ni.filename; var doc = wordapp.documents.open(ref objfullfilename, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); doc.activewindow.activate(); doc.activewindow.selection.wholestory(); doc.activewindow.selection.copy(); maindoc.activewindow.selection.pastespecial(); doc.activewindow.close(); if (globalvar.pagebreak) { doc.activewindow.selection.insertbreak(); } break; case "xls": case "xlsx": break; case "xml": break; } recursivetoprint(childxmlnode.childnodes); } }
Comments
Post a Comment