Welcome to OfficeWriter v3 .NET Samples
OfficeWriter is designed as a server-based solution and is licensed by server CPU. However, that doesn't mean that you are limited to use OfficeWriter in ASP.NET application. The samples listed on this page are examples of other uses of OfficeWriter.
You can download any of these demos to run on your machine.
Database note: The samples listed on this page use the ADO.NET System.Data.SqlClient namespace to connect to Microsoft SQL Server and the AdventureWorks 2000 sample database.
If you do not have the AdventureWorks 2000 database on your SQL Server you can download it here.
SQL Server DTS Sample
Overview
You can use OfficeWriter from a Data Transformation Services (DTS) package in order to add Excel or Word document exporting to your DTS packages. This sample uses OfficeWriter to dump contents of a database into an Excel workbook.
The key part of this DTS package sample is the ActiveX Task in which OfficeWriter for Excel is used programmatically through VBScript.
Installation
Click below to download this sample. Follow the instructions in "readme.txt" to install on your server.
Windows Service Sample
Overview
This sample shows OfficeWriter's usage in a .NET Windows service. The ExcelTemplate and ExcelApplication objects are used together in this demo to show how generation of Excel reports can be automated in such a way that you do not have to write additional code for each report.
Create a simple ExcelTemplate workbook with data markers. For example, add %%=MyDsrc.FirstName and %%=MyDsrc.LastName to A1 and B1 of the first worksheeet. Add an additional worksheet to the workbook called "ReportConfig". In cell A1 of "ReportConfig" enter the data source name (MyDsrc). In cell A2, enter the query that you want to be the source of data for this report (SELECT FirstName, LastName FROM Employee). In cell A3, enter the connection string. Here is an example workbook that works with this service.
This sample service monitors a folder for new Excel workbooks (.xls files). When it detects that an Excel workbook has been dropped into the folder, OfficeWriter opens the workbook and looks for the "ReportConfig" worksheet. ExcelApplication reads the data source name, query, and connection string values from ReportConfig and then deletes it. The workbook is then opened as an ExcelTemplate object and populated with the data source defined in the ReportConfig sheet.
Installation
Follow this procedure to install this service sample on your machine:
Download the code - Get a Zip of this sample:
Build the project - Open the vbproj or csproj file. Add a project reference to SAXW6NET.dll (you can find this in the OfficeWriter install directory). Open the app.config file and set the "dropDir" value to a folder that will be monitored by this service. Build the project.
Install and start the service - Open a Visual Studio .NET command prompt and change directory to the \bin folder where the service .exe is built. Use the following command to install as a service: installutil /i Service.exe Later, you can uninstall the service with the same command, but using the /u switch instead of /i. If you open the Services window from your computer's Administrative Tools menu, you should see an entry for "OfficeWriterService". Start the service from the Services window or by issuing the "net start OfficeWriterService" command.
Test it out - Drop a properly set-up template file (or the example workbook) into the dropDir to test it.
Windows Form Sample
Overview
This sample connects to the AdventureWorks2000 sample database and creates a report that displays database statistics including total database size, and tables from each database. The interface for this sample is a Windows Form.
Both the ExcelTemplate and ExcelApplication objects are used in this demo. First, ExcelTemplate is used to populate the template file with summary information for
each database (the path to the template file is set in the app.config file). Then, if you check the "Show database table lists" box, ExcelApplication is used to add a worksheet for each database listing its tables.
Installation
Follow this procedure to run this sample on your computer:
Download the code - Get a Zip of this sample:
Build the project - Open the vbproj or csproj file. Add a project reference to SAXW6NET.dll (you can find this in the OfficeWriter install directory). Open the app.config file and set the path to the template workbook (dblisttemplate.xls). Build the project.
Run the application - Execute the emitted .exe file, or start from Visual Studio .NET.

Copyright 2005 © SoftArtisans, Inc. All Rights
Reserved.
|