win32com 模拟在 Excel 中执行 Select 两次

win32com Analog to Performing Select All Twice in Excel

在 win32com 中,

cells = worksheet.UsedRange

类似于在Excel中按一次ctrl-a。

win32com相当于按两次ctrl-a是什么?

The use case is when you use the format painter after pressing cntl-a twice it will paste all the formatting including the column width.

我不建议这样做。 Worksheet.UsedRange property as Excel sees it could easily becomes the entire worksheet (1048576 rows × 16384 columns). The Range.PasteSpecial method has options for pasting formatting as well as column widths (e.g. xlPasteColumnWidths)那个比较合适。

在原生 Excel 中使用较新的工作表,旧的流氓 xlCellTypeLastCell property 已基本消除,但在处理跨平台编码时仍然需要注意。