Home > Backend Development > PHP Tutorial > PHP code to export word format data_PHP tutorial

PHP code to export word format data_PHP tutorial

WBOY
Release: 2016-07-13 10:41:19
Original
831 people have browsed it

Share an example of PHP code to export word format files, a PHP class that exports content into word documents, share it with everyone, and interested friends can learn from it.
Contents of this section:
A PHP class to export word documents

Example:

01
02
/**
03
* Class for generating word documents
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
//导出的程序文件
33
//导出 ---start---
34
require SITE_ROOT.'include/word.class.php'; //类文件放在根目录下的include文件夹下
35
$word = new word();
36
//查询数据填入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['wrapinfo'] = $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 .='


49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79
iGo运
单号

  '.$val['box_code'].'
日期 '.date('Y-m-d',$val[create_date]).' 标示
姓名
'.$val[code].'/'.$val['orderid'].'
'.$val['orderinfo']['user_name'].'
件数 3 重量 56.5 品名 咬咬了,吸盘碗,学饮杯,鱼干油
服务
类别
库房服务 服务
要求
合小箱


客户
备注

'.$val['orderinfo']['beizhu'].'



Arrival
Situation



What’s the problem? I can’t get any results
What’s the problem? Not enough fruit










< ;br/>
80
';
81
}
82
$word->start();
83
$filename = 'pick Export manifest.doc';
84
echo $html;
85
$word->save($filename);
86

87
//Type of file
88
header('Content-type: application/word');
89
header('Content-Disposition: attachment; filename="Pick list 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 a word file
A simple example of php exporting a word document
Solution to page view and style issues after php exports Word
Example code for php exporting word format documents
The best way to generate excel or word documents using php Simple method
php generates word document (read database)
The simplest example of php generating word
php uses phpword to generate word Document example
Simple example of php generating word file
php generates code to export word (can include pictures)
php generated Word example
Introduction to php code for exporting web pages into Word documents
php uses phpword to generate word documents
Original reference: http://www.jbxue .com/article/13631.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/699431.htmlTechArticleShare an example of PHP code to export word format files, a PHP class that exports word documents, share it with everyone, Interested friends can refer to it for reference. Contents of this section: A php export w...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template