Python教程

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

这篇关于excel python 保持格式复制粘贴 Excel.Application的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!