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


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

Appending data to an excel sheet by python code

Started byManoj Rout <manojrout70@gmail.com>
First post2013-09-14 04:33 -0700
Last post2013-09-14 10:28 -0700
Articles 4 — 4 participants

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


Contents

  Appending data to an excel sheet by python code Manoj Rout <manojrout70@gmail.com> - 2013-09-14 04:33 -0700
    Re: Appending data to an excel sheet by python code MRAB <python@mrabarnett.plus.com> - 2013-09-14 18:06 +0100
    Re: Appending data to an excel sheet by python code Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-09-14 13:22 -0400
    Re: Appending data to an excel sheet by python code petmertens@gmail.com - 2013-09-14 10:28 -0700

#54163 — Appending data to an excel sheet by python code

FromManoj Rout <manojrout70@gmail.com>
Date2013-09-14 04:33 -0700
SubjectAppending data to an excel sheet by python code
Message-ID<87454429-bd36-44b2-bef1-055d976c16ae@googlegroups.com>
hi
  i want to append some data to an existing excel sheet by reading from  file.But here i am facing 2 problem.first is when i am reading from file.


import re

file=open("C:\Workspace\WS2\P1\Dave\Generated\src\UART001\UART001_Conf.c","r")
strings=re.search(r'(?<=(.Mode = UART_))\w+',file.read())
string=re.search(r'(?<=(.StopBit = UART_))\w+',file.read())

print strings.group()
print string.group()

workbook.close()



Here if i will read only once then it is fine and not showing any error.But if i will do it for second time i.e.2nd string i have to search and print both of them,then it is showing error.

And one more problem how to append some data to an existing excel sheet by python code.

so can u please help me on this problem.

Thanks and with regards 
Manoj Rout

[toc] | [next] | [standalone]


#54168

FromMRAB <python@mrabarnett.plus.com>
Date2013-09-14 18:06 +0100
Message-ID<mailman.377.1379178380.5461.python-list@python.org>
In reply to#54163
On 14/09/2013 12:33, Manoj Rout wrote:
> hi
>    i want to append some data to an existing excel sheet by reading from  file.But here i am facing 2 problem.first is when i am reading from file.
>
>
> import re
>
It's a good idea to use raw string literals for file paths on
Windows. Alternatively, you could use forward slashes instead of
backslashes.

> file=open("C:\Workspace\WS2\P1\Dave\Generated\src\UART001\UART001_Conf.c","r")

Here you're reading the entire file:

> strings=re.search(r'(?<=(.Mode = UART_))\w+',file.read())

Here you're trying to read the entire file again, but you're already
read to its end, so you'll now get an empty string:

> string=re.search(r'(?<=(.StopBit = UART_))\w+',file.read())
>
> print strings.group()
> print string.group()
>
What's 'workbook'? Don't you mean 'file'?

> workbook.close()
>
>
>
> Here if i will read only once then it is fine and not showing any error.But if i will do it for second time i.e.2nd string i have to search and print both of them,then it is showing error.
>
You haven't shown the traceback, so I have to guess what the error was.

> And one more problem how to append some data to an existing excel sheet by python code.
>
> so can u please help me on this problem.
>

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


#54170

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2013-09-14 13:22 -0400
Message-ID<mailman.378.1379179382.5461.python-list@python.org>
In reply to#54163
On Sat, 14 Sep 2013 04:33:42 -0700 (PDT), Manoj Rout
<manojrout70@gmail.com> declaimed the following:

>hi
>  i want to append some data to an existing excel sheet by reading from  file.But here i am facing 2 problem.first is when i am reading from file.
>
>
>import re
>
>file=open("C:\Workspace\WS2\P1\Dave\Generated\src\UART001\UART001_Conf.c","r")

	For safety, it is better to work with / rather than \ (the only time
you must have the \ in Windows is when sending the string to a command
shell -- os.system and similar functions)

>strings=re.search(r'(?<=(.Mode = UART_))\w+',file.read())

	You've just read the entire file and are now at EOF

>string=re.search(r'(?<=(.StopBit = UART_))\w+',file.read())
>
... so there is nothing left to read here.

	Either read the file into memory first and pass the string to both re
calls, or rewind the file (which may require closing/opening since you
specified "r" mode) between the re calls

>And one more problem how to append some data to an existing excel sheet by python code.
>

	Your best chances are to use libraries designed to access Excel files
(consider, Office XP Excel files are some crytic binary, while Office 2010
Excel files are zipped XML -- your code won't work on both forms).

	If you are on a Windows box, you could use ctypes (or maybe the win32
packages) to access the Excel DLL directly, and navigate just like you
would in an Excel "macro" (visual basic for applications).
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

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


#54171

Frompetmertens@gmail.com
Date2013-09-14 10:28 -0700
Message-ID<b936ef2c-04cd-4f23-ba99-62ff17015a95@googlegroups.com>
In reply to#54163
Did you consider using xlrd and xlwt?
I guess these package provide a solution to your problem.

[toc] | [prev] | [standalone]


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


csiph-web