'How to crop a worksheet to used range with openpyxl? [closed]

I used openpyxl to delete some columns and rows from my original small excel worksheet, and save the result to a new .xlsx file, which is about 200KB. I cropped the result sheet to fit its used range (Tip2 here: https://www.upslide.net/en/reduce-excel-file-size/), and the file size was reduced to around 10KB.

I tried to use openpyxl to do the same thing, but failed to reduce the file size.

How can I crop the worksheet? It's it possible to do it with openpyxl or other packages?

I think this function is really useful when handling large sheet.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source