Are xlrd and xlwt compatible?

I am trying to create a book with python, and I need to check the values โ€‹โ€‹of different cells to fill it, but I have problems. I use xlrd and xlwt to create and edit an excel file.

I made a small example of my problem, and I do not understand why it does not work.

 import xlwt import xlrd wb = xlwt.Workbook() ws = wb.add_sheet('Test') ws.write(0,0,"ah") cell = ws.cell(0,0) # AttributeError: 'Worksheet' object has no attribute 'cell' print cell.value 

I took it for granted that xlrd and xlwt have common classes that can interact with each other, but that doesn't seem to be the case. How to get cell value for open Worksheet object?

+4
source share
1 answer

In my opinion, the xlwt and xlrd modules are separate and are used to read whole books into memory or write dates from memory to a file. If you want to use these two modules, I believe that you need to do something like:

1) Read the existing file in memory. (Xlrd) 2) Edit the book in memory 3) Write the book. (Xlwt)

In other words, they DO NOT work interchangeably. What works this way, although it is another module called 'openpyxl', this module allows you to create objects and manipulate them at runtime in the form in which you are trying above.

Link: http://packages.python.org/openpyxl/

+2
source

Source: https://habr.com/ru/post/1435742/


All Articles