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

Free Support Forum - aspose.com

Unable to remove more than one column at a time from a worksheet

In the attached workbook, there are two hidden columns - A and D. If I run the code below, which is attempting to delete both of those columns, column A gets deleted but column D is not. In fact, column D gets unhidden. If you switch the order of the removals (remove column A first), then column A gets deleted and nothing happens to column D - it remains hidden, but it also remains in the workbook. Is there a better way to remove the columns, perhaps?



The code I’m using is the following:



Dim Workbook = New Aspose.Cells.Workbook(SourceFile)



With Workbook.Worksheets(0)

’ Need to do this to get all the columns available for some reason.

For Index = .Cells.MinColumn To .Cells.MaxColumn

Dim Column = .Cells.Columns(Index)

Next



.Cells.Columns.RemoveAt(3)

.Cells.Columns.RemoveAt(0)

End With

Workbook.Save(DestFile)



Thanks for any help on this.



– Michael Whalen

Hi,


Well, I think you may try to use Cells.DeleteColumn method instead. Please see the sample updated code segment for your reference:
e.g
Sample code:


’ Need to do this to get all the columns available for some reason.

For Index = .Cells.MinColumn To .Cells.MaxColumn

Dim Column = .Cells.Columns(Index)

Next


.Cells.DeleteColumn(3)

.Cells.DeleteColumn(0)

End With



Thank you.

Fantastic - works like a charm. I’d missed that function. Thanks!

– Michael Whalen

Hi Michae Whalenl,


Good to know that your issue is revolved now. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.

Thank you.