We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

System.ArgumentException: The section number is out of range

I’m getting that exception when processing the file attached. My Hashtable has simple values like (##DatRev, 11032011). My code is:

Workbook xls = new Workbook(pFileName);
foreach (DictionaryEntry item in htTagsRegs)
{
for (int i = 0; i < xls.Worksheets.Count; i++)
{
Aspose.Cells.PageSetup pageSetup = xls.Worksheets[i].PageSetup;
for (int j = 0; j < xls.Worksheets.Count; j++)
{
string header = pageSetup.GetHeader(j);
if (header != null && header != “”)
{
header = header.Replace(item.Key.ToString(), item.Value.ToString());
pageSetup.SetHeader(j, header);
}
string footer = pageSetup.GetFooter(j);
if (footer != null && footer != “”)
{
footer = footer.Replace(item.Key.ToString(), item.Value.ToString());
pageSetup.SetFooter(j, footer);
}
}
xls.Worksheets[i].Replace(item.Key.ToString(), item.Value.ToString());
}
}
xls.Save(pTmpFileName, Aspose.Cells.SaveFormat.ODS);

Hi,

Thanks for reporting this issue.

Please provide me code relating to HashTable (htTagsRegs) populating it with some dummy values so that I could be able to execute it.

Hashtable htTagsRegs = new Hashtable();
htTagsRegs.Add("##CodDoc", “CodDoc”);
htTagsRegs.Add("##NumRev", “NumRev”);
htTagsRegs.Add("##TitDoc", “TitDoc”);
htTagsRegs.Add("##DatCri", “DatCri”);
htTagsRegs.Add("##NmeApr", “NmeApr”);
htTagsRegs.Add("##TipCop", “TipCop”);
htTagsRegs.Add("##DatImp", “DatImp”);
htTagsRegs.Add("##SigUni", “SigUni”);

Hi,


Thanks for providing us your source code and template file.
There is small issue in your source code. Please see my comments below,

C# Code:

Workbook xls = new Workbook(pFileName);
foreach (DictionaryEntry item in htTagsRegs)
{
for (int i = 0; i < xls.Worksheets.Count; i++)
{
Aspose.Cells.PageSetup pageSetup = xls.Worksheets[i].PageSetup;

//This Loop [for (int j = 0; j < xls.Worksheets.Count; j++) ] is in correct,
//Because there are only three sets of Header and Footer
//That means there are 3 Header [Left, Centre, Right], Same for Footer
//Where as you are looping over the number of worksheets that are 7 in your provided
//Template file. Please use [for (int j = 0; j < 3; j++)]
for (int j = 0; j < xls.Worksheets.Count; j++)
{
string header = pageSetup.GetHeader(j);
if (header != null && header != “”)
{
header = header.Replace(item.Key.ToString(), item.Value.ToString());
pageSetup.SetHeader(j, header);
}
string footer = pageSetup.GetFooter(j);
if (footer != null && footer != “”)
{
footer = footer.Replace(item.Key.ToString(), item.Value.ToString());
pageSetup.SetFooter(j, footer);
}
}
xls.Worksheets[i].Replace(item.Key.ToString(), item.Value.ToString());
}
}
xls.Save(pTmpFileName, Aspose.Cells.SaveFormat.ODS);