Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Need a quick way to delete a large amount of empty rows in xlsx file

$
0
0

Hi everyone, I need a function that will allow me to quickly clean up the empty rows in an xlsx. I currently have a function that does the job, but does so incredibly slowly considering there are over 1Mil empty rows, compared to about 8k rows of actual data. Any help with this issue would be greatly appreciated. I've included the current bit of code for reference.

#Counts rows in
$sheetRange = $sheet.UsedRange
$sheetrowCount = $sheetRange.Rows.Count

#Cleanup Empty Rows
$max = $sheet.UsedRange.Rows.Count
for ($i = $max; $i -ge 6; $i--) {
    if ($sheet.Cells.Item($i, 1).Text -eq '') {
        $heetRange = $sheet.Rows.Item($i).Delete()
    }
}



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>