View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Tas Tas is offline
external usenet poster
 
Posts: 11
Default A fast way to fill cells in Excel

Excel_generator is the main class that will initialize the COM conecxion.
I have a "sheet" member which at the calling of the following method will be
available and pointing to the current active sheet.

void Excel_generator::add_some_data
( int staring_row,
int no_blocks,
int block_row_length,
int block_col_length
)
{
for (int i=0;i<no_blocks;i++)
{
Excel_block blk
(block_row_length,
block_col_length,
Excel_border::THICK,
Excel_coordinate((staring_row+i-1)*block_row_length*2,1));

for (int j=0;j<block_row_length;j++)
{
for (int k=0;k<block_col_length;k++)
{
blk.add_content(j, k, L" Something");
}
}

blk.write_to_sheet(sheet);
}
}

My Excel_block class has as variables(among others) one COleSafeArray
content_array which will store the "data" and a static Range object generated
only once in the actual sheet and than copied by the write_to_sheet method:
void Excel_block::write_to_sheet(CWorksheet &sheet)
{
Excel_coordinate end_coordinate =
Excel_coordinate(start_coordinate.get_row()+get_ro ws()-1,
start_coordinate.get_col()+get_columns()-1);

Excel_coordinate start_coordinate2 =
Excel_coordinate(start_coordinate.get_row()+2*(get _rows()-1)-1,
start_coordinate.get_col());

char *range1=new char[10];
start_coordinate.get_excel_coordinate(range1);
char *range2=new char[10];
end_coordinate.get_excel_coordinate(range2);

CRange range = sheet.get_Range(COleVariant(range1),
COleVariant(range2));

if (block_format)//this is my static range object which is already generated
{
VARIANT copyTo;
V_VT(&copyTo) = VT_DISPATCH;
V_DISPATCH(&copyTo) = range;
block_format.Copy(copyTo); // Here I copy the block to my range!!
}

range.put_Value2(COleVariant(content_array));//and then put my values
content_array.Detach();

delete range1;
delete range2;
}

"RB Smissaert" wrote:

Post the code and we can see if it could be done faster.

RBS

"Tas" wrote in message
...
Hello there,

I have some questions regarding this Excel Automation (I'm not an expert
on
this so please "excuse" if the questions are too trivial)...

I try to build a small application that will generate a very large number
of
columns and rows into Excel sheets (lets say about 200 sheets each one
with
50 000 rows and 100 columns). There is a way to store "Cell" objects in
arrays so I could lets say "create" them into this array and than add the
array to a specific range (similar to the "Text", double, short storage
into
an array...)? Why I'm asking this is because my Cells must have a specific
format (they are somehow structured as "BLOCKS" and this block will repeat
itself for many times) and I need a fast way to "copy" this "block"... I
already did a sample where I'm generatig arround 10 000 "blocks" on a
sheet,
each block containing 3 rows and 15 colums, having each cell with a
different
color and a random border. The time until it was finished was arround 31
seconds... Can I do this faster? Any ideas are more than wellcome.

Thanks,
Tas