zoukankan      html  css  js  c++  java
  • [php]在PHP中读取和写入WORD文档的代码

    测试平台windows 

    使用的windows的com主键。

     1 <?  
     2 // 建立一个指向新COM组件的索引  
     3 $word = new COM("word.application") or die("Can't start Word!");  
     4 // 显示目前正在使用的Word的版本号  
     5 //echo "Loading Word, v. {$word->Version}<br>";  
     6 // 把它的可见性设置为0(假),如果要使它在最前端打开,使用1(真)  
     7 // to open the application in the forefront, use 1 (true)  
     8 //$word->Visible = 0;  
     9 
    10 //打?一个文档  
    11 $word->Documents->OPen("d:a.doc");  
    12 //读取文档内容  
    13 
    14 $test= $word->ActiveDocument->content->Text;  
    15 
    16 echo $test;  
    17 echo "<br>";  
    18 //将文档中需要换的变量更换一下  
    19 $test=str_replace("<{变量}>","这是变量",$test);  
    20 echo $test;  
    21 $word->Documents->Add();  
    22 // 在新文档中添加文字  
    23 $word->Selection->TypeText("$test");  
    24 //把文档保存在目录中  
    25 $word->Documents[1]->SaveAs("d:/myweb/comtest.doc");  
    26 // 关闭与COM组件之间的连接  
    27 $word->Quit();  
    28 ?> 

      

  • 相关阅读:
    POJ-2955 Brackets(括号匹配问题)
    NYOJ
    石子合并问题
    hdu 4915 括号匹配+巧模拟
    hdu 4920
    hdu 4911 求逆序对数+树状数组
    hdu 4923 单调栈
    hdu 4930 斗地主恶心模拟
    hdu 4927 组合+公式
    hdu 4925 黑白格
  • 原文地址:https://www.cnblogs.com/tl542475736/p/4466533.html
Copyright © 2011-2022 走看看