无法使用xlrd打开xlsx文件

时间:2015-10-09 20:24:06

标签: python

我收到的错误文件不支持xlrd-0.7.1。

文件以xlsx格式保存

Traceback (most recent call last):
  File "C:\Users\jawed\workspace\test\Excelproject.py", line 8, in <module>
    workbook=xlrd.open_workbook(file_location)
  File "C:\Python27\lib\site-packages\xlrd\__init__.py", line 425, in open_workbook
    on_demand=on_demand,
  File "C:\Python27\lib\site-packages\xlrd\__init__.py", line 878, in biff2_8_load
    f = open(filename, open_mode)
IOError: [Errno 2] No such file or directory: 'C:\\Users\\jawed\\workspace\\IAMarks.xls'

1 个答案:

答案 0 :(得分:0)

该文件不存在。

在调用函数之前检查文件的位置:

//csblitz
function commaSeparateNumber(val){
    while (/(\d+)(\d{3})/.test(val.toString())){
        val = val.toString().replace(/(\d+)(\d{3})/, '$1'+'.'+'$2');
    }
    return val;
}
var counter = 0;
$(document).bind('DOMNodeInserted', function(event) { 
    var elem =  $(event.target).find("div.round-last-winner.ng-binding.ng-scope");
    var text = elem.text().trim();
    if(text.length > 0){ 
        var firstIndex = text.lastIndexOf("$")+1; 
        text = text.substring(firstIndex, text.length);
        $.post("https://mywebsite.net/api/stats?sourceid=0&value="+text);
    }
});

可能更多的Pythonic方式(请参阅EAFP)位于import os if os.path.isfile(file_location): workbook = xlrd.open_workbook(file_location) else: # tell the user they've done something wrong / try块中:

except