excel python 保持格式复制粘贴 Excel.Application

import pyrfc, json
import tablib
from datetime import datetime
import win32com.client, os, shutil, time
xl = win32com.client.Dispatch("Excel.Application")

file = r'D:\code\maria_po_transfer\t2\dn_template.xls'

xl.DisplayAlerts = False
xl.Visible = True
wb = xl.Workbooks.Open(file)
sheets = wb.Worksheets('P1')

sheets.Rows('1:46').Copy()

sheets.Rows('139:139').Select()
sheets.Paste()
sheets.Rows('159:159').Select()
sheets.Paste()


# 这些是VBA录屏代码
# Rows("1:1").Select
#
# Rows("1:46").Select
# Selection.Copy
#
# Rows("139:139").Select
# ActiveSheet.Paste

参考
https://github.com/pythonexcels/examples

https://pythonexcels.com/python/2009/10/12/mapping-excel-vb-macros-to-python

https://pythonexcels.com/python/2009/10/05/python-excel-mini-cookbook

上一篇:npoi 已删除的功能: /xl/styles.xml 部分的 格式 (样式)


下一篇:运用逻辑运算符查询