473,402 Members | 2,055 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,402 software developers and data experts.

Re: Broken examples

Tim;
Finally got a chance to test your snippet. Thank you for it!

I took the liberty of flushing it out a bit.
================
#!/---
#
import os
import win32com.client

excel = win32com.client.Dispatch( 'Excel.Application' )
excel.Visible=1 # shows the spreadsheet (can be handy)
xlCSV = 6
# substitute for list generation
list = ["c:\\temp\\test.xls", "c:\\temp\\test1.xls"]

for nm in list:
csv = os.path.splitext( nm )[0] + '.csv'
print "Procesing file:", csv
if os.path.exists(csv): # window$ won't auto overwrite
os.unlink(csv)
wb = excel.Workbooks.Open( nm )
wb.SaveAs( csv, xlCSV )
print wb.Close() # requires manual verification
# eliminating unattended runs

#wb.Exit() & wb.Quit() # generate ERROR(s) - no such thing(s)
# leaving Excel open

excel.Visible=0 # actually closes Excel if no sheet open
# verified via task manager

print "Check to see if this worked."

# end of file
=================
The above does in fact work.
Using the above I have a few questions.
Documentation on xlCSV came from where?
" on .Workbooks.Open(file.xls) came from ???
" on .SaveAs( filename, xlCSV ) came from ???
" on .Close() came from ???
Tell me about the lack of the .Exit() and/or .Quit(), please.
I ran out of time today. Is it possible to send something like an
<enterkeystroke to a Window (<yes><no>) box if it accepts same from
actual keyboard? May not work anyway since .Close() hangs (in
interactive) awaiting it's answer.

Tim - thank you again! At least this works well enough that a clerk can
press <enteruntil the thing runs out of material. :) Just press and
hold the <enterkey until the buffer overflow beeps and go do some
filing and when the screen 'stops' do it again... Eliminates typos.
Thank you.

Steve
no******@hughes.net
Aug 12 '08 #1
2 1875
On Aug 12, 10:36 am, norseman <norse...@hughes.netwrote:
Tim;
Finally got a chance to test your snippet. Thank you for it!

I took the liberty of flushing it out a bit.
================
#!/---
#
import os
import win32com.client

excel = win32com.client.Dispatch( 'Excel.Application' )
excel.Visible=1 # shows the spreadsheet (can be handy)
xlCSV = 6
# substitute for list generation
list = ["c:\\temp\\test.xls", "c:\\temp\\test1.xls"]

for nm in list:
csv = os.path.splitext( nm )[0] + '.csv'
print "Procesing file:", csv
if os.path.exists(csv): # window$ won't auto overwrite
os.unlink(csv)
wb = excel.Workbooks.Open( nm )
wb.SaveAs( csv, xlCSV )
print wb.Close() # requires manual verification
# eliminating unattended runs

#wb.Exit() & wb.Quit() # generate ERROR(s) - no such thing(s)
# leaving Excel open

excel.Visible=0 # actually closes Excel if no sheet open
# verified via task manager

print "Check to see if this worked."

# end of file
=================
The above does in fact work.
Using the above I have a few questions.
Documentation on xlCSV came from where?
" on .Workbooks.Open(file.xls) came from ???
" on .SaveAs( filename, xlCSV ) came from ???
" on .Close() came from ???
Tell me about the lack of the .Exit() and/or .Quit(), please.
I ran out of time today. Is it possible to send something like an
<enterkeystroke to a Window (<yes><no>) box if it accepts same from
actual keyboard? May not work anyway since .Close() hangs (in
interactive) awaiting it's answer.

Tim - thank you again! At least this works well enough that a clerk can
press <enteruntil the thing runs out of material. :) Just press and
hold the <enterkey until the buffer overflow beeps and go do some
filing and when the screen 'stops' do it again... Eliminates typos.
Why do you want to save as CSV? Would you be happier with a simple
reliable method to extract information from Excel files without all
that bother? If so, consider the xlrd package (http://www.lexicon.net/
sjmachin/xlrd.htm). If you really do need CSV files, still consider
xlrd in combination with the Python csv module -- remove all that user
involvement, allow the user to use Excel for other purposes while the
job is running (instead of filing), programatically handle exception
conditions (like more than one worksheet in the workbook), run it on
Linus or a Mac if you want to, ...

Aug 12 '08 #2
John Machin wrote:
On Aug 12, 10:36 am, norseman <norse...@hughes.netwrote:
>Tim;
Finally got a chance to test your snippet. Thank you for it!

I took the liberty of flushing it out a bit.
================
....(snip)
>>

Why do you want to save as CSV? Would you be happier with a simple
reliable method to extract information from Excel files without all
that bother? If so, consider the xlrd package (http://www.lexicon.net/
sjmachin/xlrd.htm). If you really do need CSV files, still consider
xlrd in combination with the Python csv module -- remove all that user
involvement, allow the user to use Excel for other purposes while the
job is running (instead of filing), programatically handle exception
conditions (like more than one worksheet in the workbook), run it on
Linus or a Mac if you want to, ...

--
http://mail.python.org/mailman/listinfo/python-list
======================
Why do you want to save as CSV? There is a ton of text processing
programs that suit various people
and thus text lends itself to a
greater audience and massive amounts
of processing tools. Tools people
already know how to use.

Would you be happier with a
simple reliable method to
extract information from Excel
files without all that bother? In truth - perhaps on occasion. But
take a look at the following*. I can
process 1,000's of files while I am
asleep and I don't even need to know
the internal layout. Secretaries,
Clerks and even Student help can use
their favorite text program to search
and replace whatever. Massive amounts
of data can be reviewed and corrected
by non-special computer users. Not to
mention my use of things like sed for
the bulk work.

If so, consider the xlrd package
(http://www.lexicon.net/sjmachin/xlrd.htm).
I did download it. I'll give it a
"test drive" as soon as I can. Then
I can comment on it. There are times
when it could be handy.
If you really do need CSV
files, still consider xlrd in
combination with the Python csv
module -- remove all that
user involvement... Point here is I need human review.
What I don't need is typos.
The intent in the original Clerk
statement was to poke fun at Window$.
Microsoft "point'n'click" is very
non-production oriented.
"The following*"
====================
#!/---
#
import os
import win32com.client

excel = win32com.client.Dispatch( 'Excel.Application' )
excel.Visible=0 #=1 shows the spreadsheet (can be handy)
xlCSV = 6
# a substitute for the list generator
list = ["c:\\temp\\test.xls", "c:\\temp\\test1.xls"]

for nm in list:
csv = os.path.splitext( nm )[0] + '.csv'
print "Procesing file:", csv
if os.path.exists(csv):
os.unlink(csv)
wb = excel.Workbooks.Open( nm )
wb.SaveAs( csv, xlCSV )
wb.Close( False )

excel.Quit()

print "Check to see if this worked for you."

# end of file
====================

The case at hand is that The State of California has been keeping
weather records for awhile. The more reliable stations date from the
1920's. Others go back into the latter 1800's. Satellite reporting is
rather new. Before that one took a horse or a buckboard and went off to
check things. Daily data is missing (even now) for various reasons. The
human can do what computers cannot - think (we hope) :). Some forms of
omissions can be bulk checked. Some cannot. It is counter productive
to try to create 'the all encompassing program'. The 'do all' does, as
yet, not exist. If someone reading this got lost, try this; would you
consider taking your brand new Ferrari 4-wheeling in the Grand Canyon?
Or would you prefer that beat-up old jeep over there?
Sometimes just getting out and walking around accomplishes more. Maybe
not as fast, but usually better. The trick is knowing which to program
and which to give to the kid. It is also counter productive to force
people well trained on Tool A to only use Tool B. Better to find a
common zone and let each use their respective favorite.

"If you are not converting data, you are not producing anything useful."
-- Me
John - Thanks for the link. I will test the library.
Steve
no******@hughes.net
Aug 12 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Michael | last post by:
I have broken PythonWin and I don't know how or why. It worked great until recently. I have installed / removed several apps since it worked last. I could have a virus unknown to my antivirus...
28
by: Grant Edwards | last post by:
I finally figured out why one of my apps sometimes fails under Win32 when it always works fine under Linux: Under Win32, the pickle module only works with a subset of floating point values. In...
5
by: Retlak | last post by:
A week ago I decided to convert an old web site from frames to a frameless layout. I'd done this before with a different website, converted from layout using frames to layout using tables....
42
by: cody | last post by:
public DateTime Value { get { try { return new DateTime(int.Parse(tbYear.Text), int.Parse(tbMonth.Text), int.Parse(tbDay.Text)); } catch (FormatException)
2
by: jm | last post by:
Hello, It appears the compiler #define _MSC_VER is broken under .NET, even though when "mousing over" the _MSC_VER it says it's #def'd as 1300. That's exactly what I'd expect. However, when I...
5
by: clintonG | last post by:
Neither MSDN code examples nor will function. Has anybody figured out how to use the 2.0 classes, methods and properties to dynamically create HTML in the HTML <head> element? I've burned...
13
by: Steven Bethard | last post by:
Jean-Paul Calderone <exarkun@divmod.comwrote: Interesting. Could you give a few illustrations of this? (I didn't run into the same problem at all, so I'm curious.) Steve
4
by: norseman | last post by:
I'm only talking about IPC related. I have googled, yahooed, and so forth for several months now. ALL examples I've come across have failed including those pertinent in the Python doc area. ...
0
by: Terry Reedy | last post by:
norseman wrote:
8
by: Steven D'Aprano | last post by:
According to the Python docs, once an iterator raises StopIteration, it should continue to raise StopIteration forever. Iterators that fail to behave in this fashion are deemed to be "broken": ...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.