Below the script read the sheet names of the Excel document.
How could I improve it so that it can extract the entire contents of column B (starting from row 5, so that row 1-4 is ignored) on each sheet and create an object?
eg. if column B on sheet 1 (called London) has the following meanings:
Marleybone
Paddington
Victoria
Hammersmith
and column C in sheet 2 (called) Nottingham has the following meanings:
Alverton
Annesley
Arnold
Askham
I want to create an object that looks like this:
City,Area
London,Marleybone
London,Paddington
London,Victoria
London,Hammersmith
Nottingham,Alverton
Nottingham,Annesley
Nottingham,Arnold
Nottingham,Askham
This is my code:
clear all
sheetname = @()
$excel=new-object -com excel.application
$wb=$excel.workbooks.open("c:\users\administrator\my_test.xls")
for ($i=1; $i -le $wb.sheets.count; $i++)
{
$sheetname+=$wb.Sheets.Item($i).Name;
}
$sheetname
source
share