中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

C#編程讀取文檔Doc,Docx,Pdf的內(nèi)容

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用
Doc文檔:Microsoft Word 14.0 Object Library (GAC對象,調(diào)用前需要安裝word。安裝的word版本不同,COM的版本號也會不同)
Docx文檔:Microsoft Word 14.0 Object Library (GAC對象,調(diào)用前需要安裝word。安裝的word版本不同,COM的版本號也會不同)
Pdf文檔:PDFBox
/*
     作者:GhostBear
 *   博客地址:Http://blog.csdn.net/ghostbear
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;

using org.pdfbox.pdmodel;
using org.pdfbox.util;

using Microsoft.Office.Interop.Word;


namespace TestPdfReader
{
    class Program
    {
        static void Main(string[] args)
        {


            //PDF
            PDDocument doc = PDDocument.load(@"C:\resume.pdf");
            PDFTextStripper pdfStripper = new PDFTextStripper();
            string text = pdfStripper.getText(doc);
            string result = text.Replace('\t', ' ').Replace('\n', ' ').Replace('\r', ' ').Replace(" ", "");
            Console.WriteLine(result);


            //Doc,Docx
            object docPath = @"C:\resume.doc";
            object docxPath = @"C:\resume.docx";
            object missing=System.Reflection.Missing.Value;
            object readOnly=true;

            Application wordApp;
            wordApp = new Application();

            Document wordDoc = wordApp.Documents.Open(ref docPath,
                                                  ref missing,
                                                  ref readOnly,
                                                  ref missing,
                                                  ref missing,
                                                  ref missing,
                                                  ref missing,
                                                  ref missing,
                                                  ref missing,
                                                  ref missing,
                                                  ref missing,
                                                  ref missing,
                                                  ref missing,
                                                  ref missing,
                                                  ref missing,
                                                  ref missing);
            string text2 = FilterString(wordDoc.Content.Text);

            wordDoc.Close(ref missing, ref missing, ref missing);
            wordApp.Quit(ref missing, ref missing, ref missing);
            Console.WriteLine(text2);


            Console.Read();
            
        }

        private static string FilterString(string input)
        {
            return Regex.Replace(input, @"(\a|\t|\n|\s+)", "");
           
        }
    }
}

標簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:Android 多點手勢識別

下一篇:python實現(xiàn)的Caesar加解密算法