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


Groups > comp.lang.python > #6859 > unrolled thread

Aw: How to import data from MySQL db into excel sheet

Started byMartin Brochhaus <martin.brochhaus@googlemail.com>
First post2011-06-02 05:19 -0700
Last post2011-06-06 16:18 -0400
Articles 8 — 6 participants

Back to article view | Back to comp.lang.python


Contents

  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

#6859 — Aw: How to import data from MySQL db into excel sheet

FromMartin Brochhaus <martin.brochhaus@googlemail.com>
Date2011-06-02 05:19 -0700
SubjectAw: How to import data from MySQL db into excel sheet
Message-ID<9ad94241-e281-4325-9c0d-23547ad0b9b9@glegroupsg2000goo.googlegroups.com>
Why do you need to do this with python? Why not output the SQL data as a .cvs and open that file in Excel. The user can then adjust column widths as he likes.

If it has to be done programatically, you might want to start your journey here: 
http://www.python-excel.org/

Best regards,
Martin

[toc] | [next] | [standalone]


#6875 — Re: How to import data from MySQL db into excel sheet

Fromhisan <santosh.ssit@gmail.com>
Date2011-06-02 10:25 -0700
SubjectRe: How to import data from MySQL db into excel sheet
Message-ID<85318329-5bc8-4474-a54e-4e7ff53cd304@k3g2000prl.googlegroups.com>
In reply to#6859
On Jun 2, 5:19 pm, Martin Brochhaus <martin.brochh...@googlemail.com>
wrote:
> Why do you need to do this with python? Why not output the SQL data as a .cvs and open that file in Excel. The user can then adjust column widths as he likes.
>
> If it has to be done programatically, you might want to start your journey here:http://www.python-excel.org/
>
> Best regards,
> Martin



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

[toc] | [prev] | [next] | [standalone]


#6878 — Re: How to import data from MySQL db into excel sheet

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2011-06-02 11:48 -0700
SubjectRe: How to import data from MySQL db into excel sheet
Message-ID<mailman.2396.1307040552.9059.python-list@python.org>
In reply to#6875
On Thu, 2 Jun 2011 10:25:24 -0700 (PDT), hisan <santosh.ssit@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
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [next] | [standalone]


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

Fromhisan <santosh.ssit@gmail.com>
Date2011-06-03 05:22 -0700
SubjectRe: How to import data from MySQL db into excel sheet -- Very Urgent
Message-ID<abce1ec7-2265-451f-ac5b-1a3aa79e3fae@22g2000prx.googlegroups.com>
In reply to#6878
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.

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/

[toc] | [prev] | [next] | [standalone]


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

FromKushal Kumaran <kushal.kumaran+python@gmail.com>
Date2011-06-03 18:11 +0530
SubjectRe: How to import data from MySQL db into excel sheet -- Very Urgent
Message-ID<mailman.2428.1307104903.9059.python-list@python.org>
In reply to#6937
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

[toc] | [prev] | [next] | [standalone]


#7094 — RE: How to import data from MySQL db into excel sheet

From"Prasad, Ramit" <ramit.prasad@jpmchase.com>
Date2011-06-06 12:35 -0400
SubjectRE: How to import data from MySQL db into excel sheet
Message-ID<mailman.2493.1307378163.9059.python-list@python.org>
In reply to#6875
> 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

If you are using xlwt:
sheet.col(9).width = 3200

I am not sure exactly what unit the 3200 represents so I just adjust this manually to be a size that works for me.


Ramit



Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423


This communication is for informational purposes only. It is not
intended as an offer or solicitation for the purchase or sale of
any financial instrument or as an official confirmation of any
transaction. All market prices, data and other information are not
warranted as to completeness or accuracy and are subject to change
without notice. Any comments or statements made herein do not
necessarily reflect those of JPMorgan Chase & Co., its subsidiaries
and affiliates.

This transmission may contain information that is privileged,
confidential, legally privileged, and/or exempt from disclosure
under applicable law. If you are not the intended recipient, you
are hereby notified that any disclosure, copying, distribution, or
use of the information contained herein (including any reliance
thereon) is STRICTLY PROHIBITED. Although this transmission and any
attachments are believed to be free of any virus or other defect
that might affect any computer system into which it is received and
opened, it is the responsibility of the recipient to ensure that it
is virus free and no responsibility is accepted by JPMorgan Chase &
Co., its subsidiaries and affiliates, as applicable, for any loss
or damage arising in any way from its use. If you received this
transmission in error, please immediately contact the sender and
destroy the material in its entirety, whether in electronic or hard
copy format. Thank you.

Please refer to http://www.jpmorgan.com/pages/disclosures for
disclosures relating to European legal entities.

[toc] | [prev] | [next] | [standalone]


#7105 — Re: How to import data from MySQL db into excel sheet

FromBenjamin Kaplan <benjamin.kaplan@case.edu>
Date2011-06-06 11:43 -0700
SubjectRe: How to import data from MySQL db into excel sheet
Message-ID<mailman.2501.1307385843.9059.python-list@python.org>
In reply to#6875
On Mon, Jun 6, 2011 at 9:35 AM, Prasad, Ramit <ramit.prasad@jpmchase.com> wrote:
>> 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
>
> If you are using xlwt:
> sheet.col(9).width = 3200
>
> I am not sure exactly what unit the 3200 represents so I just adjust this manually to be a size that works for me.
>
>
> Ramit
>
>

xlwt is a package for editing Excel files. CSV, despite being a format
that Excel can open, is not an Excel file. A CSV is to spreadsheets
what plain text is to word processing. It's an extremely simple, easy
to use format programaticfally but it doesn't support any formattting
of any kind.

[toc] | [prev] | [next] | [standalone]


#7110 — RE: How to import data from MySQL db into excel sheet

From"Prasad, Ramit" <ramit.prasad@jpmchase.com>
Date2011-06-06 16:18 -0400
SubjectRE: How to import data from MySQL db into excel sheet
Message-ID<mailman.2507.1307393775.9059.python-list@python.org>
In reply to#6875
>>> 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

>xlwt is a package for editing Excel files. CSV, despite being a format
>that Excel can open, is not an Excel file. A CSV is to spreadsheets
>what plain text is to word processing. It's an extremely simple, easy
>to use format programaticfally but it doesn't support any formattting
>of any kind.

Topic says importing into excel, so I assume the OP is *currently* using CSV but wants to *switch* to Excel. If that is true then the following is the syntax for it. Assuming you open a workbook and create a worksheet within with a local name of "sheet".

> sheet.col(9).width = 3200


Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

This communication is for informational purposes only. It is not
intended as an offer or solicitation for the purchase or sale of
any financial instrument or as an official confirmation of any
transaction. All market prices, data and other information are not
warranted as to completeness or accuracy and are subject to change
without notice. Any comments or statements made herein do not
necessarily reflect those of JPMorgan Chase & Co., its subsidiaries
and affiliates.

This transmission may contain information that is privileged,
confidential, legally privileged, and/or exempt from disclosure
under applicable law. If you are not the intended recipient, you
are hereby notified that any disclosure, copying, distribution, or
use of the information contained herein (including any reliance
thereon) is STRICTLY PROHIBITED. Although this transmission and any
attachments are believed to be free of any virus or other defect
that might affect any computer system into which it is received and
opened, it is the responsibility of the recipient to ensure that it
is virus free and no responsibility is accepted by JPMorgan Chase &
Co., its subsidiaries and affiliates, as applicable, for any loss
or damage arising in any way from its use. If you received this
transmission in error, please immediately contact the sender and
destroy the material in its entirety, whether in electronic or hard
copy format. Thank you.

Please refer to http://www.jpmorgan.com/pages/disclosures for
disclosures relating to European legal entities.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web