带有Excel库错误的Robot框架:“赋值前引用了本地变量‘my_sheet_index’”

2024-09-27 19:32:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我的ExcelLibrary概念证明有问题。当我试图将一些数据保存到新的Excel文件中时,它在Put Number To Cell sheetname=${mySheetName} column=1 row=1 value=90上返回一个错误UnboundLocalError: local variable 'my_sheet_index' referenced before assignment

你知道我能做些什么来阻止我得到那个吗?这是我的简易测试文件:

*** 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

Tags: 文件totestnumberputvaluelibrarycell
1条回答
网友
1楼 · 发布于 2024-09-27 19:32:09
*** 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}

这样可以避免你的第一个错误

UnboundLocalError: local variable 'my_sheet_index' referenced before assignment

我使用了Put Number To Cell,这导致了

IndexError: list index out of range

所以我使用了Put String To Cell,这会导致

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

所以我认为我发布的当前代码是你作为我的工作电脑的最佳选择,因为一些有趣的政策阻止我通过机器人保存/更改文件。。。但我真的很为难:(如果我设法避开这个问题,我会更新更多的信息。在

考虑到它在抱怨烫发——它一定是写完了,但却不能存钱。在

编辑1:在迅速改变政策后,它现在正在抛出一个

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

我不知道这是什么。。。在

相关问题 更多 >

    热门问题