Question in short :
this line:
doc.InlineShapes.AddOLEObject("Excel.Chart.8"); // doc is a Microsoft.Office.Interop.Word.Document object
opens Excel. How to disable this?
more details:
I am trying to create docx documents from a template with scripting Word2010 in c#.
I open a document this way:
Word.Document doc = app.Documents.Open(@"xxxx.docx",Visible:false);
During the script, Word2010 does not appear, but Excel2010 does, when I create a chart inside the word document (“Excel.Chart.8”)
I see the whole chart scripting process on my monitor, which is not what I want.
Is there any way to hide Excel2010 (Chart Tools) during the process?
edit: An example of creating an excel chart:
Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
Word.Document doc = app.Documents.Open(@"xxxx.docx",Visible:false);
string classtype = "Excel.Chart.8";
Bookmark shapeBookMark = doc.Bookmarks.get_Item("mybookmark");
Word.InlineShape wrdInlineShape = doc.InlineShapes.AddOLEObject(classtype, Range: shapeBookMark.Range);
if (wrdInlineShape.OLEFormat.ProgID == classtype)
{
object verb = Word.WdOLEVerb.wdOLEVerbHide;
wrdInlineShape.OLEFormat.DoVerb(ref verb);
Excel.Workbook obook = (Excel.Workbook)wrdInlineShape.OLEFormat.Object;
Excel.Worksheet sheet = (Excel.Worksheet)obook.Worksheets["Sheet1"];
//then the access of a cell goes like this:
((Microsoft.Office.Interop.Excel.Range)sheet.Cells[1, 1]).Value = "data";
}
Notice that Visible:false parameter must be used, because otherwise both excel and word will appear on a long scripting process. On a short one, it will not appear, but I need to do long scripting processes (creating, filling and formatting 16 charts/docx)
I can recreate this on my machine, although I’m using Office 2007 rather than 2010. The only semi-solution I’ve managed to find so far is to get the active instance of Excel and switch it to invisible. Excel will flash up for a second and then disappear, but at least it will not remain visible while you perform your scripting/charting.
So inserting this into your code: