BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Excel Automation (count used rows for each used column)

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (ActiveX)
View previous topic :: View next topic  
Author Message
Sudesh
Guest





PostPosted: Thu Jan 06, 2005 3:14 pm    Post subject: Excel Automation (count used rows for each used column) Reply with quote



Hello:

How to count used rows of each column in a worksheet?
I am able to count total used columns and rows using "CurrentRegion".

Thanks,
Sudesh



Back to top
BigStew
Guest





PostPosted: Thu Jan 06, 2005 4:24 pm    Post subject: Re: Excel Automation (count used rows for each used column) Reply with quote



Use the Used_Range property of a WorkSheet;
This routine counts the number of non-blank cells in the used range.
Use this as an example.

Stewart

RangePtr Range = WS1->get_UsedRange();
RangePtr cols = Range->get_Columns();
RangePtr rows = Range->get_Rows();

int cellCount = 0;
for (int i = 1; i < rows->Count+1; ++i)
{
for (int j = 1; j < cols->Count+1; ++j)
{
AnsiString a = TVariant(Range->get_Item(TVariant(i),TVariant(j)));
if (!a.IsEmpty()) ++cellCount;
}
}
ShowMessage(cellCount);
"Sudesh" <sudeshc (AT) vfemail (DOT) net> wrote

Quote:
Hello:

How to count used rows of each column in a worksheet?
I am able to count total used columns and rows using "CurrentRegion".

Thanks,
Sudesh






Back to top
Sudesh
Guest





PostPosted: Thu Jan 06, 2005 5:23 pm    Post subject: Re: Excel Automation (count used rows for each used column) Reply with quote



Hi:

So there is no such direct property to give individual row count of a
column?

Counting Rows like this will waste a lot of time.
Consider a case where the largest row count is say 64K but other columns are
with very few rows.
So for each column, iterating through 64K row cells will be too much time
consuming!! Automation speed itself is very slow.

Any other way? (I am using BCB3.0)

Thanks,
Sudesh


Back to top
Mike King
Guest





PostPosted: Thu Jan 06, 2005 6:33 pm    Post subject: Re: Excel Automation (count used rows for each used column) Reply with quote

"Sudesh" <sudeshc (AT) vfemail (DOT) net> wrote

Quote:
Hi:

So there is no such direct property to give individual row count of a
column?

Counting Rows like this will waste a lot of time.
Consider a case where the largest row count is say 64K but other columns
are with very few rows.
So for each column, iterating through 64K row cells will be too much time
consuming!! Automation speed itself is very slow.

Any other way? (I am using BCB3.0)

Thanks,
Sudesh

Yes, automation can be slow so to compensate for that try getting Excel to
do more of the work for you. Excel is really good at number crunching so
let it do and you can just get the results. So just do something like the
following:

65536 - WorksheetFunction.CountBlank(column)



Back to top
Sudesh
Guest





PostPosted: Thu Jan 06, 2005 7:04 pm    Post subject: Re: Excel Automation (count used rows for each used column) Reply with quote

Hi Mike:
Whats the correct syntax fot this in BCB?
I get error "method 'CountBlank' not supported..." with the following.
int x = XLWorkSheet.OleFunction("CountBlank");

Thanks,
Sudesh

"Mike King" <emailMK (AT) excite (DOT) com> wrote
Quote:
So just do something like the following:

65536 - WorksheetFunction.CountBlank(column)





Back to top
Sudesh
Guest





PostPosted: Thu Jan 06, 2005 7:10 pm    Post subject: Re: Excel Automation (count used rows for each used column) Reply with quote

Sorry i mean
int x = XLWorkSheet.OleFunction("CountBlank",col);


Back to top
Mike King
Guest





PostPosted: Thu Jan 06, 2005 7:19 pm    Post subject: Re: Excel Automation (count used rows for each used column) Reply with quote

"Sudesh" <sudeshc (AT) vfemail (DOT) net> wrote

Quote:
Sorry i mean
int x = XLWorkSheet.OleFunction("CountBlank",col);


I use BCB almost everyday and I use Excel quite often but when I try to get
them to talk to one another I just start cry Smile I cheat and write some VBA
code and let it do most of the work. So in other words, I have no clue how
to do it in BCB.



Back to top
Sudesh
Guest





PostPosted: Fri Jan 07, 2005 2:10 am    Post subject: Re: Excel Automation (count used rows for each used column) Reply with quote

No cry for this anymore:-)
int x =
XL.OlePropertyGet("WorksheetFunction").OleFunction("CountBlank",XLRange) ;

Thanks Mika for the clue.
Sudesh

Quote:
I use BCB almost everyday and I use Excel quite often but when I try to
get them to talk to one another I just start cry Smile I cheat and write
some VBA code and let it do most of the work. So in other words, I have
no clue how to do it in BCB.




Back to top
Mike King
Guest





PostPosted: Fri Jan 07, 2005 2:45 pm    Post subject: Re: Excel Automation (count used rows for each used column) Reply with quote

Do you know of a good article/tutorial of how to use IDispatch like you just
did?

"Sudesh" <sudeshc (AT) vfemail (DOT) net> wrote

Quote:
No cry for this anymore:-)
int x =
XL.OlePropertyGet("WorksheetFunction").OleFunction("CountBlank",XLRange) ;

Thanks Mika for the clue.
Sudesh

I use BCB almost everyday and I use Excel quite often but when I try to
get them to talk to one another I just start cry Smile I cheat and write
some VBA code and let it do most of the work. So in other words, I have
no clue how to do it in BCB.






Back to top
Sudesh
Guest





PostPosted: Fri Jan 07, 2005 5:11 pm    Post subject: Re: Excel Automation (count used rows for each used column) Reply with quote

Sorry, my knowledge of COM is also very limited. I hope some expert will
post to help.
Sudesh

"Mike King" <emailMK (AT) excite (DOT) com> wrote

Quote:
Do you know of a good article/tutorial of how to use IDispatch like you
just did?



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (ActiveX) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.