Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically edit Excel sheets? [closed]

I need to edit an Excel workbook using python. Is there a way of doing this without reading in the workbook, editing what I want and the writing it back? i.e. is there a way I can do this on the fly, as I only need to edit a couple of values per sheet?

I have looked at pyexcelerator, xlrd, and xlwt, but they only seem to support (as far as I can work out) reading and writing not editing. I cannot use pywin32 as I am using linux.

Any suggestions of libraries or particular ways of doing things?

like image 453
Jim Jeffries Avatar asked Nov 19 '10 15:11

Jim Jeffries


People also ask

Can Excel pull data from a closed workbook?

Extracting data from a closed file in another workbook is a common request by most of the excel user. They would like to pull or consolidate data from closed files; however, this is not possible.

Can Python process Excel files?

Getting Started. Openpyxl is a Python library that provides various methods to interact with Excel Files using Python. It allows operations like reading, writing, arithmetic operations, plotting graphs, etc. This module does not come in-built with Python.


2 Answers

First off, what version of Excel? Excel2007+ use an XML file format, while Excel2003- used a proprietary binary format... so the tools to read and write these work in totally different ways.

If you're after the more recent xlsx files, then take a look at Eric' Gazoni's openpyxl project. The code can be found on bitbucket. The driving force behind this is the ability to read and write xlsx files from Python within a single library.

Even then, it reads the entire workbook, but allows you to modify cells before writing it back.

Simply put: the structure of an Excel file doesn't lend itself to easy editing.... it's not simply a case of changing a few characters.

like image 111
Mark Baker Avatar answered Sep 19 '22 00:09

Mark Baker


xlutils has a copy module that may be interseting for you

like image 34
luc Avatar answered Sep 18 '22 00:09

luc