Author Topic: reference or late bind excel  (Read 2233 times)

0 Members and 1 Guest are viewing this topic.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
reference or late bind excel
« on: July 15, 2010, 11:24:55 AM »
OK I have never done this in C#, so my question, Is it better to late bind excel for use in Autocad or to reference it in the project?  And on top of that, do I reference a DLL or the com thingy.  What I want to do is open excel for write, read my titleblock attributes, and write those values to excel.  My big stumbling block is how to connect to excel.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: reference or late bind excel
« Reply #1 on: July 15, 2010, 11:25:51 AM »
I tried looking through the examples here on the swamp, but the most I could find was a USING statement, but I didn't know how the connection was made.
Code: [Select]
// borrowed from fixo
using Microsoft.Office.Interop.Excel;
using Excel = Microsoft.Office.Interop.Excel;

//' References -> COM -> Microsoft.Excel XX.0 Object Library
//' Create form and drop Button1 and ListView1 on it
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: reference or late bind excel
« Reply #2 on: July 15, 2010, 06:30:47 PM »
Hello David,

I recall that Kean has done a few posts regarding the use of Excel
... perhaps a search on his site will reveal a nugget.

haven't tried myself so can't post a sample and I'm up to my ears at the moment ...

[added]
Perhaps ?
http://through-the-interface.typepad.com/through_the_interface/excel/
« Last Edit: July 15, 2010, 06:37:41 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: reference or late bind excel
« Reply #3 on: July 15, 2010, 06:42:25 PM »
thanks Kerry, i will check that out now!
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: reference or late bind excel
« Reply #4 on: July 16, 2010, 03:38:22 AM »
Hi,

I tried something to read/write excel from AutoCAD (here).
I used late binding to solve compatibility issues: from the tests I did, a dll compiled against an Excel version won't work with earlier versions.
Speaking English as a French Frog

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: reference or late bind excel
« Reply #5 on: July 16, 2010, 03:43:57 AM »
Hi,

I tried something to read/write excel from AutoCAD (here).
I used late binding to solve compatibility issues: from the tests I did, a dll compiled against an Excel version won't work with earlier versions.

I KNEW I'd seen some code here somewhere .. :)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Glenn R

  • Guest
Re: reference or late bind excel
« Reply #6 on: July 16, 2010, 06:00:40 AM »
Read all about it - get yer early/late binding here.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: reference or late bind excel
« Reply #7 on: July 16, 2010, 11:15:16 AM »
Thanks everyone, lots of reading to do now. ;)
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Jerry J

  • Newt
  • Posts: 48
Re: reference or late bind excel
« Reply #8 on: July 23, 2010, 06:50:20 PM »
I really don't see any advantage to late binding, in that if you have the typelib for the earliest version you wish to support you would obviously use early binding for the intellisence and compile time error reporting.  If you don't have the typelib then how would you know if the method even existed, except for the runtime error, and then it's too late. I guess the late binding would be handy if you know the methods for each version and then ...switch case v1; v2; etc.  Is this really what Microsoft is saying?

Jerry