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

Free Support Forum - aspose.com

Delete Columns

We have a Excel Template with several columns. We want to delete now differently columns. Is there a possibility by API Columns to delete?

Thanks for you timely help in this matter.
Hans

Dear Hans,

Currently this feature is not supported.

You can try an alternative solution: set the column width to 0. So this column is hidden. And you can put null value to cell which you want to delete.

Dear Laurence,

thank you for the fast answer. With set the column width to 0 works it well.
How can I set the cell value to Null?

Regards
Hans

Dear Hans,

You can try the following sample code:

Cells cells = excel.Worksheets[0].Cells;
cells[“B2”].PutValue(null);

So in Cell “B2”, the data you set in designer file is cleared.

@hsh,
We have supported this feature now and you can use following example where WorkSheet.Cells.DeleteColumn() is used to delete a column at a particular index.

// Instantiating a Workbook object
Workbook workbook = new Workbook("sample.xlsx");

// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[0];

// Deleting a column from the worksheet at 2nd position
worksheet.Cells.DeleteColumn(4);

// Saving the modified Excel file
workbook.Save(dataDir + "output.xlsx");

Following article contains detailed information about working with Rows and Columns:
Inserting and Deleting Rows and Columns

Download the latest version of Aspose.Cells for .NET from the following link:
Aspose.Cells for .NET (Latest Version)

You can download the latest demos here.