Board index » delphi » Speed needed in Word...

Speed needed in Word...

Hi All, and Deborah

First of all three cheers for Deborah for "always" coming up with a very
good answer. People like Deborah really make newsgroups worth while..

Next, I do have a problem that I woul like some help on.
The problem is speed.
I have a Delphi application (Delphi 5) reading a table in an Oracle DB. The
resultset I want printed in a word doc. I can get it to work, but its very
slow. Basically here is what I do:

TheQuery.First;
   j := 2; {start in second row in table, the table in word is defined
beforehand}
   while not TheQuery.EOF do
   begin
     for i := 1 to numberOfColumns do {numberOfColumns is calcualted
earlyer}
     begin
      try
       aTable.Cell(j,i).Range.text := TheQuery.Fields[i-1].AsString;
{aTable is a Word table}
      except on E:EdatabaseError do
       begin
         aTable.Cell(j,i).Range.text := 'INVALID VALUE'; {Sometimes in
Oracle I meet invalid dates...}
       end;
      end;
     end;
     j := j + 1;
     TheQuery.Next;
   end;

I am in other words taking ONE FIELD value at a time and putting it into
word. If my dataset is 1000 records with 4 or 5 fields this takes a long
time. I have tried opening word first, so I can watch (on screen) how fast
(read slow) it goes, and it seems that at first it is quite fast, but it
slows down as it goes along.

Is there ANY way I can get the resultset stuffed into word in one go. I'm
obviously looking for something like:

aTable.Range.text := TheQuery;

Please do post any help here in the group so others can benefit from it, but
please reply at my mail adress too, as I'm not always able to read the
group. Thank you very much in advance.  Thats jens.fu...@lpt.dk
Any good help will indeed be rewarded by a virtual rose.

Regards
Jens

 

Re:Speed needed in Word...


The best way to speed-up word document generation with use of ole, I suggest
outputting your text in a tempory .rtf file and then importing it in word
using ole. I haven't tried it using tables, but I think it is possible with
the new .rtf format.

Maarten Spoek.

Quote
Jens Fudge <Jens.Fu...@lpt.dk> wrote in message

news:888as1$hit4@bornews.borland.com...
Quote
> Hi All, and Deborah

> First of all three cheers for Deborah for "always" coming up with a very
> good answer. People like Deborah really make newsgroups worth while..

> Next, I do have a problem that I woul like some help on.
> The problem is speed.
> I have a Delphi application (Delphi 5) reading a table in an Oracle DB.
The
> resultset I want printed in a word doc. I can get it to work, but its very
> slow. Basically here is what I do:

> TheQuery.First;
>    j := 2; {start in second row in table, the table in word is defined
> beforehand}
>    while not TheQuery.EOF do
>    begin
>      for i := 1 to numberOfColumns do {numberOfColumns is calcualted
> earlyer}
>      begin
>       try
>        aTable.Cell(j,i).Range.text := TheQuery.Fields[i-1].AsString;
> {aTable is a Word table}
>       except on E:EdatabaseError do
>        begin
>          aTable.Cell(j,i).Range.text := 'INVALID VALUE'; {Sometimes in
> Oracle I meet invalid dates...}
>        end;
>       end;
>      end;
>      j := j + 1;
>      TheQuery.Next;
>    end;

> I am in other words taking ONE FIELD value at a time and putting it into
> word. If my dataset is 1000 records with 4 or 5 fields this takes a long
> time. I have tried opening word first, so I can watch (on screen) how fast
> (read slow) it goes, and it seems that at first it is quite fast, but it
> slows down as it goes along.

> Is there ANY way I can get the resultset stuffed into word in one go. I'm
> obviously looking for something like:

> aTable.Range.text := TheQuery;

> Please do post any help here in the group so others can benefit from it,
but
> please reply at my mail adress too, as I'm not always able to read the
> group. Thank you very much in advance.  Thats jens.fu...@lpt.dk
> Any good help will indeed be rewarded by a virtual rose.

> Regards
> Jens

Re:Speed needed in Word...


using rtf would certainly be one way to go but requires file handling and
importing and makes the design of the table less flexible (ie not in Word).
I would send a block of data as one (or several) large text string with
comma/tab or other delimeter per field and CR delimeters per record. You
then ask Word to convert text to tables. Finally format the table as you
like.
See my demos for examples.

--
Regards

Allan Harkness
Check my Word Components at:
http://www.atheroma.freeserve.co.uk/

Other Threads