好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

c# 常用文檔轉換txt文件

c# 常用文檔轉換txt文件

1.pdf 轉換 txt

通過 PDFBox 組件,生成txt文件。需要下載PDFBox 組件。

2.word excell 轉換txt

直接調用相應組件,另存為txt。

需要注意:

2.1 word 文檔關閉,需要調用

         object SaveChange = false;
                app.Quit(ref SaveChange, ref obj, ref obj);

2.2 excell 文檔關閉,需要調用

       wbk.Close(Type.Missing, Type.Missing, Type.Missing);

       wst = null;
                wbk = null;
                app.Quit();

在打開excell文檔的時候,賦值2個變量

 app.Visible = false;//打開的excell不可見
 app.DisplayAlerts = false;//不是顯示彈出對話框

3.下面是實現代碼:

3.1 構建IcDocument接口

    public   interface   IcDocument
    {
         void   TransformDocument();
    } 

3.2 構建操作基類 BaseDocument

View Code

3.3 構建 工程類 FactoryDocument,根據傳入的轉換文檔後綴,生成不同的子類。

View Code

3.4 構建excell操作類 EexcelDocument : BaseDocument, IcDocument

View Code

3.5 構建word 操作類  WordDocument : BaseDocument, IcDocument

View Code

3.6 構建pdf 操作類 PdfDocument : BaseDocument,IcDocument

View Code

3.7 在程序中使用

      static   void  Main( string  [] args)
        {

            IcDocument document  = FactoryDocument.GetDocoment( "  c:\\temp  " ,  @"  C:\Users\Desktop\changes.pdf  "  );
            document.TransformDocument();
            document  = FactoryDocument.GetDocoment( "  c:\\temp  " ,  @"  D:\WorkDocuments\201203.xls  "  );
            document.TransformDocument();
        } 

 

分类:  C#

作者: Leo_wl

    

出处: http://www.cnblogs.com/Leo_wl/

    

本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

版权信息

查看更多关于c# 常用文檔轉換txt文件的详细内容...

  阅读:49次