473,666 Members | 1,991 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Another PythonWin Excel question

I followed the example in
http://stompstompstomp.com/weblog/technical/2004-05-20 and learned that to
add a new worksheet to an Excel workbook, you would use the
workbook.Worksh eets.Add() method. That works. However, the new worksheet
got added *in front* of the last worksheet I was at. How can I get it to
add *after*?

Thanks,

--
Me
Jul 18 '05 #1
12 1880
I am not sure about this but I believe you can give a parameter
after="sheet1". to Add(), like so, Add(after="shee t1").

Unfortunately I do not have Excel installed on this machine to confirm
this.

A tip: if you have VBA (which you should if you have Excel) installed,
lookup the Add method for the Worksheets collection. VBA will show the
code completion, with all the arguments for the method call. Try the
same for any of the methods.

Thanks,
--Kartic

Jul 18 '05 #2

"Kartic" <ka************ ******@gmail.co m> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
I am not sure about this but I believe you can give a parameter
after="sheet1". to Add(), like so, Add(after="shee t1").

I get a "got an expected keyword argument 'after'" from Add().
Unfortunately I do not have Excel installed on this machine to confirm
this.

A tip: if you have VBA (which you should if you have Excel) installed,
lookup the Add method for the Worksheets collection. VBA will show the
code completion, with all the arguments for the method call. Try the
same for any of the methods.

Yes, I read about that but unfortunately I have no experience with VBA *at
all*. :=(
Thanks,
--Kartic

Jul 18 '05 #3
Sorry, I was thinking of the move() method. Move() takes the after=
argument.

See this link for usage. (The left nav bar has all other method of the
worksheets collection, so bookmark this page :-)

http://msdn.microsoft.com/library/de...oworkbooks.asp
Thanks

Jul 18 '05 #4
Ah, this work:

self.xlbook.Wor ksheets.Add(Non e,sht)

got it from:

http://mail.python.org/pipermail/pyt...er/183367.html

Thanks again.

--
Me
"It's me" <it***@yahoo.co m> wrote in message
news:ou******** ********@newssv r21.news.prodig y.com...

"Kartic" <ka************ ******@gmail.co m> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
I am not sure about this but I believe you can give a parameter
after="sheet1". to Add(), like so, Add(after="shee t1").


I get a "got an expected keyword argument 'after'" from Add().
Unfortunately I do not have Excel installed on this machine to confirm
this.

A tip: if you have VBA (which you should if you have Excel) installed,
lookup the Add method for the Worksheets collection. VBA will show the
code completion, with all the arguments for the method call. Try the
same for any of the methods.


Yes, I read about that but unfortunately I have no experience with VBA *at
all*. :=(
Thanks,
--Kartic


Jul 18 '05 #5
It's me wrote:
I followed the example in
http://stompstompstomp.com/weblog/technical/2004-05-20 and learned that to
add a new worksheet to an Excel workbook, you would use the
workbook.Worksh eets.Add() method. That works. However, the new worksheet
got added *in front* of the last worksheet I was at. How can I get it to
add *after*?

Thanks,

--
Me

Hello,

I did it yesterday like this way and it works well (part of my code):

wb.Worksheets.A dd(Count=nrMont hs,After=wb.Wor ksheets(1))

As I read in MSDN you could not write After="sheet1" instead you must
use the Object of sheet1 like in my example and it works well in my
case. The Count=... statement will create n Sheets after the first worksheet
By
Marten
Jul 18 '05 #6

"Marten Bauer" <Ma**********@g mx.net> wrote in message
news:34******** *****@individua l.net...

I did it yesterday like this way and it works well (part of my code):

wb.Worksheets.A dd(Count=nrMont hs,After=wb.Wor ksheets(1))
As I read in MSDN you could not write After="sheet1" instead you must
use the Object of sheet1 like in my example and it works well in my
case. The Count=... statement will create n Sheets after the first worksheet
Yes, I learn that as well. The parameter to After is a Worksheet object.
It appears if you don't specify any parameters, it would add it Before the
current sheet.

Thanks,


By
Marten

Jul 18 '05 #7
"It's me" <it***@yahoo.co m> writes:
Yes, I read about that but unfortunately I have no experience with VBA *at
all*. :=(


You don't really have to know VBA, but if you're going to try to
interact with COM objects from Python, you'll find it much smoother if
you at least use any available reference information for the COM
object model and interfaces you are using.

In the Excel case, that means understanding - or at least knowing how
to look in a reference - its object model, since that will tell you
exactly what parameters an Add method on a worksheet object will take
and how they work.

For excel, online documentation can be found in a VBAXL9.CHM help file
(the "9" may differ based on Excel release), but it might not always
be installed depending on what options were selected on your system. In
my English, Office 2000 installation, for example, the files are located in:
c:\Program Files\Microsoft Office\Office\1 033

You can load that file directly, or Excel itself will reference it
from within the script editor help (Tools->Macro->Visual Basic Editor,
then F1 for help). If you methods or classes and have the help
installed it'll bring in the reference.

You can also find it on MSDN on the web, although it can be tricky to
navigate down to the right section - the top of the Office 2000 object
documentation should be available at:

http://msdn.microsoft.com/library/en...modelguide.asp

This is mostly reference information, but there are some higher level
discussions of overall objects (e.g., worksheets, workbooks, cells,
etc...) too.

-- David
Jul 18 '05 #8
Thanks,

"David Bolen" <db**@fitlinxx. com> wrote in message
news:u1******** ***@fitlinxx.co m...
"It's me" <it***@yahoo.co m> writes:
Yes, I read about that but unfortunately I have no experience with VBA *at all*. :=(
You don't really have to know VBA, but if you're going to try to
interact with COM objects from Python, you'll find it much smoother if
you at least use any available reference information for the COM
object model and interfaces you are using.

In the Excel case, that means understanding - or at least knowing how
to look in a reference - its object model, since that will tell you
exactly what parameters an Add method on a worksheet object will take
and how they work.

For excel, online documentation can be found in a VBAXL9.CHM help file
(the "9" may differ based on Excel release), but it might not always
be installed depending on what options were selected on your system. In
my English, Office 2000 installation, for example, the files are located

in: c:\Program Files\Microsoft Office\Office\1 033

You can load that file directly, or Excel itself will reference it
from within the script editor help (Tools->Macro->Visual Basic Editor,
then F1 for help). If you methods or classes and have the help
installed it'll bring in the reference.

You can also find it on MSDN on the web, although it can be tricky to
navigate down to the right section - the top of the Office 2000 object
documentation should be available at:

http://msdn.microsoft.com/library/en...modelguide.asp
This is mostly reference information, but there are some higher level
discussions of overall objects (e.g., worksheets, workbooks, cells,
etc...) too.

-- David

Jul 18 '05 #9
It's me wrote:
I followed the example in
http://stompstompstomp.com/weblog/technical/2004-05-20 and learned that to
add a new worksheet to an Excel workbook, you would use the
workbook.Worksh eets.Add() method. That works. However, the new worksheet
got added *in front* of the last worksheet I was at. How can I get it to
add *after*?

Thanks,

--
Me


Does this help?

http://msdn.microsoft.com/library/de...nworkbooks.asp

--
Mike
Jul 18 '05 #10

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

Similar topics

0
1314
by: quadric | last post by:
Hi, I am just getting into PythonWin. I need my application that has Python embedded within it to communicate with an Excel spreadsheet. I have done this manually with PythonWin. All works well. How can I get my application to communicate via PythonWin with the Excel spreadsheet in an automated way?
14
2878
by: Jive | last post by:
I've un-installed Python 2.4, re-installed Python 2.3 and PythonWin for 2.3, but it's still broke. When I start PythonWin, sometimes it looks like it is going to be okay. But as soon as I open a .py file, the interactive window grabs the focus and will not let go. I am stumped. Is there something PythonWin uses that I could try re-installing? WxPython maybe?
3
3340
by: tkpmep | last post by:
I have a Python program that collects user input using msg = "Enter the full path and name of the file to be processed: " answer = raw_input(msg) If I run it in IDLE, the question is splashed across the execution window, and if it is long, simply wraps to the next line. Most importantly, it is intelligible, because I see the entire message. I enter my answer on the next line, and once again, I can see the entire path and file name,...
2
7328
by: siggy2 | last post by:
Hi All, (sorry for my bad english) I wrote a __tiny__ and __stupid__ recursive script directly into pythonwin interactive window with a time.sleep(1) and a print before each recursion... I should have taken a closer look at the ending condition (never satisfied!), anyway I was quite confident that a control-C would have stopped the intepreter as it is (incidentally?) when this break sequence is entered
7
4197
by: Robert | last post by:
Hello, I'm using Pythonwin and py2.3 (py2.4). I did not come clear with this: I want to use win32-fuctions like win32ui.MessageBox, listctrl.InsertItem ..... to get unicode strings on the screen - best results according to the platform/language settings (mainly XP Home, W2K, ...). Also unicode strings should be displayed as nice as possible at the console with normal print-s to stdout (on varying platforms, different
14
1959
by: Dan | last post by:
Just starting to do some windows Client / Server programming. Which would you recommend? I need to create a server to fire events and communicate with clients over a lan. Thanks
1
2056
by: Andrea Gavana | last post by:
Hi All, I am having some problems in running a very simple python script, which prints some numbers in an Excel spreadsheet. The numbers are stored in a list. I know that the numbers are different (random generated), but when I open the Excel file I get a column of data with all the numbers equal to the first item in the python list. I attach a very simple script that reproduces the problem. I am using Python 2.5, PythonWin build 210,...
4
4368
by: siggi | last post by:
Hi all, newbie question: I'd like to try speech synthesis with PythonWin 2.5. Problem ****** according to several instructions, such as found on http://surguy.net/articles/speechrecognition.xml and in a book on Python,
4
3610
by: sterling | last post by:
I'm curious as to why the difference between IDLE and pythonWin when using win32com. opening an excel file, i've attempted to grab the chart information out of the file. commands like co = ChartObjects(1) works in pythonWin but doesn't work in IDLE. however, on both co = chartobjects(1) works just fine.
0
8356
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8871
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8551
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
7386
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5664
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1776
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.