Free Support Forum -

Copy and process multiple/dynamic worksheets

I have the below - but am getting an index failure on the process - should be pretty straight-forward, but am missing something.

What I am trying to do - is to take the first sheet and copy it and then process each accordingly.

protected void Button1_Click(object sender, EventArgs e)


string s = "27235,99282";

string path = MapPath(".");

path = path.Substring(0, path.LastIndexOf("\\"));

string designerFile = path + @"\reports\APC - Claim Analysis.xlsx";

//Create WorkbookDesigner object.

WorkbookDesigner wd = new WorkbookDesigner();

Workbook wb = wd.Workbook;

WorksheetCollection sheets = wb.Worksheets;

string[] words = s.Split(',');

for (int i = 0; i < words.Length; i++)



SqlParameter[] aryParams = new SqlParameter[4];

aryParams[0] = new SqlParameter("@strDB", SqlDbType.VarChar);

aryParams[0].Value = "dbRedlands";

aryParams[1] = new SqlParameter("@intMarketGroupID", SqlDbType.Int);

aryParams[1].Value = 1;

aryParams[2] = new SqlParameter("@strQuery", SqlDbType.VarChar);

aryParams[2].Value = words[i];

aryParams[3] = new SqlParameter("@strYear", SqlDbType.VarChar);

aryParams[3].Value = "2010";

DataSet ds = SqlHelper.ExecuteDataset(ConnectionStrings.PDE, CommandType.StoredProcedure, "spPDE_Report_OPStatusT_SimpleGroup", aryParams);

DataTable dt = ds.Tables[0];

dt.TableName = "Summary";

//Open the template file (which contains smart markers).




wd.Process(i, true);

Worksheet oWorkSheet = wb.Worksheets[i];

oWorkSheet.Name = words[i];


string outputName = "APC - Claim Analysis.xlsx";

OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();

saveOptions.SaveFormat = SaveFormat.Xlsx;

wd.Workbook.Save(this.Response, outputName, ContentDisposition.Attachment, saveOptions);




Please provide us your complete runnable project and remove all the db related code. Please use hardcoded values instead. We will look into it and help you asap.