简体   繁体   中英

xlwt can't write to xls file?

Been following a guide to write to xls files and the exmaple used was the following:

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

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:

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

FYI, here is the write() method 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.

     ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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