If you insert (copy and paste) a range in excel, you get the option to shift down the content below. There is no such option for Cell.PutValue().
Instead i’m using InsertRange below the field, where i want to put the value.
If there is a Table below the cell where i want to insert the range, excel tells me this is not possible as it would break the table.
In Aspose, it just happens (and the table breaks).
I know, you aren’t ot supposed to insert a range above a table, but how can i check if this is allowed without looping over all the tables and comparing their area manually (which is expensive when you do this often).
Will this throw an exception in 23.3? What is the best way to prevent this?
I need to insert ranges before i write values, so i can shift down content, but i don’t want situations like this to break the entire excel file.
Cells cells = workbook.Worksheets[0].Cells;
// Add a table
ListObjectCollection listObjects = workbook.Worksheets[0].ListObjects;
listObjects.Add(20, 2, 25, 7, true);
// Write values above the table, which would overwrite everything in the table
int[] myValueArray = new int[] { 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 };
cells.ImportArray(myValueArray, 15, 3, true);
// so let's insert a range first
CellArea cellArea;
cellArea.StartRow = 16;
cellArea.EndRow = cellArea.StartRow + myValueArray.Count();
cellArea.StartColumn = 3;
cellArea.EndColumn = cellArea.StartColumn;
// Result: Table is broken and excel file reports an error when opening it.
cells.InsertRange(cellArea, ShiftType.Down);