复制和使用win32com&粘贴隔离Python [英] copy & paste isolation with win32com & python

查看:194
本文介绍了复制和使用win32com&粘贴隔离Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种使用python和win32com复制和粘贴的方法,以便python脚本可以在后台运行并且不会弄乱用户"的复制和粘贴功能?

Is there a way of using python and win32com to copy and paste such that python scripts can run in the background and not mess up the "users" copy and paste ability?

from win32com.client import Dispatch
import win32com.client

xlApp = Dispatch("Excel.Application")
xlWb = xlApp.Workbooks.Open(filename_xls)
ws = xlWb.Worksheets(1)
xlApp.Visible=False

ws.Range('a1:k%s' % row).select
ws.Range('a1:k%s' % row).cut
ws.Range('a7').select
ws.paste

假设脚本将在大量数据集上连续运行...

assume that the script will be running continuously on a large collection of datasets...

好了,这个问题更清晰了,我需要所有格式,因此,仅获取t值当然很简单,但并不一定就是所需要的.

Ok, some more clarity to the question, I need the formating, all of it, so just grabbing t values is of course simple, but not exactly what is needed.

因此,让我将问题表达为: 为什么没有选择,复制和粘贴例程就可以在python中同时获取值和Excel格式?

So then let me phrase the question as: What is there a why to grab both the value and its excel formating in python without the select, copy, and paste routine?

推荐答案

而不是:

ws.Range('a1:k%s' % row).select
ws.Range('a1:k%s' % row).cut
ws.Range('a7').select
ws.paste

我做到了:

ws.Range("A1:K5").Copy(ws.Range("A7:K11"))

根据 MSDN:Excel对象模型参考

这篇关于复制和使用win32com&粘贴隔离Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆