• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Valued Contributor
    Ertqwa
    Posts: 73
    Registered: ‎10-03-2011

    Read Embedded Excel sheet

    282 Views, 14 Replies
    02-08-2013 11:11 AM

    Hello,

     

    I have a drawing with an embedded Excel sheet. I want to read the contents of the excel sheet. How can this be done? Maybe in combination with Microsoft.Office.Interop.Excel?

     

    Ty.

    Please use plain text.
    ADN Support Specialist
    Posts: 162
    Registered: ‎07-24-2007

    Re: Read Embedded Excel sheet

    02-11-2013 05:22 PM in reply to: Ertqwa

    Does this help

     

    http://adndevblog.typepad.com/autocad/2012/04/update-linked-ole-object-from-net.html





    Fenton Webb

    Developer Technical Services

    Autodesk Developer Network


    Please use plain text.
    Valued Contributor
    Ertqwa
    Posts: 73
    Registered: ‎10-03-2011

    Re: Read Embedded Excel sheet

    02-11-2013 08:50 PM in reply to: fenton.webb

    Hi,

     

    I already saw some articles about linked OLE objects, but not about embedded OLE objects. But maybe it will help me, I'll look it at.

     

    Thank you.

    Please use plain text.
    Active Contributor
    Posts: 40
    Registered: ‎09-04-2012

    Re: Read Embedded Excel sheet

    02-12-2013 08:29 AM in reply to: Ertqwa

    How do you embed an Excel spreadsheet into a DWG?

    Linking means the .xls(x) is somewhere else but we hold a reference to the spreadsheet.

    Embedding would mean the Excel object, the spreadsheet and its information is actually inside the DWG. I Haven't tinkered with that possibility yet, how did you manage to achieve it?

    Besides from that.

    Whether you have the Excel file inside the DWG or just a link to it, just open the Excel object like you would any Excel file, either early or latebound.

    Some say "Write in early bound, compile, debug and then translate into late bound", for performance and compability reasons of course.

    If you're looking into writing something quick, just do early bound and don't waste time translating.

    If you have the time, early bound and then late bound. Creating a custom class can do wonders.

    Please use plain text.
    Valued Contributor
    Ertqwa
    Posts: 73
    Registered: ‎10-03-2011

    Re: Read Embedded Excel sheet

    02-13-2013 11:55 AM in reply to: DouceDeux

    Hi,

     

    I open Excel, add data, copy the cells, and paste it in Autocad. I close Excel without saving it.

    I right-click the Excel table in AutoCAD and pick OLE->OPEN to open it again in Exel to edit it.

    Since I dont save the Excel file, I assume it is saved in the dwg.

     

    Ty for your reply.

    Please use plain text.
    Active Contributor
    Posts: 40
    Registered: ‎09-04-2012

    Re: Read Embedded Excel sheet

    02-13-2013 04:50 PM in reply to: Ertqwa

    For the life of meeeee!
    God damned OLE objects!

    I'm stuck here:

    [CommandMethod("test1")]
    public void test1()
    {
      Database newD = Application.DocumentManager.MdiActiveDocument.Database;
      Editor newE = Application.DocumentManager.MdiActiveDocument.Editor;
      PromptEntityResult per = newE.GetEntity("Pick a OLE object: ");
      Object id = per.ObjectId;
    
      using (Transaction newT = newD.TransactionManager.StartTransaction())
      {
        Ole2Frame myOle = newT.GetObject(per.ObjectId, OpenMode.ForRead) as Ole2Frame;
        object excel = myOle.OleObject;
      }
    }

    I don't know what to do with that object or how to find how what to do with it.
    I've tried everything I could think of (which wasn't much). Online search would not help.

    It's an interesting topic, I guess I would need to read about OLE objects.

    These guys were on to something, or solved it, I dont even know now:
    http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/How-do-I-programmatically-access-an-em...
    but it's for Inventor, I dont know if the AutoCAD API has a ReferencedOLEFileDescriptor type.
    Keep me updated.

    Please use plain text.
    ADN Support Specialist
    Posts: 162
    Registered: ‎07-24-2007

    Re: Read Embedded Excel sheet

    02-14-2013 03:13 PM in reply to: DouceDeux

    OleObject returns an unmanaged COleClientItem object. I don't believe that is exposed by via our .NET API so you are totally on your own there. Your best (perhaps only) option is to use C++





    Fenton Webb

    Developer Technical Services

    Autodesk Developer Network


    Please use plain text.
    Moderator
    Alexander.Rivilis
    Posts: 1,168
    Registered: ‎04-09-2008

    Re: Read Embedded Excel sheet

    02-15-2013 01:26 AM in reply to: fenton.webb

    Looks like it is possible in .NET but with P/Invoke:

    Update linked OLE object from .NET


    Пожалуйста не забывайте про Утвердить в качестве решения!Утвердить в качестве решения и Give Kudos!Баллы
    Please remember to Accept Solution!Accept as Solution and Give Kudos!Kudos

    Please use plain text.
    ADN Support Specialist
    Posts: 162
    Registered: ‎07-24-2007

    Re: Read Embedded Excel sheet

    02-15-2013 07:24 AM in reply to: Alexander.Rivilis

    I believe that allows you to update the link, not gain access to the OleClientItem itself. But maybe that's all that's needed here?





    Fenton Webb

    Developer Technical Services

    Autodesk Developer Network


    Please use plain text.
    Moderator
    Alexander.Rivilis
    Posts: 1,168
    Registered: ‎04-09-2008

    Re: Read Embedded Excel sheet

    02-15-2013 07:42 AM in reply to: fenton.webb

    Hi, Fenton!

    I do not think this is all that is necessary to the author. But I point out a direction that may lead him to the solution of its problems.

    Description of COleClientItem class: http://msdn.microsoft.com/en-us/library/et2y5cd7%28v=vs.100%29.aspx

    IMHO it is possible call P/Invoke any methods of COleClientItem for any purpose. For example, to run associated application (Word/Excel/etc.) hi can P/Invoke method COleClientItem::Run


    Пожалуйста не забывайте про Утвердить в качестве решения!Утвердить в качестве решения и Give Kudos!Баллы
    Please remember to Accept Solution!Accept as Solution and Give Kudos!Kudos

    Please use plain text.