Change sheet name and adding sheets with OWC XP

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I cannot seem to find any documentation on OWC XP on how to add new sheets to a SpreadsheetClass object nor how to rename the sheets so that the tab of each sheet has something I want.

Here is the code I have that I assume would change the name of the sheets:

SpreadsheetClass xlsheet = new SpreadsheetClass();
xlsheet.ActiveSheet.Name = "Hello!";
// Save it off to the filesystem...
xlsheet.Export(Server.MapPath("myfile.xls",
OWC10.SheetExportActionEnum.ssExportActionNone,
OWC10.SheetExportFormat.ssExportHTML);
// set content header so browser knows you're sending Excel workbook...
Response.ContentType="application/x-msexcel";
Response.AddHeader("content-disposition", "attachment; filename=myfile.xls");

// Stream it out!
Response.WriteFile(Server.MapPath("myfile.xls");

However, when the Excel spreadsheet is launched, I see a sheet with a tab named "Sheet" but it does not have the name I set.

How do I do this?

Also, once I've created a spreadsheet, how do I add more sheets to it? I would assume the following should work, but it only results in me getting a blank spreadsheet with one sheet in it:

SpreadsheetClass xlsheet = new SpreadsheetClass();
xlsheet.ActiveWorkbook.Sheets.Add(Type.Missing, Type.Missing, 5, XlSheetType.xlWorksheet);

However, once I've saved the file and launch it, there is only 1 sheet in it.

Is this not possible in ASP.NET? The file is getting saved on the server side and then streamed down to the client.

Thanks for any help.
 
Back
Top