Is there a way to write something into an XLS file with python while keeping the initial format of this XLS file unchanged (such as font size, cell background color, etc)Thanks!
Asked
Active
Viewed 789 times
4 Answers
2
Maybe have a look at xlrd, xlwt, xlutils:
I have found it pretty useful in the past.

juanchopanza
- 223,364
- 34
- 402
- 480
-
Thank you! I tried the xlutils.copy, but it changed the initial styles completely... – ladyfafa Mar 29 '11 at 13:36
-
1This should help, following similar advice from @john machin I got it to work: http://stackoverflow.com/questions/3723793/preserving-styles-using-pythons-xlrd-xlwt-and-xlutils-copy – juanchopanza Mar 29 '11 at 13:38
0
If you can go for XML serializations of Office documents. Also have a look at ... http://www.python-excel.org/

Manuel Salvadores
- 16,287
- 5
- 37
- 56
0
You could also use pywin32 if you are using Windows

Fábio Diniz
- 10,077
- 3
- 38
- 45
-
1@ladyfafa: Fabio means: Use the COM interface in pywin32 to use Excel's COM interface directly. This is the most powerful and most flexible solution (you can do everything you can do in Excel), but you must be running on a Windows system with Excel installed. – winwaed Mar 29 '11 at 14:16
0
If the available tools like xlrd, xlwt, and xlutils don't work, you may have to fall back to programmatically editing the file with Excel via COM. Of course, you'll need a copy of Excel, have to work from Windows, and it will be slower than other approaches.

Steven Rumbalski
- 44,786
- 9
- 89
- 119
-
Excel COM is also the only way of creating/editing Excel 2007/2010 worksheets at the moment. I know I'd like a non-COM solution to creating Excel 2007 worksheets and ideally signing them as well. (Yes I know the OP asked for xls specifically. ) – winwaed Mar 29 '11 at 14:15