vb.net - How to use the column number to reference an Excel column instead of the column letter -
the following code works:
imports microsoft.office.interop dim xlapp new excel.application xlapp.visible = true dim wb1 excel.workbook wb1 = xlapp.workbooks.open("c:\book1.xlsx") dim ws1 excel.worksheet ws1 = ctype(wb1.sheets(1), excel.worksheet) ws1 ctype(.columns("k:xfd"), excel.range).numberformat = "general" end
i want use column number instead of column letter.
this tried doesn't work:
with ws1 ctype((.columns(11), .columns(.columns.count)), excel.range)).numberformat = "general" end
in general, can use integer. should access range
property, passing 2 cell
references.
dim a, b, c, d integer ws1 .range(.cells(a, b), .cells(c, d)).numberformat = "general" end
where
here specific solution
with ws1 dim a, b, c, d integer = 1 ' row 1 b = 11 ' column k c = .rows.count ' last row d = .columns.count ' last column .range(.cells(a, b), .cells(c, d)).numberformat = "general" end
and since range
takes objects, pass both integer indices , strings cells
. may helpful in future.
with ws1 dim a, b, c, d object = 1 ' row 1 b = "k" ' column k c = .rows.count d = .columns.count .range(.cells(a, b), .cells(c, d)).numberformat = "general" end
Comments
Post a Comment