this code work perfect on win7 + office 2007, but on win8 + office 2013 i got error 0x80010108 RPC_E_DICONNECTED The object invoked has disconnected from its clients.
any idea?
hello everybody
this code work perfect on win7 + office 2007, but on win8 + office 2013 i got error 0x80010108 RPC_E_DICONNECTED The object invoked has disconnected from its 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);
}
}
User contributions licensed under CC BY-SA 3.0