Export only visible rows to CSV with Powershell

拥有回忆 提交于 2021-01-29 04:16:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!