Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #6938

Re: How to import data from MySQL db into excel sheet -- Very Urgent

References <9ad94241-e281-4325-9c0d-23547ad0b9b9@glegroupsg2000goo.googlegroups.com> <85318329-5bc8-4474-a54e-4e7ff53cd304@k3g2000prl.googlegroups.com> <mailman.2396.1307040552.9059.python-list@python.org> <abce1ec7-2265-451f-ac5b-1a3aa79e3fae@22g2000prx.googlegroups.com>
From Kushal Kumaran <kushal.kumaran+python@gmail.com>
Date 2011-06-03 18:11 +0530
Subject Re: How to import data from MySQL db into excel sheet -- Very Urgent
Newsgroups comp.lang.python
Message-ID <mailman.2428.1307104903.9059.python-list@python.org> (permalink)

Show all headers | View raw


On Fri, Jun 3, 2011 at 5:52 PM, hisan <santosh.ssit@gmail.com> wrote:
> Task i need to achieve here is:
> I need to write a python script which fetches all the data from the
> MySQL database and dumps into an excel sheet. since i was not able to
> dump the data into excel sheet i used CSV file which looks similar to
> excel sheet.
> on dumping the data into CSV file i came know that column width is too
> small and hence it was not possible to display data properly.
> Hence i requested the way to increase the column widht to accommodate
> data of any length.
>

The xlwt module lets you write excel files from python.  There is more
information at http://www.python-excel.org/.  The examples page has an
example called col_width.py, which should be what you need.

> below is my sample code
>
>
> import os,time
> import MySQLdb
> import csv
> db=MySQLdb.Connect("localhost","root","san123","phone")
> cursor=db.cursor()
>
> cursor.execute("select column_name from information_schema.columns
> where table_name='phonebook'")
> row=cursor.fetchall()
> f=open(os.getcwd()+"\\analytics.csv",'w')
> writer = csv.writer(f)
> writer.writerow(row)
> cursor.execute("select * from phonebook")
> col_val=cursor.fetchall()
> writer.writerows(col_val)
> f.close()
>
> My Main objective is to fetch the data and from database and dump it
> into excel sheet or csv file using Python.
> If there any ways to achieve this using python please let me know.
>
> Waiting for the early response-
>
> I need to achieve my task using python only
>
>
>
>
>
>
> On Jun 2, 2:48 pm, Dennis Lee Bieber <wlfr...@ix.netcom.com> wrote:
>> On Thu, 2 Jun 2011 10:25:24 -0700 (PDT), hisan <santosh.s...@gmail.com>
>> declaimed the following in gmane.comp.python.general:
>>
>>
>>
>> > Currently i am importing the Database into CSV file using csv module,
>> > in csv file i need to change the column width according the size of
>> > the data. i need to set different column width for different columns
>> > pleas let me know how to achieve this
>>
>>         Since CSV files are purely text, no Excel Spreadsheet visual
>> attributes can be defined in them...
>>
>>         Take Python out of the equation.
>>
>>         How would you change column width using an Excel VBA script/macro?
>>
>>         When you can answer that, you will have the answer of how to do it
>> from Python...
>> --
>>         Wulfraed                 Dennis Lee Bieber         AF6VN
>>         wlfr...@ix.netcom.com    HTTP://wlfraed.home.netcom.com/
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
regards,
kushal

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Aw: How to import data from MySQL db into excel sheet Martin Brochhaus <martin.brochhaus@googlemail.com> - 2011-06-02 05:19 -0700
  Re: How to import data from MySQL db into excel sheet hisan <santosh.ssit@gmail.com> - 2011-06-02 10:25 -0700
    Re: How to import data from MySQL db into excel sheet Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2011-06-02 11:48 -0700
      Re: How to import data from MySQL db into excel sheet -- Very Urgent hisan <santosh.ssit@gmail.com> - 2011-06-03 05:22 -0700
        Re: How to import data from MySQL db into excel sheet -- Very Urgent Kushal Kumaran <kushal.kumaran+python@gmail.com> - 2011-06-03 18:11 +0530
    RE: How to import data from MySQL db into excel sheet "Prasad, Ramit" <ramit.prasad@jpmchase.com> - 2011-06-06 12:35 -0400
    Re: How to import data from MySQL db into excel sheet Benjamin Kaplan <benjamin.kaplan@case.edu> - 2011-06-06 11:43 -0700
    RE: How to import data from MySQL db into excel sheet "Prasad, Ramit" <ramit.prasad@jpmchase.com> - 2011-06-06 16:18 -0400

csiph-web