title: How do I reduce CSV file size?
body: <p>I have a PowerShell script that converts an .xlsx file (21.1MB) to a CSV file (16.5MB). When I open the .csv file that was created and press save, a dialog box pops up that says <em>"Some features in your workbook might be lost if you save it as a CSV. Do you want to keep using that format?"</em>, I press yes and the CSV file that was 16500KB shrinks to  58KB. I know that it must be deleting a lot of formatting in the file to do that, but I don't know how in PowerShell to replicate that reduction in file size. I have googled a lot but haven't found anything of use.</p>
  
  <pre><code>$files = Get-ChildItem C:\Users\user\Desktop\id.xlsx
  $Excel = New-Object -ComObject Excel.Application
  $Excel.Visible = $false
  $Excel.DisplayAlerts = $false
  
  foreach ($file in $files) {
      $WorkBook = $Excel.Workbooks.Open($file.Fullname)
      $sheet = $workbook.Sheets.Item(1) # Activate the first worksheet
      [void]$sheet.Cells.Item(1, 1).EntireRow.Delete() # Delete the first row
      [void]$sheet.Cells.Item(1, 1).EntireColumn.Delete()      # Delete the first column
  
      #delete the next 31 rows
      for ($i=1;$i -le 32;$i++) {
          [void]$sheet.Cells.Item(1, 4).EntireColumn.Delete()
      }
      $NewFilePath = [System.IO.Path]::ChangeExtension($file.Fullname,".csv")
      $Workbook.SaveAs($NewFilepath, 6)   # CSV
  }
  
  # cleanup
  $Excel.Quit()
  [System.Runtime.Interopservices.Marshal]::ReleaseComObject($WorkBook) | Out-Null
  [System.Runtime.Interopservices.Marshal]::ReleaseComObject($Excel) | Out-Null
  [System.GC]::Collect()
  [System.GC]::WaitForPendingFinalizers()
  </code></pre>