473,555 Members | 2,554 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Applicat ion' )
excel.Visible=1 # shows the spreadsheet (can be handy)
xlCSV = 6
# substitute for list generation
list = ["c:\\temp\\test .xls", "c:\\temp\\test 1.xls"]

for nm in list:
csv = os.path.splitex t( 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
<enterkeystro ke 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 1885
On Aug 12, 10:36 am, norseman <norse...@hughe s.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.Applicat ion' )
excel.Visible=1 # shows the spreadsheet (can be handy)
xlCSV = 6
# substitute for list generation
list = ["c:\\temp\\test .xls", "c:\\temp\\test 1.xls"]

for nm in list:
csv = os.path.splitex t( 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
<enterkeystro ke 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...@hughe s.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'cl ick" is very
non-production oriented.
"The following*"
=============== =====
#!/---
#
import os
import win32com.client

excel = win32com.client .Dispatch( 'Excel.Applicat ion' )
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\\test 1.xls"]

for nm in list:
csv = os.path.splitex t( 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
1654
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 program, I guess. I'm stumped. ---------- The Symptoms --------------------- Here's what happens. I fire up PythonWin without opening a python...
28
2656
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 particular the if you try to dump/load an infinity or nan value, the load operation chokes: Under Linux: $ python
5
1418
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. Pretty easy. But this time I thought - table layout is obsolete too, time to learn CSS. A task that would have been trivial, and taken maybe an...
42
2348
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
7544
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 compile code that uses it - #if _MSC_VER == 1200 // some code here #elif _MSC_VER == 1300 // somemore code
5
1562
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 through everything I could find using google. <%= Clinton Gallagher METROmilwaukee (sm) "A Regional Information Service" NET csgallagher AT...
13
2145
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
1770
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. Outline: cd somedir ls -1 *.xls >thislist #ls hyphen one python process.py (yes - ls can go here if wanted. easier to edit outside)
0
162
by: Terry Reedy | last post by:
norseman wrote:
8
1902
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": http://docs.python.org/lib/typeiter.html I don't understand the reasoning behind this. As I understand it, an iterator is something like a stream....
1
7587
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7903
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6176
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5170
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3593
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2034
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1156
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
863
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.