When you create charts in hidden Word2010, Excel opens. How to disable this?

Shortly speaking:

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 a Word2010 script in C #. I open the document this way:

Word.Document doc = app.Documents.Open(@"xxxx.docx",Visible:false);

Word2010 does not appear during script, but Excel2010 does this when I create a chart inside a word document ("Excel.Chart.8")

I see the whole process of creating charts on my monitor, which I do not want.

Is there a way to hide Excel2010 (Chart Tools) during the process?

edit: 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";
      }

, Visible: false, excel, word. , , (, 16 /docx)

+3
1

, Office 2007, 2010 . -, , - Excel . Excel , , ​​ /.

:

Word.InlineShape wrdInlineShape = doc.InlineShapes.AddOLEObject(classtype, Range: shapeBookMark.Range);
Excel.Application xlApp = (Excel.Application)Marshal.GetActiveObject("Excel.Application");
xlApp.Visible = false;

if (wrdInlineShape.OLEFormat.ProgID == classtype)
{
    // etc...
+1

All Articles