# powershell extract data from excel range



## nomad (Sep 30, 1999)

I am building some powershell script to get data from an excel spread sheet and i have 2 named ranges, "DATA BEGIN", which is just one cell (A8) and "DATA END", which is also just one cell in column A but it floats depending on how many rows i have after "DATA BEGIN" in my spread sheet. So what i would like to do in powershell is extract the data from all the rows between "DATA BEGIN" and "DATA END" in 3 columns and write to my output pane. this is what i have so far... can anyone help?

cls
$file = "C:\Users\tertom01\Desktop\Temp\test.xlsx" 
$sheetName = "Sheet1" 
$objExcel = New-Object -ComObject Excel.Application
$workbook = $objExcel.Workbooks.Open($file)
$sheet = $workbook.Worksheets.Item($sheetName)
$objExcel.Visible=$false 
$rowMax = ($sheet.UsedRange.Rows).count 
$rowName,$colName = 10,2
$rowAge,$colAge = 10,3 
$rowCity,$colCity = 10,4
for ($i=1; $i -le $rowMax-1; $i++)
{
$name = $sheet.Cells.Item($rowName+$i,$colName).text
$age = $sheet.Cells.Item($rowAge+$i,$colAge).text
$city = $sheet.Cells.Item($rowCity+$i,$colCity).text
}
$objExcel.quit()


----------

