Share the code for exporting a file in the word format in php, a php class for exporting the file content as a word document, and share it with you. For more information, see.
Content of this section:
A class for exporting Word documents in php
Example:
01
<? Php
02
/**
03
* Word document generation class
04
* By www.jbxue.com
05
*/
06
Class word
07
{
08
Function start ()
09
{
10
Ob_start ();
11
Echo '12
Xmlns: w = "urn: schemas-microsoft-com: office: word"
13
Xmlns = "http://www.w3.org/TR/REC-html40"> ';
14
}
15
Function save ($ path)
16
{
17
Echo "18
$ Data = ob_get_contents ();
19
Ob_end_clean ();
20
21
$ This-> wirtefile ($ path, $ data );
22
}
23
24
Function wirtefile ($ fn, $ data)
25
{
26
$ Fp = fopen ($ fn, "wb ");
27
Fwrite ($ fp, $ data );
28
Fclose ($ fp );
29
}
30
}
31
32
// Export the program file
33
// Export --- start ---
34
Require SITE_ROOT. 'include/word. class. php'; // put the class file in the include folder under the root directory
35
$ Word = new word ();
36
// Enter the query data in word.
37
$ Result = $ db-> query ("SELECT * FROM". DB_PRE. "box where status = '9' order by boxid DESC ");
38
While ($ r = $ db-> fetch_array ($ result ))
39
{
40
$ R ['orderinfo'] = $ db-> get_one ("SELECT * FROM ". DB_PRE. "order where orderid = '". $ r ['orderid']. "'");
41
$ R ['rapinfo'] = $ db-> get_one ("SELECT * FROM ". DB_PRE. "wrap where orderid = '". $ r ['orderid']. "'");
42
$ Boxlist [] = $ r;
43
}
44
45
Foreach ($ boxlist as $ key => $ val ){
46
$ Order-> UPCAbarcode ($ val ['box _ Code']);
47
48
$ Html. = '<table width = 800 cellpadding = "6" align = "center" cellspacing = "5" bgcolor = "#000000">
49
<Tr bgcolor = "White" height = "50">
50
<Td width = 80 style = "border: 1px solid # c8c8c8;"> iGo <br/> Ticket No. </td>
51
<Td width = 300 style = "border: 1px solid # c8c8c8;"> <br/> & nbsp ;'. $ val ['box _ Code']. '</td>
52
<Td width = 60 style = "border: 1px solid # c8c8c8;"> date </td>
53
<Td width = 100 style = "border: 1px solid # c8c8c8;"> '. date ('Y-m-d', $ val [create_date]). '</td>
54
<Td width = 100 style = "border: 1px solid # c8c8c8;"> name <br/> </td>
55
<Td width = 240 style = "border: 1px solid # c8c8c8;"> '. $ val [code]. '/'. $ val ['orderid']. '<br/> '. $ val ['orderinfo'] ['user _ name']. '</td>
56
</Tr>
57
<Tr bgcolor = "White">
58
<Td width = 60 style = "border: 1px solid # c8c8c8;"> Number of parts </td>
59
<Td width = 40 style = "border: 1px solid # c8c8c8;"> 3 </td>
60
<Td width = 40 style = "border: 1px solid # c8c8c8;"> weight </td>
61
<Td width = 150 style = "border: 1px solid # c8c8c8;"> 56.5 </td>
62
<Td width = 40 style = "border: 1px solid # c8c8c8;"> product name </td>
63
<Td width = 390 style = "border: 1px solid # c8c8c8;"> bit, suction bowl, xueyin cup, dried fish oil </td>
64
</Tr>
65
<Tr bgcolor = "White">
66
<Td width = 110 style = "border: 1px solid # c8c8c8;"> service <br/> Category </td>
67
<Td width = 200 style = "border: 1px solid # c8c8c8;"> warehouse service </td>
68
<Td width = 110 style = "border: 1px solid # c8c8c8;"> service <br/> requirements </td>
69
<Td width = 280 style = "border: 1px solid # c8c8c8;"> small box </td>
70
</Tr>
71
<Tr bgcolor = "White">
72
<Td width = 120 style = "border: 1px solid # c8c8c8; "> <br/> customer <br/> remarks <br/> </td>
73
<Td width = 580 style = "border: 1px solid # c8c8c8;"> '. $ val ['orderinfo'] ['beizhu'].' </td>
74
</Tr>
75
<Tr bgcolor = "White">
76
<Td width = 120 style = "border: 1px solid # c8c8c8; "> <br/> arrival status <br/> </td>
77
<Td width = 580 style = "border: 1px solid # c8c8c8;"> what is the problem? If not, <br/> what is the problem? If not, <br/> what is the problem? If not, <br/> </td>
78
</Tr>
79
</Table> <br/>
80
';
81
}
82
$ Word-> start ();
83
$ Filename = 'picking ticket export .doc ';
84
Echo $ html;
85
$ Word-> save ($ filename );
86
87
// File type
88
Header ('content-type: application/word ');
89
Header ('content-Disposition: attachment; filename = "Picking ticket export .doc "');
90
Readfile ($ filename );
91
Ob_flush ();
92
Flush ();
93
Exit ();
94
// Export word -- end --
Articles you may be interested in:
A simple example of php exporting word Files
Simple Example of php Word document Export
Php: how to solve the page view and style problems after exporting Word
Php export the instance code of the word format document
Php is the easiest way to generate excel or Word documents
Php generates Word documents (read database)
The simplest example of php word generation
Example of using phpword to generate a Word document in php
A simple example of generating a word file using php
Php code for generating and exporting word (including images)
Example of Generating word in php
Introduction to php code for exporting webpages as Word documents
Php uses phpword to generate WORD Documents
Reference: http://www.jbxue.com/article/13631.html