There is a module called openpyxl.
It allows you to read and write Excel in Python. For the time being, I used this module to read an existing Excel file.
In addition, it seems that some people are writing articles on Qiita about how to create an Excel file using openpyxl. If you are interested, please go there.
> easy_install openpyxl
import openpyxl
book = openpyxl.load_workbook(filename)
sheet = book.active #Get the active sheet object
print(sheet.cell("A1").value)
for row in sheet.rows:
for cell in row:
print(cell.value, end=" ")
print("")
It can not be used.
When I read the document, it seems that I can create a table, but I can only operate the table created there.
** It seems to be the bottom right cell where the value is written **.
It is not possible to know from openpyxl whether a cell is row / column merged **.
However, when row / column merge is performed, all values of the merged cells other than the upper left cell will be None. So, isn't it possible to guess the value set in the cell based on that?
For example, if you have the following column ...
for row in sheet.rows:
for cell in row:
print(cell.value, end=" ")
print("")
When you run, the output looks like this:
A 1 2
B 3 None
None 5 6
C 7 8
None 9 0
It will be a form of guessing what was written in the merged cell from this point.
Recommended Posts