简体   繁体   English

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

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

I am new to Sikuli. 我是Sikuli的新手。 I need to copy data from excel sheets and paste them to a DB query using sikuli script. 我需要从excel工作表中复制数据,然后使用sikuli脚本将其粘贴到数据库查询中。 And how can I iterate among the excel cells to copy and paste the data repeatedly. 以及如何在Excel单元格之间迭代以重复复制和粘贴数据。

excel单元格

These data needs to copied and pasted one after the other. 这些数据需要一个接一个地复制和粘贴。

It might be easier to copy all of the cells at once, then paste them one by one. 一次复制所有单元格,然后将它们一个个粘贴,可能会更容易。

once Sikuli has opened Excel, you could do something like: 一旦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) 

Would something like that be of help? 这样的事会有帮助吗?

Rather than providing a specific approach let's understand the options you have. 除了提供特定的方法外,让我们了解一下您所拥有的选项。

  1. Simulate user keyboard actions (like it is described here by @autoKarma). 模拟用户键盘操作(如@autoKarma所述)。
  2. Excel sheet having a very specific structure allows you to detect some key points like first column and first row and then calculate other cells locations based on them. 具有非常特定结构的Excel工作表使您可以检测一些关键点,例如第一列和第一行,然后根据它们计算其他单元格位置。
  3. You can try and use one of the Python Excel API libraries to access the excel sheet directly via API. 您可以尝试使用Python Excel API库之一直接通过API访问excel工作表。 If you only need to read the document and to to amend it, I believe this will be fairly easy to do. 如果您只需要阅读和修改文档,我相信这将很容易做到。

Note : In all cases you will obviously have to think of how do you bring yourself to the point where you have an open Excel sheet on your screen and how to dispose of it when done. 注意 :在所有情况下,您显然都必须考虑如何将自己带到屏幕上有打开的Excel工作表以及完成后如何处理它。

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

相关问题 Excel可以将某些单元格从一张纸复制/粘贴到另一张纸上,但要稍加改动 - Excel to copy / paste some cells from one sheet to another but with a twist 从过滤表复制/粘贴可见单元格 - Copy/Paste Visible Cells from Filtered sheet C#:从Excel工作表复制单元格范围并粘贴到HTML电子邮件正文中 - C#: copy range of cells from excel sheet and paste in HTML email body Excel VBA如何将单元格的一部分复制并粘贴到新制作的工作表中 - Excel VBA How to copy and paste a section of cells into a newly made sheet 将非空白单元格从 sheet1 复制并粘贴到 sheet2 - Copy and paste nonblank cells from sheet1 to sheet2 Python / Pandas从Excel工作表复制和粘贴 - Python/Pandas copy and paste from excel sheet excel VB 将单元格从工作表复制到另一个 - excel VB copy cells from on sheet to another 将单元格值从Excel工作表复制到数组中 - Copy Cells values from Excel sheet into an array 如何根据工作表2中单元格的值从工作表1中复制特定单元格并将其粘贴到工作表2的相应行中? - How do I copy specific cells from sheet 1 and paste into corresponding rows of sheet 2 , based on values of cells in sheet 2? Excel“如果>复制>插入1行>粘贴>仅值(从一张纸到另一张纸)” - Excel “if > copy > insert 1 line > paste > only values (from sheet to sheet)”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM