We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

InserColumn to empty Worksheet

I have an issue concerning IWorksheet.InsertColumn method.

When I use it on a non-empty Worksheet (for example filled by ImportDataView, it works just fine.

However, when I try to create a Worksheet from scratch, it does not seem to work as I expect it to.


ExcelEngine eng = new ExcelEngine();
IApplication app = eng.Excel;
app.DefaultVersion = ExcelVersion.Excel97to2003;
IWorkbook workbook = app.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
sheet.InsertColumn(1);


If I use InsertColumn(0), I get an exception "Value cannot be less 1 and greater than max column index".

If I use InsertColumn(1), I don't seem to get any result (the number of columns is still 0 afterwards).

What am I doing wrong?

1 Reply

GM Geetha M Syncfusion Team August 5, 2009 11:51 AM UTC

Hi Jakub,

Thank you for your interest in Syncfusion products.

InsertColumn is designed to work if the column index falls within the UsedRange of the sheet. In other words, a new column can be inserted only within the UsedRange, otherwise, a new cell must be added. This is why the existing sheet works and a new worksheet created from scratch does not show any effect. Also, the InsertColumn method takes input in one based index, and hence to insert a column at "A", you must use sheet.InsertColumn(1);

Please try this and let me know if you have any questions.

Regards,
Geetha

Loader.
Live Chat Icon For mobile
Up arrow icon