Questions tagged [openpyxl]

Openpyxl is a Python library for reading and writing Excel 2010 xlsx/xlsm/xltx/xltm files.

Openpyxl is a Python library to read/write Excel 2010 xlsx, xlsm, xltx, and xltm files.

It was born from lack of an existing library to read/write natively from Python the Office Open XML format.

All kudos to the PHPExcel team as openpyxl was initially based on PHPExcel.

Features:

  1. Tables
  2. Data validation
  3. Charts

About security:

By default Openpyxl does not guard against quadratic blowup or billion laughs XML attacks. To guard against these attacks, install defusedxml.

Project documentation can be found at openpyxl - A Python library to read/write Excel 2010 xlsx/xlsm files.

5440 questions
278
votes
12 answers

Pandas: Looking up the list of sheets in an excel file

The new version of Pandas uses the following interface to load Excel files: read_excel('path_to_file.xls', 'Sheet1', index_col=None, na_values=['NA']) but what if I don't know the sheets that are available? For example, I am working with excel…
Amelio Vazquez-Reina
  • 91,494
  • 132
  • 359
  • 564
199
votes
20 answers

Is there a way to auto-adjust Excel column widths with pandas.ExcelWriter?

I am being asked to generate some Excel reports. I am currently using pandas quite heavily for my data, so naturally I would like to use the pandas.ExcelWriter method to generate these reports. However the fixed column widths are a problem. The…
badideas
  • 3,189
  • 3
  • 25
  • 26
165
votes
14 answers

How to save a new sheet in an existing excel file, using Pandas?

I want to use excel files to store data elaborated with python. My problem is that I can't add sheets to an existing excel file. Here I suggest a sample code to work with in order to reach this issue import pandas as pd import numpy as np path =…
Stefano Fedele
  • 6,877
  • 9
  • 29
  • 48
151
votes
20 answers

openpyxl - adjust column width size

I have following script which is converting a CSV file to an XLSX file, but my column size is very narrow. Each time I have to drag them with mouse to read data. Does anybody know how to set column width in openpyxl? Here is the code I am…
Satish
  • 16,544
  • 29
  • 93
  • 149
138
votes
10 answers

How can I use openpyxl to read an Excel cell value and not the formula computing it?

I am using openpyxl to read a cell value (excel addin-webservice updated this column). I have used data_only = True but it is not showing the current cell value, instead it is the value stored the last time Excel read the sheet. wbFile =…
user3411047
  • 1,425
  • 2
  • 9
  • 14
130
votes
3 answers

Save list of DataFrames to multisheet Excel spreadsheet

How can I export a list of DataFrames into one Excel spreadsheet? The docs for to_excel state: Notes If passing an existing ExcelWriter object, then the sheet will be added to the existing workbook. This can be used to save different …
Andy Hayden
  • 359,921
  • 101
  • 625
  • 535
91
votes
11 answers

No module named 'openpyxl' - Python 3.4 - Ubuntu

I installed openpyxl with $ pip install openpyxl when I try the command from openpyxl import Workbook I get Traceback (most recent call last): File "", line 1, in from openpyxl import Workbook ImportError: No module named…
FrancescoVe
  • 1,060
  • 1
  • 7
  • 12
83
votes
4 answers

Get sheet by name using openpyxl

I am writing some data into an Excel file, but I don’t know how to adjust the code in order to be able to control which sheet I am writing into: from openpyxl import load_workbook wb = load_workbook(filename) active_ws = wb.active Instead of…
horace_vr
  • 3,026
  • 6
  • 26
  • 48
78
votes
6 answers

getting sheet names from openpyxl

I have a moderately large xlsx file (around 14 MB) and OpenOffice hangs trying to open it. I was trying to use openpyxl to read the content, following this tutorial. The code snippet is as follows: from openpyxl import load_workbook wb =…
rivu
  • 2,004
  • 2
  • 29
  • 45
76
votes
8 answers

Fill cells with colors using openpyxl?

I am currently using openpyxl v2.2.2 for Python 2.7 and i wanted to set colors to cells. I have used the following imports import openpyxl, from openpyxl import Workbook from openpyxl.styles import Color, PatternFill, Font, Border from…
Ahmed Rashad
  • 763
  • 1
  • 5
  • 5
72
votes
6 answers

Is it possible to get an Excel document's row count without loading the entire document into memory?

I'm working on an application that processes huge Excel 2007 files, and I'm using OpenPyXL to do it. OpenPyXL has two different methods of reading an Excel file - one "normal" method where the entire document is loaded into memory at once, and one…
Hubro
  • 56,214
  • 69
  • 228
  • 381
65
votes
6 answers

How to access the real value of a cell using the openpyxl module for python

I am having real trouble with this, since the cell.value function returns the formula used for the cell, and I need to extract the result Excel provides after operating. Thank you. Ok, I think I ahve found a way around it; apparently to access…
user3455972
  • 651
  • 1
  • 5
  • 4
61
votes
9 answers

getting the row and column numbers from coordinate value in openpyxl

I'm trying to covert a coordinate value in excel to a row number and column number in openpyxl. For example if my cell coordinate is D4 I want to find the corresponding row and column numbers to use for future operations, in the case row = 3, column…
A Alstone
  • 1,087
  • 2
  • 10
  • 12
60
votes
8 answers

iterate through all rows in specific column openpyxl

I cannot figure out how to iterate through all rows in a specified column with openpyxl. I want to print all of the cell values for all rows in column "C" Right now I have: from openpyxl import workbook path = 'C:/workbook.xlsx' wb =…
Daniel Dahms
  • 909
  • 2
  • 8
  • 8
49
votes
10 answers

Setting styles in Openpyxl

I need advice on setting styles in Openpyxl. I see that the NumberFormat of a cell can be set, but I also require setting of font colors and attributes (bold etc). There is a style.py class but it seems I can't set the style attribute of a cell, and…
Nelson Shaw
  • 1,103
  • 2
  • 10
  • 10
1
2 3
99 100