The following screen captures will show you how to create a Windows C# application that takes advantage of xlsgen.
Start VisualStudio .NET, click on New Project
and choose Windows Application
from the available C# projects.
When the project is created, open the Solution window. Right-click on Reference
, and select Add a reference
.
Click on the COM
tab, look up component named : Excel Generator.ARsT design 2003
. Double-click on it, and click ok.
At this point, the component need to be registered before it appears in the window. Installing the product automatically registers that component. Contact the technical support in case you don't know what to do with it.
Doing so, VisualStudio creates a file Interop.xlsgen.dll
in your application directory known as a COM interop assembly which lets you use the application object model with any .NET language, including C#.
When VisualStudio completes the integration of the component, it appears right in the list of references with the following name : xlsgen
.
In order to access easier the component interfaces, it is recommended to add an appropriate namespace statement in your code :
Right-click in Form1 and select View code
. In the source code, add the following statement near other using statements :
using xlsgen;
Just type ix and hit Ctrl-Space, this should bring intellisense and show the component interfaces.
Paste the following code in Form1.cs
, then build the solution and run it :
xlsgen.CoXlsEngine engine = new xlsgen.CoXlsEngine(); IXlsWorkbook wbk = engine.New( @"c:\myfirstfile.xls" ); IXlsWorksheet wksht = wbk.AddWorksheet( "samplesheet" ); wksht.set_Label(1,2, "Hello world!"); wbk.Close(); System.Diagnostics.Process.Start( @"c:\myfirstfile.xls" ); System.Runtime.InteropServices.Marshal.ReleaseComObject(engine);
What we basically do is create a component instance, name the Excel file we want to create, create a worksheet, add a simple Hello World! label, and close it. Excel is then automatically started, only to show the resulting Excel file.
That shows how simply it is to generate Excel files without ever relying on Excel itself.
Plain and simple!
The source code for that C# project is available here (26 kb). Unzip the file, and double-click on the .sln file.
Note that if you'd like to see a sample program which reads a .NET dataset and imports it into an Excel workbook using xlsgen code, you may want to take a look at sample called "dataset" available in the C# and VB.NET folders of the install.