热搜:NVER node 开发 php

php将html转入word中

2024-07-25 19:20:01
php将html转入word中

这是经过测试的,这种方法有一点不好,html页面代码要写在php中,不过好歹能运行,看程序

<?php

class word{

function start(){

ob_start();

echo '

xmlns:w="urn:schemas-microsoft-com:office:word"

xmlns="http://www.w3.org/TR/REC-html40">';

}

function save($path)

{

echo "";

$data = ob_get_contents();

}

function wirtefile($fn,$data){

$fp=fopen($fp,$data);

fwrite($fp,$data);

}

}


$html='

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

姓名 性别 年龄 爱好 备注
张三 32 足球
 

  李四 

 

43 篮球
 

';

//批量生成

//for($i=1;$i

$word = new word();

$word->start();

$wordname='个人测试php生成word.doc';

echo $html;

$word->save($wordname);

header('Content-type:application/word');

header('Content-Disposition: attachment; filename='.$wordname.'');

//readfile($wordname);

ob_flush();//每次执行前刷新缓存

flush();


//}

?>