LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Maximum worksheets in an Excel..

Hi Friends,
I am making a C# application that will create reports in Excel
from a database. My report involves creating many worksheets. Is there
any limitation for maximum worksheets in a workbook. As per Microsoft
the number of worksheets is only limitted by memory.. For me if i
create more than 256 sheets i get the exception with the value
0x800A03EC.

I get the exception here...
sheet1 = (Worksheet)book.Sheets.Add(_missing,
(object)sheet1, (object)(260), _missing);
if i keep the worksheets to be less than 256 i am able to create the
report...

Ive given the code for the reference...

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Interop;
using Microsoft.Office.Interop.Excel;


namespace MaxSheetsExcel
{

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private object _missing = System.Reflection.Missing.Value;
private string _filename =
@"D:\VDC_emailExport\ExcelTemplate\MaxSheetsExcel. xls";
private string _template =
@"D:\VDC_emailExport\ExcelTemplate\Template_Def.xl s";
private void button1_Click(object sender, EventArgs e)
{
//MessageBox.Show("Button Clicked!");
// excel objects
Microsoft.Office.Interop.Excel.Application ExcelApp = null;
Workbook book = null;
Worksheet sheet1 = null;
Workbooks books = null;

ExcelApp = new
Microsoft.Office.Interop.Excel.Application();
books = ExcelApp.Workbooks;
//Hesri - Instead of creating a workbook from scratch make
use of a template
//to create the report
book = ExcelApp.Workbooks.Open(_template, _missing,
_missing, _missing, _missing, _missing, _missing, _missing, _missing,
_missing, _missing, _missing, _missing, _missing,
_missing);
//book = books.Add((object)XlWBATemplate.xlWBATWorksheet);


sheet1 = (Worksheet)book.Sheets[1];
sheet1.Name = "Report_parameters";
for (int i = book.Sheets.Count; i = 2; i--)
{
sheet1 = (Worksheet)book.Sheets[i];
sheet1.Delete();
}
sheet1 = (Worksheet)book.Sheets.Add(_missing,
(object)sheet1, (object)(260), _missing);

book.SaveAs((object)_filename, _missing, _missing,
_missing, _missing, (object)false, XlSaveAsAccessMode.xlExclusive,
_missing, _missing, _missing, _missing, _missing);

ReleaseComObject(sheet1);
book.Close(false, (object)_filename, false);
ExcelApp.Workbooks.Close();
ReleaseComObject(book);
ReleaseComObject(books);
ExcelApp.Quit();
ReleaseComObject(ExcelApp);
GC.Collect();
GC.WaitForPendingFinalizers();
}
private void ReleaseComObject(object ExcelObj)
{
try
{

System.Runtime.InteropServices.Marshal.ReleaseComO bject(ExcelObj);
}
finally
{
ExcelObj = null;
}
}


}
}

Regards
Senthil

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a maximum of the number of worksheets in a workbook? CYNTHIA Excel Discussion (Misc queries) 6 December 18th 07 02:46 PM
Maximum number of worksheets in XL raju Excel Discussion (Misc queries) 6 November 17th 06 07:38 PM
maximum number of worksheets Shooter Excel Worksheet Functions 8 July 1st 06 06:38 AM
Maximum number of worksheets in Excel 2003 Josh Sale Excel Programming 1 January 9th 06 04:51 PM
Maximum value from multiple worksheets Brian Allen Excel Programming 3 November 4th 04 12:23 AM


All times are GMT +1. The time now is 02:02 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"