简体   繁体   中英

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

I am new to Sikuli. I need to copy data from excel sheets and paste them to a DB query using sikuli script. And how can I iterate among the excel cells to copy and paste the data repeatedly.

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:

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).
  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.
  3. You can try and use one of the Python Excel API libraries to access the excel sheet directly via API. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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