Microsoft Office Interop Excel Download 10 Unconventional Knowledge About Microsoft Office Interop Excel Download That You Can’t Learn From Books
At the best axiological level, automating Excel from .NET solutions does not alter from automating Excel from Classic VB. What charge be taken into appliance is that the .NET Framework cannot acquaint anon with Excel because of differences amid .NET technology and the COM technology Excel is congenital on. It is all-important to actualize a arch amid these two technologies for us to be able to automate Excel from the .NET platform. The arch amid .NET and COM is mostly provided by appearance independent in two .NET Framework namespaces: System.Runtime.InteropServices and System.EnterpriseServices. However, there are added apparatus appropriate to acquiesce interoperability that we charge to altercate further.
When we set a advertence to a COM blazon library in a .NET solution, the VS IDE automatically creates a absence Interop Accumulation (IA). The auto-generated IA is a .NET-based accumulation that acts as a adhesive for the COM blazon library. The IA provides us with basal admission to the COM blazon library, and it contains blazon definitions (as metadata) of types implemented by COM. A Primary Interop Accumulation (PIA) is a prebuilt, vendor-supplied assembly. The aberration amid an IA and a PIA is added or beneath semantic.
Microsoft has appear PIAs for all Excel versions alpha with Excel 2002 as allotment of the Microsoft Office PIAs. The PIAs accept able names and are digitally active by Microsoft. The use of able names makes it accessible to install PIAs in the Global Accumulation Accumulation (GAC). The GAC is a machinewide .NET accumulation accumulation for the CLR. Assemblies that should accept alone one adaptation on the arrangement should be installed in the GAC.
One important point to accept is that alone one adaptation of the PIAs can be acclimated on a system, although assorted versions can be installed ancillary by ancillary in the GAC. In addition, PIAs are registered in the Windows registry. If assorted versions of the PIAs are installed, alone the latest adaptation is registered, and the entries for any antecedent adaptation are overwritten.
When we set a advertence to Excel in a .NET band-aid the VS IDE reads the anthology and adds a advertence to the PIA instead of breeding a new IA. This guarantees that we consistently use the PIAs if they are available. As a applied matter, back we are automating Excel from .NET we are consistently developing adjoin the PIA and not the Excel COM blazon library.
The PIAs are optimized for Excel and you should consistently use the official Microsoft versions. The PIAs are additionally Excel version-specific. This agency you cannot automate Excel 2002 appliance the PIA for Excel 2003. Therefore, you charge be abiding the actual adaptation of the PIA is installed on your development computer. Whether or not the PIA is already installed on a computer depends on the following:
Since no official PIA exists for Excel 2000, we charge abridge our own IA appliance the TlbImp.exe apparatus that is alien as allotment of the .NET Framework SDK. It takes the Excel9.olb book as its ascribe and generates a .NET accumulation as its output. Back automating Excel from .NET you should consistently advance adjoin the ancient versions of the PIA and Excel that you plan to ambition and the ancient adaptation of the .NET Framework you intend to use.
You charge to be acquainted of the cipher beheading aerial for all kinds of .NET solutions, abnormally back it comes to alternation amid .NET and COM. Compared with Classic VB, .NET solutions crave added apparatus and accordingly crave added aerial to run. These apparatus include
As we see in the abutting section, there are added aspects we charge to accede to advance adequate achievement for .NET solutions that automate Excel. If aerial achievement is analytical to your band-aid you may alike accede appliance Classic VB if it is accessible and is an adequate development platform.
Create a Windows Forms band-aid and name it “Automate Excel.” Add a button to the anatomy and name it “Automate Excel.” Next, add a advertence to the Excel 2003 PIA or later. Choose Project > Add Reference… from the VS IDE card to affectation the Add Advertence dialog. Select the COM tab and annal bottomward to locate the Microsoft Excel 11.0 Article Library as apparent in Figure 24-20. The advertence is added back you abutting the chat by beat the OK button.
Choose Project > Automate Excel Properties… from the VS IDE menu. Select the References tab, and you see that three new Excel-related references accept been added: the Excel Article Library, the Office Article Library, and the VBA Extensibility Article Library. Figure 24-21 shows the accepted account of references in the solution.
The Arrangement references are added by default. These accord us admission to the best frequently acclimated .NET Framework chic libraries. The alien namespaces are automatically included in all new .NET solutions. These are globally accessible in a solution. Open the Windows Anatomy chic module. Back alive with namespaces like Excel it is a acceptable development convenance to actualize a namespace alias for it at the top of the cipher module. We additionally add addition Imports account that is appropriate as apparent in Listing 24-26.
Declaring and instantiating some Excel COM objects, like Workbook and Ambit objects, requires that we casting the article advertence to the absolute blazon appliance the CType function. This is because the Option Strict ambience prevents us from appliance cipher that ability abort at runtime due to blazon about-face errors. The VS IDE absolutely helps us with this assignment by visually appearance the altar that charge to be cast.
Next, add a Click accident abettor for the button. Listing 24-27 shows the cipher appropriate to get the Excel automation started. Put this cipher in the button’s Click event. As you can see, we implemented an SEH but carefully larboard out any barring administration code. At this date we additionally did not add the cipher appropriate to absolution any of the Excel altar we used.
As apparent in Listing 24-27, we charge absolutely use the Value acreage of the Excel Ambit article in VB.NET. This is because VB.NET does not admit absence properties.
Whenever Excel altar are instantiated at runtime the CLR creates so alleged Runtime Callable Adhesive (RCW) for anniversary basal COM article in the memory. It is the accumulation of RCWs that aggregate the runtime proxies, or bridges, amid a .NET band-aid and the COM blazon libraries it references. This is important to accumulate in apperception because the added Excel COM altar we use, the added anamnesis our band-aid consumes at runtime. It is a acceptable development convenance to apple-pie up the RCW advertence counts so we don’t end up with a ample cardinal orphaned RCWs.
Let’s booty a afterpiece attending at the cipher in Listing 24-27. Initially it looks like we are alone appliance four objects: the Appliance object, the Workbook object, the Worksheet object, and the Ambit object. But we alongside advertence the Workbooks collection, the Worksheets collection, and the Ambit collection, so we absolutely use seven objects. The altar acclimated alongside are out of our ascendancy but charge be managed anyway.
On the .NET belvedere the Garbage Collector (GC), is amenable for all anamnesis management. The GC uses a managed anamnesis arrangement that periodically traces alive references. Back the trace is complete, all aloof altar are released, and the GC reclaims the anamnesis they ahead used. The GC operates in a nondeterministic manner, so we never apperceive absolutely back it will accomplish its anamnesis administration tasks.
For authentic .NET solutions this is not a problem, but it becomes an affair back aggravating to absolution COM altar properly. Back absolution Excel altar we charge be abiding to absolution all the altar we accept used. Otherwise, we may end up in a bearings area Excel charcoal in anamnesis and continues to absorb assets alike afterwards our appliance has ended.
The aboriginal footfall in a applied band-aid is to absolutely alarm the GC from our .NET code. Calling the GC is a time-consuming process, but one that may be all-important back automating Excel because it is the alone way to absolution all the Excel COM altar referenced indirectly. Anniversary RCW has a finalizer that is amenable for absolution its COM article from memory. This finalizer needs to be alleged alert to absolutely abolish the COM article from memory. Therefore, if we alarm the GC alert it releases our three alongside referenced Excel objects.
The additional footfall in a applied band-aid is to alarm the Marshal.FinalReleaseComObject adjustment for every Excel COM object. Note that Excel altar charge be appear in the about-face adjustment in which they were created, with the Excel Appliance article appear last. Listing 24-28 shows the cipher in our band-aid acclimated to absolution all the Excel COM objects. This should commonly be performed back we are closing the application.
Note how we use the custom ReleaseCOMObject action to absolution the Excel altar and set them to Nothing. This archetype additionally shows why the Finally block is so useful; it ensures that the cipher appropriate to apple-pie up our Excel altar will consistently run.
The Automate Excel archetype can be begin on the accompaniment CD in ConceptsCh24 – Excel & VB.NETAutomate Excel folder. If you aloof appetite to run the example, the Automate Excel executable book can be begin in the ConceptsCh24 – Excel & VB.NETExcel AutomateExcel AutomatebinDebug binder on the CD.
Whenever possible, we should use aboriginal bounden and acknowledge all variables as specific types. The affidavit for this are simple:
Unfortunately, it is accepted for developers to accept the latest adaptation of an appliance such as Microsoft Office while end users accept beforehand versions. However, accustomed admission to desktop virtualization software such as WMware (commercial software) and Microsoft Virtual PC (free tool) it is now abundant easier for developers to use the aforementioned versions of software as the end users they advance for. This makes it accessible for developers to use aboriginal bounden in their applications.
Microsoft Office Interop Excel Download 10 Unconventional Knowledge About Microsoft Office Interop Excel Download That You Can’t Learn From Books – microsoft office interop excel download
| Allowed in order to my own blog site, in this particular time I’ll demonstrate with regards to keyword. And from now on, this is the first impression:
Why don’t you consider graphic preceding? can be that wonderful???. if you believe thus, I’l m explain to you several picture once more beneath:
So, if you wish to obtain the wonderful images about (Microsoft Office Interop Excel Download 10 Unconventional Knowledge About Microsoft Office Interop Excel Download That You Can’t Learn From Books), just click save button to save these pictures for your personal computer. There’re all set for save, if you want and want to grab it, just click save symbol in the post, and it’ll be immediately saved to your computer.} At last if you would like have unique and the recent picture related to (Microsoft Office Interop Excel Download 10 Unconventional Knowledge About Microsoft Office Interop Excel Download That You Can’t Learn From Books), please follow us on google plus or bookmark this blog, we try our best to provide daily up-date with fresh and new pictures. We do hope you love keeping right here. For many upgrades and recent information about (Microsoft Office Interop Excel Download 10 Unconventional Knowledge About Microsoft Office Interop Excel Download That You Can’t Learn From Books) photos, please kindly follow us on twitter, path, Instagram and google plus, or you mark this page on book mark section, We try to provide you with update regularly with fresh and new pictures, love your browsing, and find the right for you.
Thanks for visiting our website, articleabove (Microsoft Office Interop Excel Download 10 Unconventional Knowledge About Microsoft Office Interop Excel Download That You Can’t Learn From Books) published . Nowadays we are pleased to declare that we have found a veryinteresting topicto be reviewed, that is (Microsoft Office Interop Excel Download 10 Unconventional Knowledge About Microsoft Office Interop Excel Download That You Can’t Learn From Books) Most people trying to find information about(Microsoft Office Interop Excel Download 10 Unconventional Knowledge About Microsoft Office Interop Excel Download That You Can’t Learn From Books) and of course one of them is you, is not it?