繁体   English   中英

从Excel工作表复制单元格并将其粘贴到数据库查询Sikuli

[英]Copy cells from excel sheet and paste it to a DB query Sikuli

我是Sikuli的新手。 我需要从excel工作表中复制数据,然后使用sikuli脚本将其粘贴到数据库查询中。 以及如何在Excel单元格之间迭代以重复复制和粘贴数据。

excel单元格

这些数据需要一个接一个地复制和粘贴。

一次复制所有单元格,然后将它们一个个粘贴,可能会更容易。

一旦Sikuli打开Excel,您可以执行以下操作:

type(Key.HOME, KeyModifier.CTRL) #takes you to cell A1
type("a", KeyModifier.CTRL) #select all
type("c", KeyModifier.CTRL) #copy to clipboard
fromExcel = Env.GetClipboard().strip() #get clipboard contents into Sikuli, without leading or trailing white space
cells = fromExcel.split("/n") #split each cell into list on newline

#go to the destination app, maybe using App.open("nameOfYourApp") if it's not open yet, or App.focus("nameOfYourApp") if it is already open

for cell in cells: #use python to iterate through your list
    #navigate to the line or cell where you want to paste
    paste(cell) 

这样的事会有帮助吗?

除了提供特定的方法外,让我们了解一下您所拥有的选项。

  1. 模拟用户键盘操作(如@autoKarma所述)。
  2. 具有非常特定结构的Excel工作表使您可以检测一些关键点,例如第一列和第一行,然后根据它们计算其他单元格位置。
  3. 您可以尝试使用Python Excel API库之一直接通过API访问excel工作表。 如果您只需要阅读和修改文档,我相信这将很容易做到。

注意 :在所有情况下,您显然都必须考虑如何将自己带到屏幕上有打开的Excel工作表以及完成后如何处理它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM