I want to do the moral equivalent of the following VBA code:
For Each col In Worksheets('Sheet1').Columns # do stuff Next col
I have generated MFC wrappers for the Excel type library that get me this far (the generated types all derive from COleDispatchDriver:
CApplication app; app.CreateDispatch( clsid, e ); CWorkbooks wbks( app.get_Workbooks() ); CWorkbook book( wbks.Open( filename, /* optional args */ ) ); CRange cols( app.get_Columns() ); long numCols = cols.get_Count();
and from there I’m stuck. It looks like I can sort of iterate over cells using Range::get_Item( rowid, colid ), and then get the column from the cell, but I was looking for a more direct translation of the above loop.
(EDIT) Clarification: I don’t actually care about the individual cells. My goal is to determine which columns have width 0 (are hidden) and delete them from the worksheet.
I assume that you’re trying to traverse all the cells in the spreadsheet. You can get the active worksheet’s ‘all cells’ range, and loop through its rows and columns :
EDIT: In response to OP clarification:
This will probably do what you’re looking for: