473,387 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Writing to and Reading from Excel

Hi,

I did some searching online and I found that I could use

xlrd and win32com.client

It seems that I could use win32com.client to read and write to excel. However, I didn't see xlrd do that. Is there a way to do that?
Jun 20 '08 #1
4 4491
jlm699
314 100+
Yes it can read. Refer to xlrd's API here.

First line reads:
"A Python module for extracting data from MS Excel ™ spreadsheet files. "

So it doesn't look like you can write to data... but you could extract the data, do what you need with it, and then save it back as a CSV, which can then be opened by Excel
Jun 20 '08 #2
Yes it can read. Refer to xlrd's API here.

First line reads:
"A Python module for extracting data from MS Excel ™ spreadsheet files. "

So it doesn't look like you can write to data... but you could extract the data, do what you need with it, and then save it back as a CSV, which can then be opened by Excel
My bad I meant I could read it, but I don't know how to write to it. I have never worked with CSV. Is there an example?
Jun 20 '08 #3
Is there something bad about using win32com.client? If not, then I will use this script. Seems to work fine.

import win32com.client
xlApp = win32com.client.Dispatch("Excel.Application")
xlApp.Visible=1
xlWb = xlApp.Workbooks.Open("Read.xls")
print xlApp.Worksheets("Sheet1").Name
xlApp.Worksheets("Sheet2").Range("A1").Value = "yellow"
cell = xlApp.Worksheets("Sheet3")
cell.Range("C3").Value = "money"
cell.Range("D4").Value = 9999
print cell.Range("C3").Value
print cell.Range("D4").Value
xlWb.Close(SaveChanges=1)
xlApp.Quit()
Jun 20 '08 #4
jlm699
314 100+
There is nothing bad about using COM objects; aside from the fact that you cannot develop a cross-platform application. You'll be stuck to windows (but considering it's Excel you probably won't be trying to get it to work under a WINE-powered Excel or similar).

CSV (Comma Separated Values) is simply a flat text file. Each row is contained on a line, each cell separated by a comma. ie
,Name,Age,Phone Number
1,Jack,23,555-1234
2,John,34,555-4321
3,Jimmy,21,555-5454
etc...
*Note the first ',' simply will place a blank cell when you open it in Excel because it splits the lines by comma and finds a NULL value for the first element, thereby creating a blank cell. (Try saving those contents as test.csv and opening in Excel to see for yourself)

The benefit to doing this is that you can work with it just like any other file object in Python.
Jun 20 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Paul | last post by:
I was wondering if anyone has had an issue where using vba code to read an excel file and import the data into an access table some records are not imported from the excel file. It seems looking at...
3
by: Jon Brookins | last post by:
I'm reposting this question as the other post seems to have been sucked into the net black hole. I'll keep this short. I am trying to read and edit an Excel workbook in its native BIFF format. ...
3
by: RJN | last post by:
Hi I've a template excel file which has all the calculations defined. There are certain input values to be entered which gives a lot of output to the user. I don't want to expose the excel sheet...
2
by: arvind1083 | last post by:
I need help for writing a excel file. As in one excel file there could be more than one sheets so I want to know how can I give name to different sheets and select a particular sheet for writing or...
0
by: shintu | last post by:
Hallo, I am trying to write french accented characters é è ê in Excel worksheet using my perl script , But I am stuck here as I couldnt find a way of writing it !: My code: use strict;...
1
by: pvenu | last post by:
Hi, I know basic perl (regular expressions, pattern matching, string manipulation, reading writing into text files). Yet, my requirement is to read an input text file -> process this input file...
8
by: fahadqureshi | last post by:
Hello, I posted here before asking a question about reading excel. Now that the reading problem is solved i am having trouble on how to write to an excel file. This was my code to read the excel...
1
by: =?Utf-8?B?ZmhpbGxpcG8=?= | last post by:
We have a code snippet that downloads data to Excel. it is writing row by row. This causes a performance issue. Any ideas on how to speed this up will be appreciated. Please find below an...
20
by: Marin Brkic | last post by:
Hello all, please, let me apologize in advance. English is not my first language (not even my second one), so excuse any errors with which I'm about to embarass myself in front of the general...
12
by: vijayarl | last post by:
Hi All, To Moderator : Sorry i have posted this querry to member rather putting in the forum. To All: Problem stmt: I am reading the data from the excel files & writing its content to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.