几天帮朋友解决一个技术问题,在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文档的更多相关文章

  1. [转载]linux上用PHP读取WORD文档

    在linux上用PHP读取WORD文档,其实是使用了 antiword程序把word文档转化为txt文档. 再使用php执行系统命令调用而已. 具体操作如下: 1.安装antiword 官方站:htt ...

  2. C#读取Word文档内容代码

    首先要添加引用com组件:然后引用: using Word = Microsoft.Office.Interop.Word; 获取内容: /// /// 读取 word文档 返回内容 /// //// ...

  3. Python读取word文档(python-docx包)

    最近想统计word文档中的一些信息,人工统计的话...三天三夜吧 python 不愧是万能语言,发现有一个包叫做 docx,非常好用,具体查看官方文档:https://python-docx.read ...

  4. C# 设置、删除、读取Word文档背景——基于Spire.Cloud.Word

    Spire.Cloud.Word.Sdk提供了接口SetBackgroudColor().SetBackgroudImage().DeleteBackground().GetBackgroudColo ...

  5. 利用POI工具读取word文档并将数据存储到sqlserver数据库中

    今天实现了利用POI工具读取word文档,并将数据存储到sql数据库中,代码如下: package word; import java.io.File; import java.io.FileInpu ...

  6. Python读取word文档内容

    1,利用python读取纯文字的word文档,读取段落和段落里的文字. 先读取段落,代码如下: 1 ''' 2 #利用python读取word文档,先读取段落 3 ''' 4 #导入所需库 5 fro ...

  7. java中读取word文档里的内容

    package com.cn.peitest.excel.word; import java.io.FileInputStream; import java.io.FileOutputStream; ...

  8. python读取word文档

    周末需要做一个统计word文档字数的问题,刚开始以为很简单,因为之前做过excel表格相关的任务,所以认为利用扩展模块应该比较简单. 通过搜索,确实搜到了一个python操作word的模块,pytho ...

  9. PHP读取word文档

    在PHP中读取和写入WORD文档的代码 <? php // 建立一个指向新COM组件的索引 $word = new COM(”word.application”) or die(”Can't s ...

随机推荐

  1. UIView的层次结构–code

    转:http://blog.dongliwei.cn/archives/uiview-tree-code // Recursively travel down the view tree, incre ...

  2. 移动端web禁止长按选择文字以及弹出菜单

    /*如果是禁用长按选择文字功能,用css*/ * { -webkit-touch-callout:none; -webkit-user-select:none; -khtml-user-select: ...

  3. springboot自定义http反馈状态码

    最近在开发一些http server类型程序,通过spring boot构建一些web程序,这些web程序之间通过http进行数据访问.共享,如下图: 假设现在client发起一次保存数据的请求到se ...

  4. Android中asset文件夹和raw文件夹区别与用法

    *res/raw和assets的相同点: 1.两者目录下的文件在打包后会原封不动的保存在apk包中,不会被编译成二进制. *res/raw和assets的不同点:1.res/raw中的文件会被映射到R ...

  5. windows多线程同步--信号量

    推荐参考博客:秒杀多线程第八篇 经典线程同步 信号量Semaphore   首先先介绍和windows信号量有关的两个API:创建信号量.释放信号量   HANDLE WINAPI CreateSem ...

  6. leetcode笔记:Validate Binary Search Tree

    一. 题目描写叙述 Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is ...

  7. 安装 scws出现 autoconf 需要先安装

    安装在终端操作, curl -OL http://ftpmirror.gnu.org/autoconf/autoconf-latest.tar.gz tar xzf autoconf-latest.t ...

  8. 阿里云的免费型DV SSL证书

    阿里云提供的免费型DV SSL. 证书的说明: [公告]免费新根证书,切入DigiCert PKI体系,兼容性如下操作系统版本IOS 5.0+.Android 2.3.3+.JRE 1.6.5+.WI ...

  9. Linux内核剖析(一)Linux的历史

    Unix操作系统 Unix的由来 汤普逊和里奇最早是在贝尔实验室开发Unix的,此后的10年,Unix在学术机构和大型企业中得到了广泛的应用,当时的UNIX拥有者AT&T公司以低廉甚至免费的许 ...

  10. Spark 论文篇-RDD:一种为内存化集群计算设计的容错抽象(中英双语)

    论文内容: 待整理 参考文献: Resilient Distributed Datasets: A Fault-Tolerant Abstraction for In-Memory Cluster C ...