How to import records from database into Word in Delphi
No.: QA004684
Creation date: May 18, 2003 Last modification date: May 20, 2003
Category:
Delphi - database
pq :
The system I use is win2000, delphi is version 6.0, and word2000
Question: In Delphi, we need to import the records from the database into Word and create them in the form of tables. We need to display two tables side by side on one page in Word. How to achieve this?
answer :
My reply to this question is this: I have dealt with similar problems, but I poured the data into TXT. It's also drawn in table form, but I think it's the same.
The important thing is that you set a variable to be of type TStrings
like:
var
TXTstr:TStrings;
begin
TXTstr := TStringList.Create;
TXTstr.Append('────────┬────┬─────┬─────┬─────'); //Line 0
TXTstr.Append('Name│'); //First line
.... //Get value from database to TXTADO
while not TXTADO.Eof do
Begin
TXTstr[1]:=TXTstr[1]+format('%8s',[TXTADO.FieldByName('XM').Asstring])+'│';
TXTADO.next;
end;
Moderator's note: Two steps are required to complete this question. One is to read the data in the database, and the other is to use Automation technology to control Word to complete typesetting and save it as a Word file or print it. The first step has been introduced above. For the second step, please refer to: QA003053 "Use Delphi4.0 to directly control Word97".
loga 's opinion:
If it is VB, you can open the recorded macro in WORD, then manually add database records, and VBA can automatically write the code. A glimpse is for reference only.
Related questions:
QA000836 "How to know the command set of Excel97"
QA001381 "How to control Word and Excel in VB"
QA003819 "How to add text to Word using OLE"
This question was answered by Huang Wei .