zoukankan      html  css  js  c++  java
  • 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#
  • 相关阅读:
    常用的系统操作需要的响应时间
    几种RAID技术比较
    iptables详解
    mount命令详解
    解决CSocket高数据传输问题
    VC++ ComBox下拉菜单看不到值
    封装MySQL C API 基本操作
    MySQL存储过程和存储函数
    MYSQL 常用命令
    VS2005连接MySQL C API
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/2521833.html
Copyright © 2011-2022 走看看