PHP在linux读取word文档
几天帮朋友解决一个技术问题,在Linux下,将word文档中的内容读取,然后使用正则匹配,拼成sql入库
查阅了外文资料和google之后,步骤如下:
#wget http://www.winfield.demon.nl/linux/antiword-0.37.tar.gz
#tar zxvf antiword-0.37.tar.gz
#cd antiword-0.37
#make
#make install
antiword
cp /root/bin/*antiword /usr/local/bin/
mkdir /usr/share/antiword
cp -R /root/.antiword/* /usr/share/antiword/
chmod 777 /usr/local/bin/*antiword
chmod 755 /usr/share/antiword/*
安装完成之后,如果要在web上查看的话,需要使用root执行 make global_install
<?php
header("Content-type: text/html; charset=utf-8"); $filename = 'test.doc';
#$content = shell_exec('antiword '.$filename);
$content = shell_exec('antiword -mUTF-8 '.$filename); echo '<pre>';
print_r ($content);
echo '</pre>';
#coding=utf-8
#usage python <script_name> <docFilePath>
#pip install python-docx [安装一下扩展库]
import sys
import os from docx import Document #获取当前脚本得名称
argv0_list = sys.argv[0].split("\\");
script_name = argv0_list[len(argv0_list) - 1];
usage = "\n Usage python <"+script_name+"> <docFilePath>" if len(sys.argv) != 2:
print "Warning:\n docx file is empty" + usage
sys.exit()
docx_path = sys.argv[1]
if not os.path.exists(docx_path):
print "Warning:\n docx file is not exist" + usage
sys.exit() #打开文档
document = Document(docx_path)
#读取每段资料
l = [ paragraph.text.encode('utf8') for paragraph in document.paragraphs];
#输出并观察结果,也可以通过其他手段处理文本即可
for i in l:
print i
#读取表格材料,并输出结果
tables = [table for table in document.tables];
for table in tables:
for row in table.rows:
for cell in row.cells:
print cell.text.encode('utf8'),'\t',
PHP在linux读取word文档的更多相关文章
- [转载]linux上用PHP读取WORD文档
在linux上用PHP读取WORD文档,其实是使用了 antiword程序把word文档转化为txt文档. 再使用php执行系统命令调用而已. 具体操作如下: 1.安装antiword 官方站:htt ...
- C#读取Word文档内容代码
首先要添加引用com组件:然后引用: using Word = Microsoft.Office.Interop.Word; 获取内容: /// /// 读取 word文档 返回内容 /// //// ...
- Python读取word文档(python-docx包)
最近想统计word文档中的一些信息,人工统计的话...三天三夜吧 python 不愧是万能语言,发现有一个包叫做 docx,非常好用,具体查看官方文档:https://python-docx.read ...
- C# 设置、删除、读取Word文档背景——基于Spire.Cloud.Word
Spire.Cloud.Word.Sdk提供了接口SetBackgroudColor().SetBackgroudImage().DeleteBackground().GetBackgroudColo ...
- 利用POI工具读取word文档并将数据存储到sqlserver数据库中
今天实现了利用POI工具读取word文档,并将数据存储到sql数据库中,代码如下: package word; import java.io.File; import java.io.FileInpu ...
- Python读取word文档内容
1,利用python读取纯文字的word文档,读取段落和段落里的文字. 先读取段落,代码如下: 1 ''' 2 #利用python读取word文档,先读取段落 3 ''' 4 #导入所需库 5 fro ...
- java中读取word文档里的内容
package com.cn.peitest.excel.word; import java.io.FileInputStream; import java.io.FileOutputStream; ...
- python读取word文档
周末需要做一个统计word文档字数的问题,刚开始以为很简单,因为之前做过excel表格相关的任务,所以认为利用扩展模块应该比较简单. 通过搜索,确实搜到了一个python操作word的模块,pytho ...
- PHP读取word文档
在PHP中读取和写入WORD文档的代码 <? php // 建立一个指向新COM组件的索引 $word = new COM(”word.application”) or die(”Can't s ...
随机推荐
- html5中页面拨打电话的方式
<a href="tel:18688888888">拨号</a> <a href="sms:18688888888">发短信 ...
- mysql从库Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'报错处理
年后回来查看mysql运行状况与备份情况,登录mysql从库查看主从同步状态 mysql> show slave status\G; *************************** . ...
- Btrace使用教程
下载 下载链接:https://github.com/btraceio/btrace/releases/tag/v1.3.9 安装及环境配置 1.下载一个压缩包 2.解压 3.配置环境变量 sudo ...
- 理解HTTP之keep-alive
理解HTTP之keep-alive 在前面一篇文章中讲了TCP的keepalive,这篇文章再讲讲HTTP层面keep-alive.两种keepalive在拼写上面就是不一样的,只是发音一样,于是乎大 ...
- iOS开发-获取设备型号信息
开发中有的时候查看设计统计数据,或者通过日志查看错误信息,这个时候我们就需要获取获取设备信息,看下关于设备有几种方法: NSLog(@"%@",[[UIDevice current ...
- 【ZH奶酪】如何用sklearn计算中文文本TF-IDF?
1. 什么是TF-IDF tf-idf(英语:term frequency–inverse document frequency)是一种用于信息检索与文本挖掘的常用加权技术.tf-idf是一种统计方法 ...
- 【转】苹果App Store审核指南中文翻译(更新)
(注:<苹果应用商店审核指南>中文翻译最近一次更新为2013-03-04,文中红色部分是相对于2013-03-04版本的新增内容,绿色部分代表更改的内容,蓝色表示苹果相关官方文档的链接.) ...
- 【tp5】ThinkCMF5框架,配置使其支持不同终端PC/WAP/Wechat能加载不同配置和视图
1.版本 5.0.18 2.在data/conf/ 新增config.php文件,内容如下: <?php //ThinkCMF5区别不同客户端加载不同配置文件和模块.视图 $default_mo ...
- wine qq 2013 for linux deb包 Ubuntu 64位兼容
2013-08-08 Wine 1.6,如果您想体验下该版本的wine,目前可以通过ppa进行安装: sudo add-apt-repository ppa:ubuntu-wine/ppa ...
- SNF快速开发平台MVC-甘特图
上个月做了CS框架的甘特图样例,本月框架组人员又实现了BS的甘特图效果,而且效果也很不错哦 图形框可以直接拖拽调整时长时间: 新增节点: