01.
<html>
02.
<head>
03.
<title>ThaiCreate.Com PHP Word.Application Tutorial</title>
04.
</head>
05.
<body>
06.
<?
07.
$wdAlignParagraphCenter
=
"1"
;
08.
$wdAlignParagraphRight
=
"2"
;
09.
10.
$Wrd
=
new
COM(
"Word.Application"
);
11.
$DocName
=
"MyDoc/MyWord.doc"
;
12.
$Wrd
->Application->Visible = False;
13.
14.
15.
16.
$WrdDoc
=
$Wrd
->Documents->Open(
realpath
(
"thaicreate.dot"
));
17.
18.
$MyRange1
=
$WrdDoc
->Paragraphs->Add->Range;
19.
$MyRange1
->ParagraphFormat->Alignment =
$wdAlignParagraphCenter
;
20.
$MyRange1
->Font->Name =
"Verdana"
;
21.
$MyRange1
->Font->Size =
"20"
;
22.
$MyRange1
->Font->Bold = True;
23.
$MyRange1
->InsertBefore(
"Customer Report"
.
chr
(13));
24.
25.
include
"../../connect.php"
;
26.
$strSQL
=
"SELECT * FROM register"
;
27.
$objQuery
= mysql_query(
$strSQL
);
28.
$intRows
= mysql_num_rows(
$objQuery
);
29.
30.
$MyRange2
=
$WrdDoc
->Paragraphs->Add->Range;
31.
$MyRange2
->Font->Size =
"10"
;
32.
$objTable
=
$Wrd
->ActiveDocument->Tables->Add(
$MyRange2
,
$intRows
+1,6,1,2);
33.
34.
35.
$objTable
->Cell(1,1)->Range->InsertAfter(
"CustomerID"
);
36.
$objTable
->Cell(1,1)->Range->Bold = True;
37.
$objTable
->Cell(1,1)->Range->ParagraphFormat->Alignment = 1;
38.
39.
$objTable
->Cell(1,2)->Range->InsertAfter(
"Name"
);
40.
$objTable
->Cell(1,2)->Range->Bold = True;
41.
$objTable
->Cell(1,2)->Range->ParagraphFormat->Alignment = 1;
42.
43.
$objTable
->Cell(1,3)->Range->InsertAfter(
"Email"
);
44.
$objTable
->Cell(1,3)->Range->Bold = True;
45.
$objTable
->Cell(1,3)->Range->ParagraphFormat->Alignment = 1;
46.
47.
$objTable
->Cell(1,4)->Range->InsertAfter(
"CountryCode"
);
48.
$objTable
->Cell(1,4)->Range->Bold = True;
49.
$objTable
->Cell(1,4)->Range->ParagraphFormat->Alignment = 1;
50.
51.
$objTable
->Cell(1,5)->Range->InsertAfter(
"Budget"
);
52.
$objTable
->Cell(1,5)->Range->Bold = True;
53.
$objTable
->Cell(1,5)->Range->ParagraphFormat->Alignment = 1;
54.
55.
$objTable
->Cell(1,6)->Range->InsertAfter(
"Used"
);
56.
$objTable
->Cell(1,6)->Range->Bold = True;
57.
$objTable
->Cell(1,6)->Range->ParagraphFormat->Alignment = 1;
58.
59.
60.
61.
$intRows
= 1;
62.
while
(
$result
= mysql_fetch_array(
$objQuery
))
63.
{
64.
$intRows
++;
65.
$objTable
->Cell(
$intRows
,1)->Range->InsertAfter(
$result
[
"re_id"
]);
66.
$objTable
->Cell(
$intRows
,1)->Range->ParagraphFormat->Alignment = 1;
67.
68.
$objTable
->Cell(
$intRows
,2)->Range->InsertAfter(
$result
[
"re_name"
]);
69.
$objTable
->Cell(
$intRows
,2)->Range->ParagraphFormat->Alignment = 0;
70.
71.
$objTable
->Cell(
$intRows
,3)->Range->InsertAfter(
$result
[
"Email"
]);
72.
$objTable
->Cell(
$intRows
,3)->Range->ParagraphFormat->Alignment = 0;
73.
74.
$objTable
->Cell(
$intRows
,4)->Range->InsertAfter(
$result
[
"CountryCode"
]);
75.
$objTable
->Cell(
$intRows
,4)->Range->ParagraphFormat->Alignment = 1;
76.
77.
$objTable
->Cell(
$intRows
,5)->Range->InsertAfter(number_format(
$result
[
"Budget"
],2));
78.
$objTable
->Cell(
$intRows
,5)->Range->ParagraphFormat->Alignment = 2;
79.
80.
$objTable
->Cell(
$intRows
,6)->Range->InsertAfter(number_format(
$result
[
"Used"
],2));
81.
$objTable
->Cell(
$intRows
,6)->Range->ParagraphFormat->Alignment = 2;
82.
}
83.
84.
$MyRange3
=
$WrdDoc
->Paragraphs->Add->Range;
85.
$MyRange3
->ParagraphFormat->Alignment =
$wdAlignParagraphRight
;
86.
$MyRange3
->Font->Name =
"Verdana"
;
87.
$MyRange3
->Font->Size =
"10"
;
88.
$MyRange3
->InsertBefore(
chr
(13).
chr
(13).
chr
(13).
" ................................Manager"
.
chr
(13).
date
(
"Y-m-d H:i:s"
));
89.
90.
91.
$WrdDoc
->SaveAs(
realpath
(
$DocName
));
92.
$Wrd
->Application->Quit;
93.
$Wrd
= null;
94.
?>
95.
Word Created <a href=
"<?=$DocName?>"
>Click here</a> to Download.
96.
</body>
97.
</html>