<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How do I programmatically access an embedded Excel document from a C# addon? in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/how-do-i-programmatically-access-an-embedded-excel-document-from/m-p/3379409#M137011</link>
    <description>&lt;P&gt;I have an excel spreadsheet I need to access. &amp;nbsp;It is embedded within a dwg file(I'm a C# guy, not Inventor). How can I access this spreadsheet from an addon written in C#? &amp;nbsp;I wasn't sure where to look in the documentation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I assume I should start with ActiveDocument, but from there I'm not sure where to go. &amp;nbsp;I'll need to be able to read and write to the table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Wed, 21 Mar 2012 12:14:36 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2012-03-21T12:14:36Z</dc:date>
    <item>
      <title>How do I programmatically access an embedded Excel document from a C# addon?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/how-do-i-programmatically-access-an-embedded-excel-document-from/m-p/3379409#M137011</link>
      <description>&lt;P&gt;I have an excel spreadsheet I need to access. &amp;nbsp;It is embedded within a dwg file(I'm a C# guy, not Inventor). How can I access this spreadsheet from an addon written in C#? &amp;nbsp;I wasn't sure where to look in the documentation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I assume I should start with ActiveDocument, but from there I'm not sure where to go. &amp;nbsp;I'll need to be able to read and write to the table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2012 12:14:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/how-do-i-programmatically-access-an-embedded-excel-document-from/m-p/3379409#M137011</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-03-21T12:14:36Z</dc:date>
    </item>
    <item>
      <title>Re: How do I programmatically access an embedded Excel document from a C# addon?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/how-do-i-programmatically-access-an-embedded-excel-document-from/m-p/3380779#M137012</link>
      <description>&lt;P&gt;I don't think it is an Excel document anymore as it should be now inserted as a custom table. To access this table you can do it like the following.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Inventor.DrawingDocument oDrawDoc = ThisApplication.ActiveDocument;
Sheet oSheet = oDrawDoc.ActiveSheet;
if (oSheet.CustomTables.Count &amp;gt; 0) {
	CustomTable oCustomTable = oSheet.CustomTables.Item(1);
	foreach (Row oRow in oCustomTable.Rows) {
		string[] RowArray = new string[oCustomTable.Columns.Count + 1];
		for (int I = 1; I &amp;lt;= oCustomTable.Columns.Count; I++) {
			RowArray[I] = oRow.Item(I).Value;
		}
		Interaction.MsgBox(string.Join(Constants.vbLf, RowArray));
	}
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2012 02:15:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/how-do-i-programmatically-access-an-embedded-excel-document-from/m-p/3380779#M137012</guid>
      <dc:creator>Mike.Wohletz</dc:creator>
      <dc:date>2012-03-22T02:15:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do I programmatically access an embedded Excel document from a C# addon?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/how-do-i-programmatically-access-an-embedded-excel-document-from/m-p/3383351#M137013</link>
      <description>&lt;P&gt;No, what I mean is I actually have it embedded as an Excel spreadsheet(not a custom table). &amp;nbsp;It's listed under the 3rd party tab. &amp;nbsp;When I open it from inside inventor, it opens the spreadsheet in Excel.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code which DOES work in VBA&lt;/P&gt;&lt;PRE&gt;Sub openexcel()
Dim oApp As Inventor.Application
Set oApp = ThisApplication
Dim oOleRef As ReferencedOLEFileDescriptor
Set oOleRef = oApp.ActiveDocument.ReferencedOLEFileDescriptors.Item(1)
Dim oWB As Excel.Workbook
Call oOleRef.Activate(kEditOpenOLEVerb, oWB)
Dim oSheet As Excel.WorkSheet
Set oSheet = oWB.ActiveSheet
End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is what I have so far in C#, but it crashes on kEditOpenOLEVerb&lt;/P&gt;&lt;PRE&gt;Inventor.Application oApp = this.m_inventorApplication;
            ReferencedOLEFileDescriptor oOleRef = oApp.ActiveDocument.ReferencedOLEFileDescriptors[1];
            Microsoft.Office.Interop.Excel.Workbook oWB;
            oOleRef.Activate(kEditOpenOLEVerb, oWB);
            Microsoft.Office.Interop.Excel._Worksheet oSheet = (Microsoft.Office.Interop.Excel._Worksheet)oWB.ActiveSheet;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Any idea how I can modify this C# code to work the same way the VBA does? (I have to use C#)&lt;/P&gt;</description>
      <pubDate>Fri, 23 Mar 2012 13:47:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/how-do-i-programmatically-access-an-embedded-excel-document-from/m-p/3383351#M137013</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-03-23T13:47:51Z</dc:date>
    </item>
    <item>
      <title>Re: How do I programmatically access an embedded Excel document from a C# addon?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/how-do-i-programmatically-access-an-embedded-excel-document-from/m-p/3383611#M137014</link>
      <description>&lt;P&gt;I converted what you had in VBA to VB.NET and then to C# and it looks like this. I have changed it so I could test it from a standalone exe with the first line.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;public void openexcel()
{
	Inventor.Application oApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application");
	ReferencedOLEFileDescriptor oOleRef = oApp.ActiveDocument.ReferencedOLEFileDescriptors.Item(1);
	Excel.Workbook oWB = null;
	oOleRef.Activate(OLEVerbEnum.kEditOpenOLEVerb, oWB);
	Excel.WorkSheet oSheet = oWB.ActiveSheet;
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I don't do much C# ..&lt;img id="smileyindifferent" class="emoticon emoticon-smileyindifferent" src="https://forums.autodesk.com/i/smilies/16x16_smiley-indifferent.png" alt="Smiley Indifferent" title="Smiley Indifferent" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Mar 2012 15:36:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/how-do-i-programmatically-access-an-embedded-excel-document-from/m-p/3383611#M137014</guid>
      <dc:creator>Mike.Wohletz</dc:creator>
      <dc:date>2012-03-23T15:36:42Z</dc:date>
    </item>
    <item>
      <title>Re: How do I programmatically access an embedded Excel document from a C# addon?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/how-do-i-programmatically-access-an-embedded-excel-document-from/m-p/3383629#M137015</link>
      <description>&lt;P&gt;Your code converted to C# is very similar to what I have for C#. &amp;nbsp;However, unless you have a using reference I don't have yours wouldn't work either. &amp;nbsp;This is because in VBA, Inventor has&amp;nbsp;kEditOpenOLEVerb defined as something. &amp;nbsp;But from outside Inventor, C# or VB code still needs to define&amp;nbsp;kEditOpenOLEVerb before it can be used.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Mar 2012 15:49:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/how-do-i-programmatically-access-an-embedded-excel-document-from/m-p/3383629#M137015</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-03-23T15:49:26Z</dc:date>
    </item>
    <item>
      <title>Re: How do I programmatically access an embedded Excel document from a C# addon?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/how-do-i-programmatically-access-an-embedded-excel-document-from/m-p/3383639#M137016</link>
      <description>&lt;P&gt;Look at it agin,&amp;nbsp;kEditOpenOLEVerb is not correct in yours I dont think.. it should be &amp;nbsp;OLEVerbEnum.kEditOpenOLEVerb...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Mar 2012 15:55:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/how-do-i-programmatically-access-an-embedded-excel-document-from/m-p/3383639#M137016</guid>
      <dc:creator>Mike.Wohletz</dc:creator>
      <dc:date>2012-03-23T15:55:16Z</dc:date>
    </item>
    <item>
      <title>Re: How do I programmatically access an embedded Excel document from a C# addon?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/how-do-i-programmatically-access-an-embedded-excel-document-from/m-p/3383659#M137017</link>
      <description>&lt;P&gt;I tried that as well. &amp;nbsp;Neither way works for me. &amp;nbsp;As I have it now, it tells me it doesn't exist in the current contect(which makes sense). &amp;nbsp;Using your way, OLEVerbEnum.kEditOpenOLEVerb, it tells me that "the best overloaded method match has some invalid arguments". &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Mar 2012 15:59:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/how-do-i-programmatically-access-an-embedded-excel-document-from/m-p/3383659#M137017</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-03-23T15:59:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do I programmatically access an embedded Excel document from a C# addon?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/how-do-i-programmatically-access-an-embedded-excel-document-from/m-p/3383743#M137018</link>
      <description>&lt;P&gt;I don't know the answer to the C# part, but I tried what I have in VB.NET and it works just fine.. This is what I have in VB.NET..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;   Sub openexcel()
        Dim oApp As Inventor.Application = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
    Dim oOleRef As ReferencedOLEFileDescriptor  = oApp.ActiveDocument.ReferencedOLEFileDescriptors.Item(1)
        Dim oWB As Excel.Workbook = Nothing
        oOleRef.Activate(OLEVerbEnum.kEditOpenOLEVerb, oWB)
        Dim oSheet As Excel.Worksheet = oWB.ActiveSheet
        MsgBox(oSheet.Name)

    End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Mar 2012 16:25:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/how-do-i-programmatically-access-an-embedded-excel-document-from/m-p/3383743#M137018</guid>
      <dc:creator>Mike.Wohletz</dc:creator>
      <dc:date>2012-03-23T16:25:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do I programmatically access an embedded Excel document from a C# addon?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/how-do-i-programmatically-access-an-embedded-excel-document-from/m-p/3385713#M137019</link>
      <description>&lt;P&gt;Here is the error I'm coming across: "cannot convert from 'Microsoft.Office.Interop.Excel.Workbook' to out object". &amp;nbsp;My code below.&lt;/P&gt;&lt;PRE&gt;Inventor.Application oApp = this.m_inventorApplication;
            ReferencedOLEFileDescriptor oOleRef = oApp.ActiveDocument.ReferencedOLEFileDescriptors[1];
            Microsoft.Office.Interop.Excel.Workbook oWB = null;
            oOleRef.Activate(OLEVerbEnum.kEditOpenOLEVerb, oWB);
            Microsoft.Office.Interop.Excel.Worksheet oSheet = (Microsoft.Office.Interop.Excel.Worksheet)oWB.ActiveSheet;
            string name = oSheet.Name;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; The Activate function needs an out object. However, it must also be an Excel object, and C# seems unable to figure this out on its own. &amp;nbsp;&lt;SPAN&gt;Can anyone give advice on this?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Mar 2012 14:48:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/how-do-i-programmatically-access-an-embedded-excel-document-from/m-p/3385713#M137019</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-03-26T14:48:48Z</dc:date>
    </item>
    <item>
      <title>Re: How do I programmatically access an embedded Excel document from a C# addon?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/how-do-i-programmatically-access-an-embedded-excel-document-from/m-p/3386725#M137020</link>
      <description>&lt;P&gt;That means you should add "out" before the second parameter. I slightly modied the code and it should work: (also recommend to use try-catch as more as you can if you are not sure of how to use those functions)&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;using&lt;/SPAN&gt; Inventor;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;using&lt;/SPAN&gt; System.Runtime;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;using&lt;/SPAN&gt; Microsoft.Office.Interop.Excel;&lt;/P&gt;
&lt;P&gt;....&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Inventor.&lt;SPAN&gt;Application&lt;/SPAN&gt; oApp = &lt;SPAN&gt;null&lt;/SPAN&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN&gt;try&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; oApp = System.Runtime.InteropServices.&lt;SPAN&gt;Marshal&lt;/SPAN&gt;.GetActiveObject(&lt;SPAN&gt;"Inventor.Application"&lt;/SPAN&gt;) &lt;SPAN&gt;as&lt;/SPAN&gt; Inventor.&lt;SPAN&gt;Application&lt;/SPAN&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN&gt;catch&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN&gt;if&lt;/SPAN&gt; (oApp == &lt;SPAN&gt;null&lt;/SPAN&gt;) &lt;SPAN&gt;return&lt;/SPAN&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN&gt;if&lt;/SPAN&gt; (oApp.ActiveDocument != &lt;SPAN&gt;null&lt;/SPAN&gt;) {&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN&gt;if&lt;/SPAN&gt; (oApp.ActiveDocument.ReferencedOLEFileDescriptors.Count &amp;gt; 0)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN&gt;ReferencedOLEFileDescriptor&lt;/SPAN&gt; oOleRef = oApp.ActiveDocument.ReferencedOLEFileDescriptors[1];&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN&gt;Object&lt;/SPAN&gt; retObj = &lt;SPAN&gt;null&lt;/SPAN&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; oOleRef.Activate(&lt;SPAN&gt;OLEVerbEnum&lt;/SPAN&gt;.kEditOpenOLEVerb, &lt;SPAN&gt;out&lt;/SPAN&gt; retObj);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN&gt;try&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN&gt;Workbook&lt;/SPAN&gt; oWB = (&lt;SPAN&gt;Workbook&lt;/SPAN&gt;)retObj;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN&gt;Worksheet&lt;/SPAN&gt; oSheet = (&lt;SPAN&gt;Worksheet&lt;/SPAN&gt;)oWB.ActiveSheet;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN&gt;string&lt;/SPAN&gt; name = oSheet.Name;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; oWB.Close();&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN&gt;catch&lt;/SPAN&gt;(&lt;SPAN&gt;Exception&lt;/SPAN&gt; ex)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN&gt;MessageBox&lt;/SPAN&gt;.Show(ex.ToString());&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/P&gt;</description>
      <pubDate>Tue, 27 Mar 2012 06:48:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/how-do-i-programmatically-access-an-embedded-excel-document-from/m-p/3386725#M137020</guid>
      <dc:creator>barbara.han</dc:creator>
      <dc:date>2012-03-27T06:48:08Z</dc:date>
    </item>
  </channel>
</rss>

