Robot framework split string and put in to sheet excel

筅森魡賤 提交于 2019-12-13 01:50:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!