2

I have an issue with my ExcelLibrary proof of concept. When I try to save some data into new Excel file it returns an error UnboundLocalError: local variable 'my_sheet_index' referenced before assignment on Put Number To Cell sheetname=${mySheetName} column=1 row=1 value=90

Do you know what can I do to prevent getting that please? Here is my easy test file:

*** Settings ***
Library             ExcelLibrary
Library             Collections

*** Variables ***
${Excel_File_Path}   C:\\Python27\\ExcelRobotTest\\
${mySheetName}         UserImport

*** Test Cases ***
Excel Test
    Lubos Test

*** Keywords ***
Lubos Test
    Create Excel Workbook    newsheetname=${mySheetName}
    Put Number To Cell   sheetname=${mySheetName}    column=1    row=1    value=90
    Save Excel Current Directory    filename=MyNewExcel.xls
2
  • Ive managed to get around that error UnboundLocalError: local variable 'my_sheet_index' referenced before assignment but Im now stumped with a IndexError: list index out of range when adding a number... I can give you my current code if you like to get around the first error but Im still trying to get around this second issue :( Commented Mar 28, 2017 at 13:47
  • Feel free to share @Goralight Commented Mar 28, 2017 at 13:49

1 Answer 1

2
*** Settings ***
Library             ExcelLibrary

*** Variables ***
${Path}   C:\\Python27\\ExcelRobotTest\\
${name}    Test.xls

*** Test Cases ***
Excel Test
    Create

*** Keywords ***
Create
    Create Excel Workbook    ${name}
    Open Excel    ${path}${name}
    Put String To Cell    ${name}    1    1    90
    Save Excel        ${Path}${name}

This gets around your first error

UnboundLocalError: local variable 'my_sheet_index' referenced before assignment

I used Put Number To Cell and this caused a

IndexError: list index out of range

So I used Put String To Cell and this now causes a

IOError: [Errno 13] Permission denied: u'C:\Python27\ExcelRobotTest\Test.xls'

So I think the current code I've posted is your best shot as my work computer as some funny policies stopping me from saving / changing files through Robot... But I am truly stumped :( Ill update more if I manage to get around this issue.

Considering it's complaining about perms - it must have done the writing but cant save.

EDIT1: After switching policy quickly it's now throwing a

IOError: [Errno 22] invalid mode ('w+b') or filename: u'C:\Python27\ExcelRobotTest\Test.xls'

I have no idea what this is...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.