Welcome to Telelogic Product Support
  Home Downloads Knowledgebase Case Tracking Licensing Help Telelogic Passport
Telelogic DOORS (steve huntington)
Decrease font size
Increase font size
Topic Title: Writing to different excel worksheets
Topic Summary: Code currently writes to 2 different excel worbooks, but want it to write to different excel worksheets...
Created On: 20-Dec-2007 19:31
Status: Post and Reply
Linear : Threading : Single : Branch
Search Topic Search Topic
Topic Tools Topic Tools
Quick Reply Quick Reply
Subscribe to this topic Subscribe to this topic
E-mail this topic to someone. E-mail this topic
Bookmark this topic Bookmark this topic
View similar topics View similar topics
View topic in raw text format. Print this topic.
 20-Dec-2007 19:31
User is offline View Users Profile Print this message


Raul Castellanos

Posts: 7
Joined: 19-Dec-2007

I need help with this code. This code currently writes some data to 2 different excel workbooks. Opens one workbook writes data -> Opens second workbook writes data. I would like to write data in sheet 1, then write data in sheet 2, and keep writing some other data into other sheets (up to sheet 8). Sheets 3-8 will include some data that is filtered out. I would like to modify my existing code from writing to two different workbooks -> TO writing to different excel sheets. Here is my code, please help me resolve this issue. Thank you

Edited: 20-Dec-2007 at 19:36 by Raul Castellanos
Report this to a Moderator Report this to a Moderator
 20-Dec-2007 19:33
User is offline View Users Profile Print this message


Raul Castellanos

Posts: 7
Joined: 19-Dec-2007

Here is code...

Edited: 8-Jan-2008 at 22:59 by Raul Castellanos
Report this to a Moderator Report this to a Moderator
 21-Dec-2007 10:08
User is offline View Users Profile Print this message


Eric Piallat

Posts: 13
Joined: 10-Dec-2007

Hi Raul,

Working with Excel is very different from an Office version to another.
For instance, Telelogic examples only work with Excel 95.

Which version do you use yourself ?

Assuming you're working with Excel 2000, this may help you.

This perm activates the sheet with the required name from the given workbook, and returns an handle on it:
Report this to a Moderator Report this to a Moderator
 21-Dec-2007 15:39
User is offline View Users Profile Print this message


David Pechacek

Posts: 674
Joined: 5-Dec-2006

Eric I've used my Excel programs with Excel from Office 97, Office 2000, Office XP, and Office 2003. The COM interface for Excel has remained largely the same. There are a few things I do with Excel that aren't supported by Office 97 & 2000 but the majority of it as far as getting sheets and cells, setting text, changing color, etc. is all the same.

Now I've never gone back to Excel 95 (god who would still use that?). But Telelogic's examples hardly only work with it.

I haven't tested with Office 2007 yet either but Microsoft is pretty good about maintaining backwards compatibility. Looking at the MSDN stuff, it looks to be the same with some extra features added in.

The code you posted is similar to mine and it works with every version of Office I've tested with.

-------------------------
David Pechacek
AAI Services Textron
dpechacek@sc-aaicorp.com
David.Pechacek@gmail.com
Report this to a Moderator Report this to a Moderator
 21-Dec-2007 15:45
User is offline View Users Profile Print this message


David Pechacek

Posts: 674
Joined: 5-Dec-2006

Raul. Here is an old post of mine with many useful Excel functions. It's a bit outdated but has what you need. I've only added a few minor things since then.

Excel functions

Feel free to email me with any questions.

-------------------------
David Pechacek
AAI Services Textron
dpechacek@sc-aaicorp.com
David.Pechacek@gmail.com

Edited: 21-Dec-2007 at 15:46 by David Pechacek
Report this to a Moderator Report this to a Moderator
 21-Dec-2007 18:28
User is offline View Users Profile Print this message


Raul Castellanos

Posts: 7
Joined: 19-Dec-2007

I am using Office Excel 2003
Report this to a Moderator Report this to a Moderator
 21-Dec-2007 20:42
User is offline View Users Profile Print this message


Raul Castellanos

Posts: 7
Joined: 19-Dec-2007

I am running into some problems. I am able to open up another worksheet (sheet 4, since excel initalizes with 3 sheets) with this code, but it will not write to the sheet 4. I keep getting a OLE method failed, then it says "Unable to get active sheet".

I am confused on how to use the bool getSheet(int sheetNumber) function. I dont understand what to write in put(args, sheetNumber) ? Can you give me an example on how to use this function to write to Sheet 4-8?

Edited: 8-Jan-2008 at 23:00 by Raul Castellanos
Report this to a Moderator Report this to a Moderator
 21-Dec-2007 20:52
User is offline View Users Profile Print this message


David Pechacek

Posts: 674
Joined: 5-Dec-2006

You're basically using args to pass parameters to Excel functions. You want sheet 4. So you put 4 in the argument list. That's passed to the Item property of the Sheets collection and it assigns item 4 to the objSheet variable.

I think I know what the problem is though. As I said thats an old version. Add the statement "clear(args)" before the "put(args, sheetNumber)" statement. That will clear the arguments.

-------------------------
David Pechacek
AAI Services Textron
dpechacek@sc-aaicorp.com
David.Pechacek@gmail.com
Report this to a Moderator Report this to a Moderator
 21-Dec-2007 21:07
User is offline View Users Profile Print this message


Raul Castellanos

Posts: 7
Joined: 19-Dec-2007

I added "clear(args)" before "put(args, sheetNumber)" statement and initialized "int sheetNumber = 4" and i think i ran into another problem.

this is what the code looks like. Now I get an error "Problem with OLE Argument names", so i think there is something wrong with my code. I have been looking at it for 2 days...

Edited: 8-Jan-2008 at 23:00 by Raul Castellanos
Report this to a Moderator Report this to a Moderator
 21-Dec-2007 21:21
User is offline View Users Profile Print this message


David Pechacek

Posts: 674
Joined: 5-Dec-2006

I just noticed something Raul in your nextSheet() method.

At line 68:
checkRes(oleGet(objWorkbooks,cPropertyActiveSheet,objSheet))

This is incorrect. It needs to be:
checkRes(oleGet(objWorkbook,cPropertyActiveSheet,objSheet))

That is probably the source of the error your mentioned.

-------------------------
David Pechacek
AAI Services Textron
dpechacek@sc-aaicorp.com
David.Pechacek@gmail.com

Edited: 21-Dec-2007 at 21:23 by David Pechacek
Report this to a Moderator Report this to a Moderator
 21-Dec-2007 21:24
User is offline View Users Profile Print this message


Raul Castellanos

Posts: 7
Joined: 19-Dec-2007

That did it...Thank you David. Thats the benefit of having someone else look at your code and it worked.
Thanks a bunch
Report this to a Moderator Report this to a Moderator
 21-Dec-2007 21:33
User is offline View Users Profile Print this message


Raul Castellanos

Posts: 7
Joined: 19-Dec-2007

Now this fixes my problem of having to write to two different worksheets. My output data currently writes to Sheet 1 (first set of data) and then to Sheet 4 (second set of data). How would I apply a filter to my first set of data and output 5 more worksheets from different modules. I am thinking I have to do a loop to create 5 more new worksheets and then write to them separately the same way I did with sheet 4? Is that right?
Report this to a Moderator Report this to a Moderator
 21-Dec-2007 23:07
User is offline View Users Profile Print this message


David Pechacek

Posts: 674
Joined: 5-Dec-2006

Yes that sounds right. I assume you mean filter the DOORs data? This is very simple and explained in the DXL Reference manual.

Glad I could help. I'm outta here for the year. See all you DXLiens in 2008.

-------------------------
David Pechacek
AAI Services Textron
dpechacek@sc-aaicorp.com
David.Pechacek@gmail.com
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic DOORS forum.
There are currently 1 users logged in.
The most users ever online was 15 on 15-Jan-2009 at 16:36.
There are currently 0 guests browsing this forum, which makes a total of 1 users using this forum.
You have posted 0 messages to this forum. 0 overall.

FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.