国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

php生成word兩種方法

2024-05-04 21:48:53
字體:
供稿:網(wǎng)友

1.正常的touch創(chuàng)建word 2.fopen 打開word 3.fwrite 寫入word 并保存

這樣會出現(xiàn)一個(gè)問題,如果寫入的東西里面含有html代碼的話,它將直接寫入word而不是 排版了.

這個(gè)問題,需要在輸出html代碼頭部加一段代碼:

  1. $headert='<html xmlns:o="urn:schemas-microsoft-com:office:office" 
  2.   xmlns:w="urn:schemas-microsoft-com:office:word" 
  3.   xmlns="http://www.w3.org/tr/rec-html40">'; 
  4.   $footer="</html>"

比如你的內(nèi)容是$text;

那么寫入的時(shí)候$text=$header.$text.$footer;

這樣的話fck里面的東西就能按排版的樣式輸出了!

方法一,實(shí)例代碼如下:

  1. <?php 
  2. $wordnew com("word.application"or die("unable to 
  3. create word document"); 
  4. print "loaded word, version{$word->version}n"
  5. $word->visible =0; 
  6. $word->documents->add(); 
  7. //設(shè)置邊距 這個(gè)有錯(cuò)誤 
  8. // $word->selection->agesetup->rightmargin ='3"'; 
  9. //設(shè)置字體 這 
  10. $word->selection->font->name ='helvetica'
  11. //設(shè)置字號 
  12. $word->selection->font->size = 8; 
  13. //設(shè)置顏色 
  14. $word->selection->font->colorindex= 13; //wddarkred= 13 
  15. //輸出到文檔 
  16. $word->selection->typetext("hello world "); 
  17. //開源代碼Vevb.com 
  18. $range = $word->activedocument->range(0,0); 
  19. $table_t =$word->activedocument->tables->add($range,3,4); 
  20. $table_t->cell(1,2)->range->insertafter('aaa'); 
  21. //保存 
  22. //$word->sections->add(1); 
  23. $word->documents[1]->saveas(dirname(__file__)."/create_test.doc"); 
  24. //退出 
  25. $word->quit(); 
  26. ?> 

方法二,實(shí)例代碼如下:

  1. <?php 
  2. class word 
  3. function start() 
  4. ob_start(); 
  5. print'<html xmlns:o="urn:schemas-microsoft-com:office:office" 
  6. xmlns:w="urn:schemas-microsoft-com:office:word" 
  7. xmlns="http://www.w3.org/tr/rec-html40">'; 
  8. function save($path
  9. print "</html>"
  10. $data = ob_get_contents(); 
  11. ob_end_clean(); 
  12. $this->wirtefile ($path,$data); 
  13. function wirtefile ($fn,$data
  14. $fp=fopen($fn,"wb"); 
  15. fwrite($fp,$data); 
  16. fclose($fp); 
  17. ?> 

調(diào)用方法,代碼如下:

  1. $word=new word; 
  2. $word->start(); 
  3. echo $cout
  4. $wordname="word/".time().".doc"
  5. $word->save($wordname);//保存word并且結(jié)束 

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 浏阳市| 曲周县| 夏津县| 泾源县| 儋州市| 当阳市| 阿克陶县| 磐安县| 迭部县| 翼城县| 宝应县| 开封县| 诸城市| 珲春市| 浦东新区| 芦溪县| 藁城市| 雅江县| 定陶县| 农安县| 精河县| 泰兴市| 丹江口市| 平湖市| 惠州市| 武定县| 通州区| 忻州市| 怀宁县| 安阳市| 桦南县| 延津县| SHOW| 定结县| 章丘市| 视频| 孝昌县| 石阡县| 马龙县| 西城区| 蒙自县|