编程语言
首页 > 编程语言> > excel python 保持格式复制粘贴 Excel.Application

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

标签:Rows,xl,python,excel,Application,sheets,139,Select
来源: https://blog.csdn.net/nongcunqq/article/details/121638185