Excel 2000 with OWC11

S

Stefan Hirtbach

Hi,
I wrote a small program in C#, using OWC11, that fills data in an excelsheet
and save it to disk as xls-file (using the Export-function).
It works well with Office 2003 but i've got problems using the file in
Office 2002 and 2000. It seems that the exported file is in an XML-file and
not an native Excel-file. Is it possible to generate a native File to use it
with 2000 and 2002, or have I to grade down to OWC10?

BTW: How do I color cells and add macros in an Spreadsheet

Thanks in advance
Stefan

---Code---
OWC11.SpreadsheetClass xlsheet = new OWC11.SpreadsheetClass();
xlsheet.Cells[1,1] = "A";
xlsheet.Export("test.xls",OWC11.SheetExportActionEnum.ssExportActionNone,
OWC11.SheetExportFormat.ssExportAsAppropriate);
 
Joined
Jan 15, 2009
Messages
1
Reaction score
0
Excel 2000 with OWC11 RESOLVED

Hi folks,
in order to export xls to excel 2000 using owc11 you have to do a little hack

Use the SpreadSheet.Export function to export in html format an then save the object to a file.

than you have to send this file to user.
In my case, using C# and Asp.Net, an HTTPHandler solve that for me..

Here is a sample code to export the file to Excel



//PROCESSREQUEST INITIALIZATION
context.Response.Buffer = true;
context.Response.ContentType = "application/vnd.ms-excel;";
context.Response.Charset = "ISO-8859-1";
context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("ISO-8859-1");
context.Response.AddHeader("content-disposition", "attachment;filename=PlanilhaExcel.xls");
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);



//CREATE THE SPREADSHEET OBJECT
SpreadsheetClass spr = new SpreadsheetClass();
Worksheet worksheet = (Worksheet)spr.ActiveSheet;

//WRITE YOUR CONTENT
....



//CREATE A RANDOM FILE TO SAVE THE CONTENTS
String randomFile = "~/temp/" + Guid.NewGuid().ToString() + ".xls";

//EXPORT THIS FILE INTO HTML FORMAT
spr.Export(context.Server.MapPath(randomFile), SheetExportActionEnum.ssExportActionNone, SheetExportFormat.ssExportHTML);


// IN ORDER TO MAKE THE HANDLER EXPORT THE XLS FILE I REOPENED THE FILE AND SEND THE
// CONTENTS THRU Response.Write

StreamReader streamReader = new StreamReader(context.Server.MapPath(randomFile));
context.Response.Write(streamReader.ReadToEnd());
streamReader.Close();
File.Delete(context.Server.MapPath(randomFile));
context.Response.End();




I Hope it helped

C Ya All
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top