简体   繁体   English

xlwt无法写入xls文件?

[英]xlwt can't write to xls file?

Been following a guide to write to xls files and the exmaple used was the following: 遵循写xls文件的指南,使用的示例如下:

wb = xlwt.Workbook()
newsheet=wb.add_sheet('sheet1')
newsheet.write('0','0','testing')
wb.save(testing.xls)

However I get an error saying: 但是我收到一条错误消息:

ValueError: row index was '0', not allowed by .xls format ValueError:行索引为“ 0”,。xls格式不允许

This may be a really stupid question (but as guides show this as "valid" does anyone know whats causing this? 这可能是一个非常愚蠢的问题(但根据指南,这显示为“有效”,有人知道是什么原因造成的吗?

The first two arguments of the write() method have to be row and column numbers, not strings: write()方法的前两个参数必须是行号和列号,而不是字符串:

newsheet.write(0, 0, 'testing')

FYI, here is the write() method docstring : 仅供参考,这是write()方法docstring

def write(self, r, c, label="", style=Style.default_style):
    """
    This method is used to write a cell to a :class:`Worksheet`.

    :param r:

       The zero-relative number of the row in the worksheet to which
       the cell should be written.

    :param c:

       The zero-relative number of the column in the worksheet to which
       the cell should be written.

     ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM