Home > Back-end >  Spot bamboo come in: how about template page, circulation generated code in multiple records to a wo
Spot bamboo come in: how about template page, circulation generated code in multiple records to a wo

Time:10-28

North Pole: http://topic.csdn.net/u/20101220/21/fda21ce0-5dec-4eec-aae2-3b52714c4c84.html
(hope your give me back my above 200 points)

I posted an answer for yourself, here is so cold and cheerless, I have not used the DELPHI for 2 years and now with occasionally encounter problems, wanted to be lazy, seem to be self-reliant, hope your give this back to me, at the same time, online similar examples also have no, I wish the following code is useful to future generations:

Procedure TPrintWord. PrintWords (SQLSTR: string);
Var
TemplateName: OleVariant;
NewTemplate: OleVariant;
ItemIndex: OleVariant;
VSelection: wordSelection;
VBookMark: BookMark;
VTable: Table;
CopyTable: Table;
I: Integer;
J: integer;
Rend: OleVariant;
Myrange: range;
Rs: tadoquery;
The begin

CallFormCreate;
//structure print template file name the full path
TemplateName:=folderName + 'cld4. Dot';
NewTemplate:=False;

Try
WordApp. The Connect ();
Except,
MessageDlg (' your computer has not install Microsoft Office packaged or higher version! ', mtError, [mbOK], 0);
Abort.
end;

//to specify the template file to create a new Word document
WordApp. Documents. AddOld (templateName newTemplate);
VSelection:=wordApp. Selection;
Rs:=connect. Opentable (SQLSTR);
J:=1;
ItemIndex:=1;
WordDocument1. ConnectTo (WordApp. Documents. The Item (ItemIndex));
//copy the first document template
WordApp. ActiveDocument. Select;
WordApp. Selection. Copy;


While not rs. Eof do
The begin
Frm_wait. ProgressBar1. StepBy (j);
//get the document table 1
VTable:=wordApp ActiveDocument. Tables. The Item ((j - 1) * 11 + 1);
VTable. Cell (1, 2). The Range, the Text:=rs. FieldByName (' st_name). The Text;
VTable. Cell (2, 2). The Range, the Text:=rs. FieldByName (" class_name "). The Text;
////in the document list
2VTable:=wordApp ActiveDocument. Tables. The Item ((j - 1) * 11 + 2);
VTable. Cell (1, 1). The Range, the Text:=datetostr (date);


If jThe begin//the ends of the cursor, and then paste the
Worddocument1. Range. InsertAfter (' + # 13);
Rend:=worddocument1. Range. End_ - 1;
Myrange:=WordDocument1 Range (rend, rend);
Myrange. Paste;
end;
Rs. The Next;
Inc (j);
end;
WordApp. Visible:=true;
WordApp. WindowState:=1;
//print preview
//wordApp. PrintPreview:=CheckBox2. Checked;

//print immediately
//if CheckBox3. Checked then
//wordApp. PrintOutOld;

WordApp. Disconnect ();
Frm_wait. Close;
end;
Procedure TPrintWord. CallFormCreate ();
Var
TemplateName: String;
FileStream: TResourceStream;
The begin
//get the application directory
FolderName:=ExtractFilePath (Application. ExeName);

If not FileExists (folderName + 'template. Res') then
The begin
MessageDlg (' error: could not find template resource file template. Res. ', mtError, [mbOK], 0);
exit;
end;

//construct WORD print template file name the full path
TemplateName:=folderName + 'cld4. Dot';
//for resource files in the "process single print template
"FileStream:=TResourceStream. Create (hInstance, 'cld4', 'WORD');

If not FileExists (templateName) then
The begin
//removed files
FileStream. SaveToFile (templateName);
//release
FileStream. Free;
end;

end;

CodePudding user response:

Can achieve more templates, but ran into a problem, will produce extra blank page?

CodePudding user response:

solved, ha ha, but very grateful to you advice! Otherwise you can't finish this thing!
  • Related