sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #58448
Re: [Question #187149]: How to write in existing Excel Sheet
Question #187149 on SikuliX changed:
https://answers.launchpad.net/sikuli/+question/187149
hcuthbert posted a new comment:
Example 1 -- workbook is already created, column has been added to the
worksheet where cell data is added. Data has been added to the
clipboard (Ctrl &C -- copy)
def CB_Write():
#The function which is used to copy from the clipboard
Env.getClipboard()
#create a variable to use for the clipboard item
cb = Env.getClipboard()
#open the workbook
rb = xlrd.open_workbook(""C:\\SikuliX\\....\\Sample.xls")
#copy the workbook to make it writeable
wb = copy(rb)
#write to the sheet and column
#first number represents the row
#second number represents the column
#cb -- represent the write info from the clipboard
sheet = wb.get_sheet(2).write(1,0,cb)
#save the workbook
wb.save("C:\\SikuliX\\....\\Sample.xls")
CB_Write()
----------------------------------------------------------------------------------------------
Example2 -- this example overlays the workbook
def ExcWr():
#The function which is used to copy from the clipboard
Env.getClipboard()
#create a variable to use for the clipboard item and any other data needed
cb = Env.getClipboard()
cb1 = "Easy"
cb2 = "Peasy2"
#open the workbook
rb = xlrd.open_workbook("C:\\SikuliX\\...\\SikuliWrite.xls")
#copy the workbook to make it writeable
wb = copy(rb)
#specify the correct encoding of the workbook
book = xlwt.Workbook(encoding="utf-8")
#specify the sheetname
sheet1 = book.add_sheet("MySheet1")
#write the column names
#0,0 = A1
#0,1 = A2
#0,2 = A3
sheet1.write(0, 0, "Test1")
sheet1.write(0, 1, "Test2")
sheet1.write(0, 2, "Test3")
#write the row data
#1,0 = B1
#1,1 = B2
#1,2 = B3
sheet1.write(1, 0, cb)
sheet1.write(1, 1, cb1)
sheet1.write(1, 2, cb2)
book.save("C:\\SikuliX\\...\\SikuliWrite.xls")
ExcWr()
hope this helps those out there trying to write to Excel
--
You received this question notification because your team Sikuli Drivers
is an answer contact for SikuliX.