问题
I want to split Transaction ID:211444
, i want to get only value = '211444' and put it into sheet excel ?
anyone please help
回答1:
Use OperatingSystem.py and String.py libraries:
${string} = Convert to String Transaction ID:211444
${id} = Fetch From Right ${string} ID:
append to file ids.csv ID:${id}\n encoding=UTF-8
回答2:
This might be useful to you .
may sure you have xlsxwriter installed in your python packages . else do
pip install xlsxwriter
Below is robotfile content which will pass the alphanumeric string to a library written in python
sample.robot
*** Settings ***
#test.py is name of python file in which code to write in excel is written
Library test.py
*** Variables ***
#This is sample alphanumeric value passed to python function
${test} pankaj:12232
*** Test Cases ***
Test
value is
*** Keywords ***
value is
#excel_numeric is function written in python to remove strings and write to excel
excel_numeric ${test}
#log to console ${compare}
Python file test.py
import xlsxwriter
def excel_numeric(arg1):
import re
#this will only provide numeric value from strings
arg2=re.findall(r'\d+',arg1)
workbook = xlsxwriter.Workbook(r'D:\dummy.xlsx')
worksheet = workbook.add_worksheet()
for item in arg2:
print item
#write takes three arguments,row,column and value
worksheet.write(0,0,item)
workbook.close()
output :
12232 - Written in excelfile
Note Make sure you put robot and python file in same directory
来源:https://stackoverflow.com/questions/47469710/robot-framework-split-string-and-put-in-to-sheet-excel