Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Openpyxl - object has no attribute 'load_workbook'

I'm trying to load an existing workbook using openpyxl. But when I'm trying to run this code - I'm getting following error:

AttributeError: 'module' object has no attribute 'load_workbook'

import openpyxl works fine, what I'm doing wrong?

like image 471
Djent Avatar asked Oct 21 '12 17:10

Djent


People also ask

How to create a workbook in openpyxl?

Create a workbook ¶ There is no need to create a file on the filesystem to get started with openpyxl. Just import the Workbook class and start work: >>> from openpyxl import Workbook >>> wb = Workbook()

How to open an existing workbook in Python?

The same way as writing, you can use the openpyxl.load_workbook () to open an existing workbook:

How to save a workbook as a template in Python?

If you want to save the file to a stream, e.g. when using a web application such as Pyramid, Flask or Django then you can simply provide a NamedTemporaryFile (): You can specify the attribute template=True, to save a workbook as a template:


1 Answers

The examples are for a later version of openpyxl. In 1.1.4 the main __init__.py did not provide a shortcut to load_workbook in the form of

from openpyxl.reader.excel import load_workbook

so you will have to do that instead of:

from openpyxl import load_workbook

what is shown in the example.

like image 77
Anthon Avatar answered Sep 26 '22 23:09

Anthon