Communicating with Excel trough WxAutomationObject problem Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
greg
Earned some good credits
Earned some good credits
Posts: 111
Joined: Fri Sep 12, 2008 7:17 am

Communicating with Excel trough WxAutomationObject problem

Post by greg » Wed Apr 07, 2010 8:42 am

Hi all,

I am currently working on a application that is able to write Excel files. I have written a small class that is able to communicate with Excel using a wxAutomationObject.

However, I am not able to send all the VBA commands that I want to. For example, I want to add bottom border on cell. The VBA code for this is:

Code: Select all

ActiveCell.Borders(xlEdgeBottom).LineStyle = xlContinuous 
So I tried using the following code in wxWidgets:

Code: Select all

// excelObj is a wxAutomationObject with an excel instance
excelObj.PutProperty("ActiveCell.Borders(xlEdgeBottom).LineStyle", "1");


This code doesn't do anything, the cells bottom border isn't changed at all. The strange thing is that other VBA commands work just fine (bordering all cell's edges), like this one:

Code: Select all

excelObj.PutProperty("ActiveCell.Borders.LineStyle", "1");

Can anyone tell me what I am doing wrong with the border command?

Thanks,
Regards
Greg

User avatar
doublemax
Moderator
Moderator
Posts: 13988
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax » Wed Apr 07, 2010 9:11 am

I've never used wxAutomationObject (or Excel for that matter), so i can only make a wild guess here.

Try replacing "xlEdgeBottom" with its integer value "9". (I googled the value)
Use the source, Luke!

greg
Earned some good credits
Earned some good credits
Posts: 111
Joined: Fri Sep 12, 2008 7:17 am

Post by greg » Thu Apr 08, 2010 6:40 am

Sorry DoubleMax
It doesn't work properly?
Is any another idea?
Regards
Greg

timg
Earned some good credits
Earned some good credits
Posts: 148
Joined: Mon Jan 23, 2006 6:52 pm

Post by timg » Fri Apr 09, 2010 5:00 pm

From what I've seen, the wxAutomation stuff doesn't work well with code like this.

One thing you could try is to get the Border object and then apply the property to that.

Code: Select all


 excelObj.GetObject(borderObj, "ActiveCell.Borders", 1, "9"); // 9 = xlEdgeBottom

 borderObj.PutProperty("LineStyle", "1");

Not sure on how to pass the 9 for xlEdgeBottom - might need to remove the quotes, or you could make a wxVariant and pass that instead.

greg
Earned some good credits
Earned some good credits
Posts: 111
Joined: Fri Sep 12, 2008 7:17 am

Post by greg » Mon Apr 12, 2010 6:45 am

Thanks timg for Your advice.
Now It works perfect!
Regards
Greg

Post Reply