几天帮朋友解决一个技术问题,在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. SharedPreferences 原理 源码 进程间通信 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  2. 常见的机器学习&数据挖掘知识点

    原文:http://blog.csdn.net/heyongluoyao8/article/details/47840255 常见的机器学习&数据挖掘知识点 转载请说明出处 Basis(基础) ...

  3. 递归删除服务器log文件

    ## 进入logs根文件夹 cd /home/admin/logs ## 删除所有的log文件 find . -name "*.log.*" | xargs rm -f

  4. 微软BI 之SSIS 系列 - Merge, Merge Join, Union All 合并组件的使用以及Sort 排序组件同步异步的问题

    开篇介绍 SSIS Data Flow 中有几个组件可以实现不同数据源的数据合并功能,比如 Merger, Merge Join 和 Union All.它们的功能比较类似,同时也比较容易混淆,下面是 ...

  5. MDX Cookbook 03 - MDX 查询中负数,零和空值 NULL 的格式化处理

    FORMAT_STRING 属性在处理计算成员(通常是度量值成员)的时候会经常使用到,比如指定标准 Standard, 货币 Currency 或者 Percent 百分比格式.除此之外,还可以自定义 ...

  6. web,xml中关于filter的使用

    从J2EE1.3开始,Servlet2.3规范中加入了对过滤器的支持.过滤器能够对目标资源的请求和响应进行截取.过滤器的工作方式分为四种,下面让我们分别来看看这四种过滤器的工作方式:1.request ...

  7. 【MySQL】MySQL视图创建、查询。

    视图是指计算机数据库中的视图,是一个虚拟表.关系型数据库中的数据是由一张一张的二维关系表所组成,简单的单表查询只需要遍历一个表,而复杂的多表查询需要将多个表连接起来进行查询任务.对于复杂的查询事件,每 ...

  8. SED单行脚本快速参考(Unix 流编辑器)(转)

    sed.sourceforge.net被封杀,特在此处贴上官方的sed 使用说明文档 SED单行脚本快速参考(Unix 流编辑器) 2005年12月29日 英文标题:USEFUL ONE-LINE S ...

  9. PHP 扩展开发之Zephir

    最近对代码进行性能分析后,发现两个耗时的地方:自动加载文件数太多:参数验证函数调用超过1000次.这也是许多php语言框架面临的问题,所以发展出来诸如Yaf,Swoole,Phalcon这些C语言扩展 ...

  10. Spring Boot 2.0 整合Thymeleaf 模板引擎

    本节将和大家一起实战Spring Boot 2.0 和thymeleaf 模板引擎 1. 创建项目 2. 使用Spring Initlizr 快速创建Spring Boot 应用程序 3. 填写项目配 ...