Hi,
Well, Cells.MaxColumn and Cells.MaxRow provide the maximum/farthest column/row indexes which contain value or data. For your info, when the line i.e.., wrksht.Cells.DeleteColumn(i); is processed all the columns are shifted on level to left (this is same with MS Excel), it might possible that valid column indexes are not retrieved (to either delete the column or set column caption by the value string accordingly) fine, so, there is a possibility the resultant matrix won't be ok as you thought.
I think you may try to modify the loop (higher to lower value) a bit to check if it works fine for your scenario, I have tested and it works fine for a simple case, e.g.,
WebWorksheet wrksht = grdWeb.WebWorksheets[grdWeb.ActiveSheetIndex];
wrksht.SetReadonlyRange(0, 0, wrksht.Cells.MaxRow + 1, 1);
int colcount = wrksht.Cells.MaxColumn;
int rowcount = wrksht.Cells.MaxRow;
WebCell cell;
for (int i = colcount; i >= 0; i--)
{
cell = wrksht.Cells[0, i];
if (cell.StringValue != "")
{
wrksht.Cells.SetColumnCaption(i, cell.StringValue);
}
else
{
wrksht.Cells.DeleteColumn(i);
}
}
Thank you.
Amjad Sahi
Support Developer,
Aspose Sialkot Team
Contact Us