Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I know i have another options to delete the column but ,how we can fix these kind of error?



object does not contain definition for delete in excel interop 'object

xlWorksheetNew.Columns["P:Q"].Delete();

object does not contain definition for delete in excel interop 'object'

What I have tried:

i have tried :   (Excel.Range)xlWorksheetNew.Columns["P:Q"].Delete();  But its not working.Can any one help ?
Posted
Updated 31-Aug-21 17:21pm
v2
Comments
j snooze 31-Aug-21 17:29pm    
I'm not too familiar with excel interop, however it appears there is no Delete function for a columns collection. I wonder if the single column object can be deleted so get your collection of columns using xlWorksheetNew.Columns["P:Q"] and maybe do a for each column in that columns collection? Worth a try if the above code you supplied is not working.

1 solution

One thing is to re-check the type of xlWorksheetNew is it correctly defined.

Another thing is that if you want to cast the columns before Delete is called, you need to apply parenthesis. In other words
C#
((Excel.Range)xlWorksheetNew.Columns["P:Q"]).Delete();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900