问题
I have logic in an Excel macro that parses the documents and hides rows that don't have data in certain cells per row. Looking to export only the visible cells to CSV. I have code (below) to export everything, but how do I make it only do visible rows?
$oWorksheet = $objExcel.Worksheets.item(6)
$oWorksheet.Activate()
"saving $filecsv"
$oWorksheet.SaveAs($filecsv,[Microsoft.Office.Interop.Excel.XlFileFormat]::xlCSVWindows)
$workbook.Saved = $true
回答1:
Please see this answer I believe you could copy only the visible rows by using the following:
$max = $sheet.UsedRange.Rows.Count
for ($i=2; $i -le $max; $i++)
{
$row = $sheet.Cells.Item($i,1).EntireRow
if ($row.hidden -eq $false)
{
## append the row to new csv file
}
}
来源:https://stackoverflow.com/questions/39897199/export-only-visible-rows-to-csv-with-powershell