Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.04; 'attributes': 0.05; '-0700': 0.07; 'width': 0.07; 'python': 0.08; 'csv': 0.09; 'fetch': 0.09; 'length.': 0.09; 'pm,': 0.10; 'examples': 0.12; 'wrote:': 0.14; 'defined': 0.14; 'bieber': 0.16; 'columns': 0.16; 'declaimed': 0.16; 'dumps': 0.16; 'email addr:ix.netcom.com': 0.16; 'equation.': 0.16; 'f.close()': 0.16; 'properly.': 0.16; 'subject:import': 0.16; 'them...': 0.16; 'url:netcom': 0.16; 'url:wlfraed': 0.16; 'wulfraed': 0.16; 'received:74.125.82.174': 0.16; 'received:mail- wy0-f174.google.com': 0.16; 'cc:addr:python-list': 0.17; 'importing': 0.19; 'header:In-Reply-To:1': 0.21; 'column': 0.22; 'thu,': 0.22; 'cc:2**0': 0.22; 'cc:no real name:2**0': 0.23; 'module,': 0.23; 'fri,': 0.23; 'code': 0.24; 'subject: -- ': 0.25; 'url:home': 0.25; 'subject:data': 0.26; 'url:mailman': 0.26; 'script': 0.27; 'example': 0.27; 'sender:addr:gmail.com': 0.28; 'message-id:@mail.gmail.com': 0.28; 'lee': 0.29; 'import': 0.29; 'accommodate': 0.29; 'subject:How': 0.30; 'cc:addr:python.org': 0.30; 'url:listinfo': 0.30; 'module': 0.30; 'writer': 0.30; 'looks': 0.31; 'too': 0.33; 'file': 0.34; 'that,': 0.34; 'there': 0.35; 'purely': 0.35; 'using': 0.35; 'data.': 0.37; 'similar': 0.37; 'received:google.com': 0.37; 'change': 0.37; 'ways': 0.37; 'page': 0.37; 'url:python': 0.38; 'received:74.125.82': 0.38; 'received:74.125': 0.38; 'subject:from': 0.38; 'url:org': 0.38; 'data': 0.38; 'subject:: ': 0.38; 'should': 0.39; 'called': 0.39; 'more': 0.60; 'below': 0.61; 'waiting': 0.61; 'according': 0.63; 'increase': 0.64; 'here': 0.66; 'subject:Urgent': 0.73; 'dennis': 0.77; 'objective': 0.77; 'subject:Very': 0.84; 'vba': 0.84; 'skip:d 50': 0.93; 'sheet': 0.95 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:in-reply-to:references:from :date:x-google-sender-auth:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=1BACvG6Na7+FMxKYop4hCxx/81atfJ2mYbx3TJKiMV8=; b=x6PNPf09SS6t383WpqbekiukTSms+v+sGhXFcA7fEhLc4lPzJyY69Jdbu/yp12AIWu RtH1+GeLaqZmlrilvn1KKX4y9Xam5/XqyPvQh0+oI9lMwvl4kUnrbsZ0+vjKZB6OqvU2 EyLQsWR7powZU/foN29DizhTWbgJ8R90y6QR8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type :content-transfer-encoding; b=LgMb6KYemAXo4xmhcFDWIeymgSlJBJqYVr+xrcRUHKRCk7H5ogeHXrogLLdkav+gyu XFCxpiwol0cFYJskS6H8u8nug1OxLHWDuHZy6kOOoLWAeyMJDDWcGNMdJBL+hJFaARS9 885/lLHf8enRojoO2I7pGNMVxw4S/ErxfuwwE= MIME-Version: 1.0 Sender: kushal.kumaran@gmail.com In-Reply-To: References: <9ad94241-e281-4325-9c0d-23547ad0b9b9@glegroupsg2000goo.googlegroups.com> <85318329-5bc8-4474-a54e-4e7ff53cd304@k3g2000prl.googlegroups.com> From: Kushal Kumaran Date: Fri, 3 Jun 2011 18:11:21 +0530 X-Google-Sender-Auth: rTQfy0NBmWt1Dte0WtHwiWDeFEY Subject: Re: How to import data from MySQL db into excel sheet -- Very Urgent To: hisan Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 87 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1307104903 news.xs4all.nl 49048 [::ffff:82.94.164.166]:46570 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:6938 On Fri, Jun 3, 2011 at 5:52 PM, hisan 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=3DMySQLdb.Connect("localhost","root","san123","phone") > cursor=3Ddb.cursor() > > cursor.execute("select column_name from information_schema.columns > where table_name=3D'phonebook'") > row=3Dcursor.fetchall() > f=3Dopen(os.getcwd()+"\\analytics.csv",'w') > writer =3D csv.writer(f) > writer.writerow(row) > cursor.execute("select * from phonebook") > col_val=3Dcursor.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=C2=A0pm, Dennis Lee Bieber wrote: >> On Thu, 2 Jun 2011 10:25:24 -0700 (PDT), hisan >> 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 >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 Since CSV files are purely text, no Excel Sp= readsheet visual >> attributes can be defined in them... >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 Take Python out of the equation. >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 How would you change column width using an E= xcel VBA script/macro? >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 When you can answer that, you will have the = answer of how to do it >> from Python... >> -- >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 Wulfraed =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 Dennis Lee Bieber =C2=A0 =C2=A0 =C2=A0 =C2=A0 AF6VN >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 wlfr...@ix.netcom.com =C2=A0 =C2=A0HTTP://wl= fraed.home.netcom.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > --=20 regards, kushal