Bill Blogs in C#

Bill Wagner discusses C#, LINQ, and other items of interest

Simple Excel Formatting with OWC
How to use Office Web Components to create custom spreadsheets on the server

Question: Creating Excel Templates in OWC

Thank for offering to help. I am having a tough time getting started using OWC. Maybe because MS doesn’t  provide any documentation...

I have found out how to dynamically create a spreadsheet:

Add a reference to OWC11

then program:

But...
This isn't quite what I need.

What I would like to do is to

I do not want to run Excel per-se on the server because of 1) licensing and 2) server load. OWC is supposedly very light weight.

Answer:

I found two different ways to do this.

The first way (preferred):

1. Save your XLS template as an XML file. (which you did.)
2. Create the new spreadsheet as you have.
3. Use the XMLData property of the spreadsheet component to load the XML stream from the saved template:
System.IO.StreamReader rs = new StreamReader("template.xml");
string xmlContentFromFile = rs.ReadToEnd();
xlsSheet.XMLData = xmlContentFromFile;
That will give you the information from your XML spreadsheet.
4. Load the SQL Data into your spreadsheet.

If you need to use OWC 9.0, or Excel 2000:

 



Published Saturday, May 15, 2004 5:49 PM by wwagner
Filed under:

Comments

No Comments