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

Free Support Forum - aspose.com

Error in autofiitter merged cells code

Hi ,

I am using aspose.cells for my app development. In that i am merging the cells of 7 columns in a single row. at last applying autofitter option…

but i got an error like Index and length must refer to a location within the string.Par​ameter name: length

my code is :

Aspose.Cells.Style headerStyle = sheet.Cells[0, 0].GetStyle();
headerStyle.Font.IsBold = true;
headerStyle.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = Aspose.Cells.CellBorderType.Thin;
headerStyle.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = Aspose.Cells.CellBorderType.Thin;
headerStyle.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = Aspose.Cells.CellBorderType.Thin;
headerStyle.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = Aspose.Cells.CellBorderType.Thin;

Aspose.Cells.Style dataStyle = sheet.Cells[0, 0].GetStyle();
dataStyle.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = Aspose.Cells.CellBorderType.Thin;
dataStyle.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = Aspose.Cells.CellBorderType.Thin;
dataStyle.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = Aspose.Cells.CellBorderType.Thin;
dataStyle.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = Aspose.Cells.CellBorderType.Thin;
dataStyle.IsTextWrapped = true;

notationList.Count = 2;
notationList[0].notesId = 1;
notationList[1].notesId = 2;
notationList[0].notesDescription = “some text”;
notationList[1].notesDescription = “text2”;
rowCount = 15;
int offfset = 4;
if (notationList.Count != 0)
sheet.Cells[rowCount + offfset, 0].PutValue(“NoteId”);
headerStyle.HorizontalAlignment = TextAlignmentType.Left;
sheet.Cells[rowCount + offfset, 0].SetStyle(headerStyle);
sheet.Cells[rowCount + offfset, 1].PutValue(".NOTES_DESCRIPTION");
sheet.Cells[rowCount + offfset, 1].SetStyle(headerStyle);
var noOfColumnsToMerge = 8 ;
// create a Range for header and merge it
var headerRange = sheet.Cells.CreateRange(rowCount + offfset, 1, 1, noOfColumnsToMerge);
int indexValue = 5;
dataStyle.IsTextWrapped = true;
dataStyle.HorizontalAlignment = TextAlignmentType.Left;
//Adding Notes description table after controller specification table
foreach (NoteVO notation in notationList)
sheet.Cells[rowCount + indexValue, 0].PutValue(notation.notesId);
// sheet.Cells[rowCount + indexValue, 0].SetStyle(dataStyle);

sheet.Cells[rowCount + indexValue, 1].PutValue(notation.notesDescription);
// sheet.Cells[rowCount + indexValue, 1].SetStyle(dataStyle);

// create a Range for data and merge it
var range = sheet.Cells.CreateRange(rowCount + indexValue, 1, 1, noOfColumnsToMerge);
for (int colNo = 0; colNo <= noOfColumnsToMerge; colNo++)
sheet.Cells[rowCount + indexValue, colNo].SetStyle(dataStyle);
sheet.AutoFitRow(rowCount + indexValue, 1, noOfColumnsToMerge);

var options = new AutoFitterOptions { AutoFitMergedCells = true };
sheet.AutoFitRows(options); //here i m getting that error

please suggest me something


Thanks for the code segment.

Well, I cannot evaluate your code properly as there are some objects/pointers or variables for which I am not sure their values. We appreciate if you could create a sample console application (runnable), zip it and post it here to reproduce the issue on our end. We will check it to figure your issue out soon. Also, provide us the input file if you have any.

By the way, we recommend you to kindly try our latest fix/version: Aspose.Cells for .NET v7.4.0.1 and let us know if it makes any difference.

Thank you.