将Doc或者Docx文档处理成html的代码逻辑;统计word中的字数,段数,句数,读取word中文档内容的代码逻辑

将Doc或者Docx文档处理成html的代码逻辑

下面是maven的配置代码:

<!-- 文档处理所需的jar的依赖 -->
		<dependency>
			<groupId>commons-io</groupId>
			<artifactId>commons-io</artifactId>
			<version>2.4</version>
		</dependency>

		<dependency>
		    <groupId>org.apache.poi</groupId>
		    <artifactId>poi-examples</artifactId>
		    <version>3.9</version>
		</dependency>

		<dependency>
		    <groupId>org.apache.poi</groupId>
		    <artifactId>poi-scratchpad</artifactId>
		    <version>3.9</version>
		</dependency>

		<dependency>
		    <groupId>fr.opensagres.xdocreport</groupId>
		    <artifactId>org.apache.poi.xwpf.converter.xhtml</artifactId>
		    <version>1.0.4</version>
		</dependency>
		<dependency>
		    <groupId>fr.opensagres.xdocreport</groupId>
		    <artifactId>org.apache.poi.xwpf.converter.core</artifactId>
		    <version>1.0.4</version>
		</dependency>

		<dependency>
		    <groupId>org.apache.poi</groupId>
		    <artifactId>poi-ooxml</artifactId>
		    <version>3.9</version>
		</dependency>
		<dependency>
		    <groupId>org.apache.poi</groupId>
		    <artifactId>poi</artifactId>
		    <version>3.9</version>
		</dependency>
		<dependency>
		    <groupId>org.apache.poi</groupId>
		    <artifactId>poi-ooxml-schemas</artifactId>
		    <version>3.9</version>
		</dependency>
		<dependency>
		    <groupId>org.apache.xmlbeans</groupId>
		    <artifactId>xmlbeans</artifactId>
		    <version>2.3.0</version>
		</dependency>
		<dependency>
		    <groupId>org.apache.poi</groupId>
		    <artifactId>ooxml-schemas</artifactId>
		    <version>1.1</version>
		</dependency>
		<!-- 文档处理所需的jar的依赖 -->

将word处理成html的代码:

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.converter.PicturesManager;
import org.apache.poi.hwpf.converter.WordToHtmlConverter;
import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.hwpf.usermodel.Picture;
import org.apache.poi.hwpf.usermodel.PictureType;
import org.apache.poi.xwpf.converter.core.BasicURIResolver;
import org.apache.poi.xwpf.converter.core.FileImageExtractor;
import org.apache.poi.xwpf.converter.core.FileURIResolver;
import org.apache.poi.xwpf.converter.xhtml.XHTMLConverter;
import org.apache.poi.xwpf.converter.xhtml.XHTMLOptions;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.poi.xwpf.usermodel.XWPFTableCell;
import org.apache.poi.xwpf.usermodel.XWPFTableRow;
import org.w3c.dom.Document;
import com.sun.org.apache.xalan.internal.xsltc.compiler.Template;

import cn.com.hbny.docdetection.entity.ResourcesWord;
import cn.com.hbny.docdetection.server.ExtendedServerConfig;
import cn.com.hbny.docdetection.utils.Pinyin4jUtils.PinyinType;

/**
 * @brief ReadWordUtils.java 文档处理对应的工具类
 * @attention
 * @author toto
 * @date 2017年3月3日
 * @note begin modify by 涂作权  2017年3月3日  原始创建
 */
public final class ReadWordUtils {
	private static Logger logger = Logger.getLogger(ReadWordUtils.class);
	protected static final String CHARSET_UTF8 = "UTF-8";
	private static String  tempImagePath = "";

	/**
	 * 读取docx
	 * @throws Exception
	 */
	public static ResourcesWord readDocx(String path) throws Exception {
		int paragNum = 0; // 段落的个数
		int sentenceNum = 0; // 句子个数
		int wordNum = 0; // 字体个数
		StringBuffer content = new StringBuffer();
		ResourcesWord resourcesWord = new ResourcesWord();
		InputStream is = new FileInputStream(path);
		XWPFDocument doc = new XWPFDocument(is);
		List<XWPFParagraph> paras = doc.getParagraphs();
		for (XWPFParagraph para : paras) {
			// 当前段落的属性
			if (!StringUtils.isEmpty(para.getText())) {
				paragNum++;
				sentenceNum += para.getText().replace("\r\n", "").trim().split("。").length;
				content.append(para.getText());
			}
		}
		// 获取文档中所有的表格
		List<XWPFTable> tables = doc.getTables();
		List<XWPFTableRow> rows;
		List<XWPFTableCell> cells;
		for (XWPFTable table : tables) {
			// 表格属性
			// 获取表格对应的行
			rows = table.getRows();
			for (XWPFTableRow row : rows) {
				// 获取行对应的单元格
				cells = row.getTableCells();
				for (XWPFTableCell cell : cells) {
					content.append(cell.getText());
				}
			}

			/*
			 * MongoDBUtils mongoDb = new MongoDBUtils("javadb"); DBObject dbs =
			 * new BasicDBObject(); dbs.put("name", "创新性"); //分类
			 * dbs.put("major", "医疗"); //专业 dbs.put("content",
			 * content.toString().trim()); dbs.put("paragNum", paragNum);
			 * dbs.put("sentenceNum", sentenceNum); dbs.put("wordNum", wordNum);
			 * mongoDb.insert(dbs, "javadb");
			 */
		}

		// 得到全部内容的字数
		wordNum += content.toString().trim().length();
		resourcesWord.setContent(content.toString());
		resourcesWord.setParagNum(paragNum);
		resourcesWord.setSentenceNum(sentenceNum);
		resourcesWord.setWordNum(wordNum);
		close(is);
		return resourcesWord;
	}

	/**
	 * 读取doc文件的内容
	 *
	 * @throws IOException
	 */
	public static ResourcesWord readDoc(String path) throws IOException {
		int paragNum = 0; // 段落的个数
		int sentenceNum = 0; // 句子个数
		int wordNum = 0; // 字体个数
		ResourcesWord resourcesWord = new ResourcesWord();
		StringBuffer content = new StringBuffer();
		try {
			File f = new File(path);
			FileInputStream is = new FileInputStream(f);
			WordExtractor ex = new WordExtractor(is);// is是WORD文件的InputStream
			String[] paragraph = ex.getParagraphText();
			for (int i = 0; i < paragraph.length; i++) {

				paragNum++;
				System.out.println("Paragraph " + (i + 1) + " : " + paragraph[i]);
				sentenceNum += paragraph[i].replace("\r\n", "").trim().split("。").length;
				wordNum += paragraph[i].trim().length();
				content.append(paragraph[i].trim());
			}
			System.out.println("段落:" + paragNum);
			System.out.println("句子:" + sentenceNum);
			System.out.println("字体:" + wordNum);

			resourcesWord.setContent(content.toString());
			resourcesWord.setParagNum(paragNum);
			resourcesWord.setSentenceNum(sentenceNum);
			resourcesWord.setWordNum(wordNum);
			/*
			 * MongoDBUtils mongoDb = new MongoDBUtils("javadb"); DBObject dbs =
			 * new BasicDBObject(); dbs.put("name", "创新性"); //分类
			 * dbs.put("major", "医疗"); //专业 dbs.put("content",
			 * content.toString()); dbs.put("paragNum", paragNum);
			 * dbs.put("sentenceNum", sentenceNum); dbs.put("wordNum", wordNum);
			 * mongoDb.insert(dbs, "javadb");
			 */
			is.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return resourcesWord;
	}

	/**
	 * \brief doc转换成html,并返回输出的相对路径
	 * @param filePath                  :要转换的doc文档
	 * @param outPutFilePath                :文档输出的位置
	 * @attention
	 * @author toto
	 * @throws IOException
	 * @throws FileNotFoundException
	 * @throws ParserConfigurationException
	 * @date 2017年2月27日
	 * @note  begin modify by 涂作权  2017年2月27日   原始创建
	 */
	public static String doc2Html(
			String filePath,
			final String outPutFilePath)
			throws TransformerException, IOException, ParserConfigurationException {

        HWPFDocument wordDocument = new HWPFDocument(new FileInputStream(filePath));
        WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(
        		DocumentBuilderFactory
        		.newInstance()
        		.newDocumentBuilder()
        		.newDocument());

        wordToHtmlConverter.setPicturesManager(new PicturesManager() {
            public String savePicture(byte[] content, PictureType pictureType, String suggestedName, float widthInches, float heightInches) {
            	//File file = new File(outPutFilePath);
                //String name = file.getName();
                tempImagePath = outPutFilePath.substring(0,outPutFilePath.indexOf(".html")) + File.separator;

                File imageFolder = new File(tempImagePath);
                if (!imageFolder.exists()) {
					try {
						FileUtils.forceMkdir(imageFolder);
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
                String newTempImagePath = imageFolder.getPath().replace(imageFolder.getParentFile().getPath() + File.separator, "");
            	return newTempImagePath + File.separator + suggestedName;
            }
        });
        wordToHtmlConverter.processDocument(wordDocument);
        // 保存图片
        List<Picture> pics = wordDocument.getPicturesTable().getAllPictures();
        if (pics != null) {
            for (int i = 0; i < pics.size(); i++) {
                Picture pic = (Picture) pics.get(i);
                try {
                	File picOutFolder = new File(tempImagePath + File.separator);
                	if (!picOutFolder.exists()) {
						picOutFolder.mkdirs();
					}
                    pic.writeImageContent(new FileOutputStream(tempImagePath + File.separator + pic.suggestFullFileName()));
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
            }
        }
        Document htmlDocument = wordToHtmlConverter.getDocument();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        DOMSource domSource = new DOMSource(htmlDocument);
        StreamResult streamResult = new StreamResult(out);  

        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer serializer = tf.newTransformer();
        serializer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
        serializer.setOutputProperty(OutputKeys.INDENT, "yes");
        serializer.setOutputProperty(OutputKeys.METHOD, "html");
        serializer.transform(domSource, streamResult);
        out.close();
        writeFile(new String(out.toByteArray()), outPutFilePath);
        return gainRelativePathByOutputPath(outPutFilePath);
    }

	/**
     * 将docx格式的word转换为html格式的文档
     *
     * @param filePath 原始的docx文件路径存储位置
     * @param outPutFile html输出文件路径
	 * @return
     * @throws TransformerException
     * @throws IOException
     * @throws ParserConfigurationException
     */
    public static String docx2Html(String filePath,
			final String outPutFilePath)
		throws TransformerException, IOException, ParserConfigurationException {
    	//String fileOutName = outPutFile;
        XWPFDocument wordDocument = new XWPFDocument(new FileInputStream(filePath));
        XHTMLOptions options = XHTMLOptions.create().indent(4);

        // 导出图片
        Map<String, String> imageInfoMap = gainTempImagePath(outPutFilePath);
        File imageFolder = new File(imageInfoMap.get("imageStoredPath"));
        options.setExtractor(new FileImageExtractor(imageFolder));
        // URI resolver
        //这种方式获得word中的图片地址是绝对地址
        //options.URIResolver(new FileURIResolver(imageFolder));
        //设置生成的html中的img src中的地址是相对路径
        options.URIResolver(new BasicURIResolver(imageInfoMap.get("imageFolder")));

        File outFile = new File(outPutFilePath);
        outFile.getParentFile().mkdirs();
        OutputStream out = new FileOutputStream(outFile);
        XHTMLConverter.getInstance().convert(wordDocument, out, options);

        return gainRelativePathByOutputPath(outPutFilePath);
        //System.out.println("Generate " + fileOutName + " with " + (System.currentTimeMillis() - startTime) + " ms.");
    }

    /**
	 * \brief 将内容写到path路径下面
	 * @param content            :文档内容
	 * @param path               :最终的文件存储路径
	 * @attention 方法的使用注意事项
	 * @author toto
	 * @date 2017年2月27日
	 * @note  begin modify by 涂作权 2017年2月27日   修改输出的文件名称
	 */
	public static void writeFile(String docContent, String path) {
        FileOutputStream outDocFos = null;
        try {
        	//判断文件是否为空的
            if (StringUtils.isNotBlank(path)) {
            	File file = new File(path);
            	if (!file.exists()) {
					FileUtils.forceMkdir(file.getParentFile());
				}

				outDocFos = new FileOutputStream(path);
				IOUtils.write(docContent, outDocFos,CHARSET_UTF8);
			}
        } catch (FileNotFoundException fnfe) {
            fnfe.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        } finally {
            try {
                if (outDocFos != null)
                	outDocFos.close();
            } catch (IOException ie) {
            }
        }
    }

	/**
	 * 关闭输入流
	 *
	 * @param is
	 */
	private static void close(InputStream is) {
		if (is != null) {
			try {
				is.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	/**
	 * \brief 通过文档输出路径获得图片存储路径
	 * @param outPutFile             :文档输出路径
	 * @return
	 * @attention 方法的使用注意事项
	 * @author toto
	 * @date 2017年2月28日
	 * @note  begin modify by 修改人 修改时间   修改内容摘要说明
	 */
	private static Map<String, String> gainTempImagePath(String outPutFilePath) {
		Map<String,String> imageInfoMap = new HashMap<String,String>();
		try {
			//File file = new File(outPutFilePath);
	        tempImagePath = outPutFilePath.substring(0,outPutFilePath.indexOf(".html")) + File.separator;

	        File imageFolder = new File(tempImagePath);
	        if (!imageFolder.exists()) {
				try {
					FileUtils.forceMkdir(imageFolder);
				} catch (IOException e) {
					e.printStackTrace();
				}
			}

	        //System.out.println(imageFolder.getPath().replace(imageFolder.getParentFile().getPath() + File.separator, ""));
	        //return imageFolder.getPath().replace(imageFolder.getParentFile().getPath() + File.separator, "");

	        imageInfoMap.put("imageStoredPath", imageFolder.getPath());
	        imageInfoMap.put("imageFolder", imageFolder.getPath().replace(imageFolder.getParentFile().getPath(), "").replace(File.separator, ""));

	        return imageInfoMap;
		} catch (Exception e) {
			e.printStackTrace();
		}

        return null;
	}

	private static String gainRelativePathByOutputPath(String outPutFilePath) {
		//用于预览的存储路径
		String docsPreviewPath = ExtendedServerConfig.getInstance().getStringProp("DOCS_PREVIEW_PREFIX");
		return  outPutFilePath.split(docsPreviewPath)[1];
	}

	/**
	 * \brief
	 * @param orgStr            :表示要替换的就得字符串
	 * @param regEx             :表示的是正则表达式
	 * @param targetStr         :表示要替换的字符串
	 * @return
	 * @attention 方法的使用注意事项
	 * @author toto
	 * @date 2017年3月4日
	 * @note  begin modify by 涂作权  原始创建  2017年3月4日
	 */
	public static String replaceStr(String orgStr,String regEx,String targetStr){
	    if (null !=orgStr && !"".equals(orgStr.trim())) {
	        //String regEx="[\\s~·`!!@#¥$%^……&*(())\\-——\\-_=+【\\[\\]】{{}}\\|、\\\\;;::‘'“”\",,《<。.》>、/??]";
	        Pattern p = Pattern.compile(regEx);
	        Matcher m = p.matcher(orgStr);
	        return m.replaceAll(targetStr);
	    }
	    return null;
	}

	public static void main(String[] args) throws Exception {
//		String uploadFile = ExtendedServerConfig.getInstance().getStringProperty("UPLOAD_PATH");
//		String docsTempPath = ExtendedServerConfig.getInstance().getStringProperty("DOCS_TEMP_PATH");
//		String docsOutputPath = ExtendedServerConfig.getInstance().getStringProp("DOCS_OUTPUT_PATH");
//		System.out.println("uploadFile = " + uploadFile + "  " + docsTempPath + "  " + docsOutputPath);
//
		// Testtest.readWord("E://111.doc");
		// Testtest.readDoc();
		// System.out.println(content);
//		ResourcesWord readDocx = ReadWordUtils.readDoc(uploadFile + "/大学生创新创业项目申报书.doc");
//		logger.info(readDocx.getContent());
//		logger.info(readDocx.getParagNum());
//
//		new ReadWordUtils().doc2Html(uploadFile + "/大学生创新创业项目申报书.doc" , docsOutputPath + "/大学生创新创业项目申报书.html");
		//new ReadWordUtils().docx2Html(uploadFile + "/大学生创新创业项目申报书副本.docx" , docsOutputPath + "/大学生创新创业项目申报书副本.html");

	    String newStr = replaceStr("afdas//\\as   dfasd     a//asd\\\\\\asd\\/", "[\\\\]","/");
	    newStr = replaceStr(newStr, "(/){1,}", "/");
	    newStr = replaceStr(newStr, "[ ]", "");

	    System.out.println(newStr);
	}
}

下面是调用案例:

import java.io.File;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import cn.com.hbny.docdetection.mongodb.beans.DocInfo;
import cn.com.hbny.docdetection.server.ExtendedServerConfig;
import cn.com.hbny.docdetection.service.base.impl.BaseServiceImpl;
import cn.com.hbny.docdetection.service.docInfoHandler.DocInfoHandlerService;
import cn.com.hbny.docdetection.utils.Pinyin4jUtils;
import cn.com.hbny.docdetection.utils.ReadWordUtils;
import cn.com.hbny.docdetection.utils.UUIDGenerator;
import cn.com.hbny.docdetection.utils.Pinyin4jUtils.PinyinType;

/**
 * @brief DocInfoHandlerServiceImpl.java 文档检测对应的文档
 * @attention
 * @author toto
 * @date 2017年3月2日
 * @note begin modify by 涂作权   2017年3月2日  原始创建
 */
@Service(value = "docInfoHandlerService")
public class DocInfoHandlerServiceImpl extends BaseServiceImpl implements DocInfoHandlerService {
	private static Logger logger = Logger.getLogger(DocInfoHandlerServiceImpl.class);

	/**
	 * 文档处理对应的service
	 * @param docLibrayId       :文档库对应的id
	 * @param originalDocPath   :原始文档所在的位置
	 * @param uploadPath        :文档上传路径
	 * @param outPutFolderPath  :文档最终的输出文件夹
	 * @param docsPreviewPrefix :文档预览的前缀
	 */
	public DocInfo handlerSingleDocInfo(
			String docLibrayId,
			String originalDocPath,
			String uploadPath,
			String outPutFolderPath,
			String docsPreviewPrefix) {
		try {
			DocInfo docInfo = new DocInfo();
			docInfo.setId(UUIDGenerator.generate());
			docInfo.setDocLibrayId(docLibrayId);

			//处理传递过来的文件路径
			File file = new File(originalDocPath);
			//判断文件是否哦存在,如果不存在直接返回,如果存在继续下面的操作
			if (file.exists()) {
				//获取到文档的名称
				String fileName = file.getName();
				docInfo.setOriginalFileName(fileName.substring(0,fileName.toLowerCase().indexOf(".doc")));

				//截取上传文件的后面那一串路径
				String fileRelativePath = originalDocPath.substring(uploadPath.length());
			    docInfo.setOriginalDocPath(fileRelativePath);

				//判断文件后缀
				if (fileName.endsWith(".doc")) {
					//1、处理word文档,并将word文档存储在相应的位置上,将word存储成html
					String outPutFilePath = Pinyin4jUtils.toPinYin(
							outPutFolderPath + fileRelativePath.replace(".doc", ".html"),
							PinyinType.LOWERCASE);

					outPutFilePath = ReadWordUtils.replaceStr(outPutFilePath, "[\\\\]","/");
					outPutFilePath = ReadWordUtils.replaceStr(outPutFilePath, "(/){1,}", "/");
					outPutFilePath = ReadWordUtils.replaceStr(outPutFilePath, "[ ]", "");

					//下面是经过处理后的文件存储位置
                    String filePathAfterHandled = ReadWordUtils.doc2Html(originalDocPath,outPutFilePath);
                    docInfo.setHtmlDocPath(filePathAfterHandled);
				}  else {
					//1、处理word文档,并将word文档存储在相应的位置上,将word存储成html
					//1、处理word文档,并将word文档存储在相应的位置上,将word存储成html
					String outPutFilePath = Pinyin4jUtils.toPinYin(
							outPutFolderPath + fileRelativePath.replace(".docx", ".html"),
							PinyinType.LOWERCASE);

					outPutFilePath = ReadWordUtils.replaceStr(outPutFilePath, "[\\\\]","/");
					outPutFilePath = ReadWordUtils.replaceStr(outPutFilePath, "(/){1,}", "/");
					outPutFilePath = ReadWordUtils.replaceStr(outPutFilePath, "[ ]", "");

					//下面是经过处理后的文件存储位置
                    String filePathAfterHandled = ReadWordUtils.docx2Html(originalDocPath, outPutFilePath);
                    docInfo.setHtmlDocPath(filePathAfterHandled);
				}

				return null;
			} else {
				return null;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public static void main(String[] args) {
		String uploadPath = ExtendedServerConfig.getInstance().getStringProperty("UPLOAD_PATH");
		String outPutFolderPath = ExtendedServerConfig.getInstance().getStringProperty("DOCS_OUTPUT_PATH");
		String docsPreviewPrefix = ExtendedServerConfig.getInstance().getStringProperty("DOCS_PREVIEW_PREFIX");
//		new DocInfoHandlerServiceImpl().handlerSingleDocInfo(
//				UUIDGenerator.generate(),
//				uploadPath + "/双创项目申报书20170301/国家大学生创新训练计划项目申请书华师大.doc",
//				uploadPath,
//				outPutFolderPath);

//		new DocInfoHandlerServiceImpl().handlerSingleDocInfo(
//				UUIDGenerator.generate(),
//				uploadPath + "/双创项目申报书20170301/国家级大学生创新创业训练计划  立项申请书   上海电力学院.doc",
//				uploadPath,
//				outPutFolderPath,
//				docsPreviewPrefix);

		new DocInfoHandlerServiceImpl().handlerSingleDocInfo(
				UUIDGenerator.generate(),
				uploadPath + "/双创项目申报书20170301/专题产品需求规格说明书.docx",
				uploadPath,
				outPutFolderPath,
				docsPreviewPrefix);
	}
}

下面是所以用到的参数配置:

#上传的文件的存储位置的配置,统一的最后面不要加斜杠
UPLOAD_PATH=D:/installed/apache-tomcat-7.0.47/webapps/upload
##处理后的文档输出位置,统一的最后面不要加斜杠
DOCS_OUTPUT_PATH=D:/installed/apache-tomcat-7.0.47/webapps/docs-output-path
##文档预览路径,注意最后面不要加斜杠
DOCS_PREVIEW_PREFIX=/docs-output-path
##处理文档是,生成的一些图片的临时存储路径,最后面不要加斜杠
DOCS_TEMP_PATH=D:/installed/apache-tomcat-7.0.47/webapps/temp
时间: 2024-08-04 02:12:49

将Doc或者Docx文档处理成html的代码逻辑;统计word中的字数,段数,句数,读取word中文档内容的代码逻辑的相关文章

文档-关于JAVA的POI处理.doc、.docx时office和wps的不同处理

问题描述 关于JAVA的POI处理.doc..docx时office和wps的不同处理 比如用户发过来一个doc文档,但是我现在不知道他是wps的还是word的,这两个会有略微不同. 那我用poi处理时应该怎么做?可以识别吗? 我查了一下文档没有找到这部分的...大多网上的例子都是知道上传的是wps还是word. 我试了下发现不进行分类处理好像会有乱码... 解决方案 --上传文件 客户端上传文件到服务端,服务端可以获取到当前上传文件的文件名称.文件对象.文件类型等属性,判断文件的后缀区分当前上

libreoffice writer文档保存为doc或docx格式教程

  点击LibreOffice图标(看清楚,不是LibreOffice Writer图标哦) 文档保存为doc或docx格式教程-libreoffice docx"> 点击LibreOffice软件的菜单栏里的"工具"菜单,在"工具"弹出菜单里点击"选项" 点击"选项"对话框左边的"载入/保存"下的"一般" 在"选项--载入/保存--一般"对话框里选择

LibreOffice将文档转成PDF的方法

书籍,文件,教程,操作手册等现在遍布网络,在学校.工作场所及政府中也是这样--文档被封装成众多的文件格式.有时,我们需要转换文件的格式,例如,将X文件转换为PDF,为了满足用户的特定需求,通过LibreOffice这个动作可以很容易完成. 基本上,通过LibreOffice Writer,用户能够轻松自由的转换格式,如书籍.文件.PDF等,Writer能够转换每一个它能够打开的文件为PDF. 以将一个DOC文档转化成PDF格式为例: 用LibreOffice 打开DOC文档(右击文档->Open

使用Hanvon PDF Converter快速把PDF文档转换成Word

PDF格式是由Adobe公司制作的一种支持跨平台的电子文件格式,由于不是很多人会使用PDF的阅读器去编辑和查看PDF文件,所以今天就为大家介绍把pdf转换成Word的方法. 只要把pdf转换成Word,我们就可以方便地使用Word打开查看并进行编辑. 今天为大家介绍一个把PDF转换成Word的软件,Hanvon PDF Converter.这个软件可以把PDF文件转成RTF格式,RTF格式能够直接使用Word打开,所以只要转换成RTF就可以使用Word把RTF另存为DOC格式了. PDF转换成W

把wps文档转换成word文档的两种方法

  我们知道,电脑安装的是金山wps,那么,文件保存的就是wps文档了.如果要用wor打开的话,就需要将wps文档转换成word文档.今天,我们就来学习一下将wps转换成word的方法,包括了修改文件后缀名的方法.另外为doc格式的方法.下面就一起来看看具体的内容吧! 把wps转换成word的方法一: 第一步:点击我的电脑或者计算机,点击"工具",然后点击"文件夹选项"; 第二步:在对话框中点击"查看",把"隐藏已知类型文件的扩展名&q

怎么将WPS文字编辑的文档转换成pdf格式?

  pdf转成Word的DOC格式,或者Word的DOC格式转成pdf,是大家比较关心的问题.用Wps可以快速把Word文档转成pdf格式.那么怎么将WPS文字编辑的文档转换成pdf格式?下面小编就为大家介绍一下,来看看吧! 方法/步骤 1.当然还是先打开WPS文字,并新建文档; 2.开始编辑文档,如果你的文档已经编辑好了,这两步就不用了; 3.然后点击"WPS文字"->"文件"->"输出为PDF"; 4.弹出对话框,选择你要保存的路

将office2007文档转换成office2003文档的方法

  您是否遇到过发给别人的word文档,对方表示打不开的状况.其实,有可能是,您使用的是office2007来编辑跟保存该文档,而对方的电脑仍在使用office2003.那么,遇到这个状况,只需要将将office2007文档转换成2003文档就可以了,具体方法看下面的教程吧! 首先,我们找到并打开需要转换成2003版本的文档. PS:如果你是要不熟悉2007的操作想更换回2003版本的软件,那么请直接查看第6步即可. 打开文档后,我们在这个将要转换为03版本的文档最左上角,点击"office 按

借用OpenOffice将上传的Word文档转换成Html格式

有个博友写的比较详细,参考地址:http://www.cnblogs.com/luckyxiaoxuan/archive/2012/06/13/2548331.html 将Word转Html的原理是这样的: 1.客户上传Word文档到服务器 2.服务器调用OpenOffice程序打开上传的Word文档 3.OpenOffice将Word文档另存为Html格式 4.Over 至此可见,这要求服务器端安装OpenOffice软件,其实也可以是MS Office,不过OpenOffice的优势是跨平台

java OpenOffice将上传的Word文档转换成Html格式

为什么会想起来将上传的word文档转换成html格式呢?设想,如果一个系统需要发布在页面的文章都是来自word文档,一般会执行下面的流程:使用word打开文档,Ctrl+A,进入发布文章页面,Ctrl+V.看起来也不麻烦,但是,如果文档中包含大量图片呢?尴尬的事是图片都需要重新上传吧? 如果可以将已经编写好的word文档上传到服务器就可以在相应页面进行展示,将会是一件非常惬意的事情,最起码信息发布人员会很开心.程序员可能就不会这么想了,?濉?/p> 将Word转Html的原理是这样的: 1.客户