最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#實現(xiàn)批量Word轉(zhuǎn)換Html的示例代碼

 更新時間:2022年12月22日 08:48:43   作者:芝麻粒兒  
這篇文章主要為大家詳細(xì)介紹了如何利用C#批量Word轉(zhuǎn)換Html的功能,文中的示例代碼講解詳細(xì),對我們學(xué)習(xí)C#有一定的幫助,感興趣的小伙伴可以跟隨小編一起了解一下

實踐過程

效果

代碼

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    public static void BatchConvert(string docDir)//如果批量轉(zhuǎn)換
    {
        //創(chuàng)建數(shù)組保存文件夾下的文件名 
        string[] docFiles = Directory.GetFiles(docDir, "*.doc");
        for (int i = 0; i < docFiles.Length; i++)
        {
            WordToHtmlFile(docFiles[i]);
        }
        MessageBox.Show("轉(zhuǎn)換完畢!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
    //將word轉(zhuǎn)換為html
    public static void WordToHtmlFile(string WordFilePath)
    {
        try
        {
            Microsoft.Office.Interop.Word.Application wApp = new Microsoft.Office.Interop.Word.Application();
            //指定原文件和目標(biāo)文件 
            object docPath = WordFilePath;
 			string htmlPath;
            if (WordFilePath.Contains(".docx"))
            {
                htmlPath = WordFilePath.Substring(0, WordFilePath.Length - 4) + "html";
            }
            else
            {
                htmlPath = WordFilePath.Substring(0, WordFilePath.Length - 3) + "html";
            }
            object Target = htmlPath;
            //缺省參數(shù) 
            object Unknown = Type.Missing;
            //只讀方式打開 
            object readOnly = true;
            //打開doc文件 
            Microsoft.Office.Interop.Word.Document document = wApp.Documents.Open(ref docPath, ref Unknown,
            ref readOnly, ref Unknown, ref Unknown,
            ref Unknown, ref Unknown, ref Unknown,
            ref Unknown, ref Unknown, ref Unknown,
            ref Unknown);
            // 指定格式
            object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML;
            // 轉(zhuǎn)換格式 
            document.SaveAs(ref Target, ref format,
            ref Unknown, ref Unknown, ref Unknown,
            ref Unknown, ref Unknown, ref Unknown,
            ref Unknown, ref Unknown, ref Unknown);
            // 關(guān)閉文檔和Word程序 
            document.Close(ref Unknown, ref Unknown, ref Unknown);
            wApp.Quit(ref Unknown, ref Unknown, ref Unknown);
        }
        catch (Exception e)
        {
            MessageBox.Show(e.Message);
        }
    }
    private void button1_Click(object sender, EventArgs e)
    {
        if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
        {
            tsslInfo.Text = "";
            txtWordPath.Text = folderBrowserDialog1.SelectedPath;
            string[] docFiles = Directory.GetFiles(txtWordPath.Text.Trim(),"*.doc");
            for (int i = 0; i < docFiles.Length; i++)
            {
                string docPath=docFiles[i].ToString();
                string docName = docPath.Substring(docPath.LastIndexOf("\\") + 1, docPath.Length - docPath.LastIndexOf("\\") -1);
                listView1.Items.Add(docName);
            }
            tsslInfo.Text = "文件數(shù)量:"+listView1.Items.Count.ToString();
        }
    }

    private void button2_Click(object sender, EventArgs e)//單個轉(zhuǎn)換
    {
        if (listView1.Items.Count > 0)
        {
            if (listView1.SelectedItems.Count > 0)
            {
                if (MessageBox.Show("確定將此文檔轉(zhuǎn)換為HTML文件嗎?", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                {
                    string docPath = txtWordPath.Text.Trim() + "\\" + listView1.SelectedItems[0].Text;
                    WordToHtmlFile(docPath);
                    MessageBox.Show("轉(zhuǎn)換完畢!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                MessageBox.Show("請選擇要轉(zhuǎn)換的Word文檔!");
            }
        }
    }

    private void button4_Click(object sender, EventArgs e)//批量轉(zhuǎn)換
    {
        if (listView1.Items.Count > 0)
        {
            if (MessageBox.Show("確定將批量將文檔轉(zhuǎn)換為HTML文件嗎?", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
            {
                BatchConvert(txtWordPath.Text.Trim());
            }
        }
    }

    private void button3_Click(object sender, EventArgs e)
    {
        Application.Exit();
    }
}
partial class Form1
{
    /// <summary>
    /// 必需的設(shè)計器變量。
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// 清理所有正在使用的資源。
    /// </summary>
    /// <param name="disposing">如果應(yīng)釋放托管資源,為 true;否則為 false。</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Windows 窗體設(shè)計器生成的代碼

    /// <summary>
    /// 設(shè)計器支持所需的方法 - 不要
    /// 使用代碼編輯器修改此方法的內(nèi)容。
    /// </summary>
    private void InitializeComponent()
    {
        this.label1 = new System.Windows.Forms.Label();
        this.txtWordPath = new System.Windows.Forms.TextBox();
        this.button1 = new System.Windows.Forms.Button();
        this.groupBox1 = new System.Windows.Forms.GroupBox();
        this.groupBox2 = new System.Windows.Forms.GroupBox();
        this.listView1 = new System.Windows.Forms.ListView();
        this.button2 = new System.Windows.Forms.Button();
        this.button3 = new System.Windows.Forms.Button();
        this.statusStrip1 = new System.Windows.Forms.StatusStrip();
        this.tsslInfo = new System.Windows.Forms.ToolStripStatusLabel();
        this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
        this.button4 = new System.Windows.Forms.Button();
        this.groupBox1.SuspendLayout();
        this.groupBox2.SuspendLayout();
        this.statusStrip1.SuspendLayout();
        this.SuspendLayout();
        // 
        // label1
        // 
        this.label1.AutoSize = true;
        this.label1.Location = new System.Drawing.Point(8, 21);
        this.label1.Name = "label1";
        this.label1.Size = new System.Drawing.Size(65, 12);
        this.label1.TabIndex = 0;
        this.label1.Text = "選擇目錄:";
        // 
        // txtWordPath
        // 
        this.txtWordPath.Location = new System.Drawing.Point(70, 17);
        this.txtWordPath.Name = "txtWordPath";
        this.txtWordPath.Size = new System.Drawing.Size(294, 21);
        this.txtWordPath.TabIndex = 1;
        // 
        // button1
        // 
        this.button1.Location = new System.Drawing.Point(370, 15);
        this.button1.Name = "button1";
        this.button1.Size = new System.Drawing.Size(59, 23);
        this.button1.TabIndex = 2;
        this.button1.Text = "瀏覽...";
        this.button1.UseVisualStyleBackColor = true;
        this.button1.Click += new System.EventHandler(this.button1_Click);
        // 
        // groupBox1
        // 
        this.groupBox1.Controls.Add(this.txtWordPath);
        this.groupBox1.Controls.Add(this.button1);
        this.groupBox1.Controls.Add(this.label1);
        this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System;
        this.groupBox1.Location = new System.Drawing.Point(13, 12);
        this.groupBox1.Name = "groupBox1";
        this.groupBox1.Size = new System.Drawing.Size(435, 44);
        this.groupBox1.TabIndex = 3;
        this.groupBox1.TabStop = false;
        this.groupBox1.Text = "選擇目錄";
        // 
        // groupBox2
        // 
        this.groupBox2.Controls.Add(this.listView1);
        this.groupBox2.Location = new System.Drawing.Point(13, 62);
        this.groupBox2.Name = "groupBox2";
        this.groupBox2.Size = new System.Drawing.Size(435, 187);
        this.groupBox2.TabIndex = 4;
        this.groupBox2.TabStop = false;
        this.groupBox2.Text = "Word文檔";
        // 
        // listView1
        // 
        this.listView1.FullRowSelect = true;
        this.listView1.Location = new System.Drawing.Point(6, 17);
        this.listView1.Name = "listView1";
        this.listView1.Size = new System.Drawing.Size(423, 161);
        this.listView1.TabIndex = 0;
        this.listView1.UseCompatibleStateImageBehavior = false;
        this.listView1.View = System.Windows.Forms.View.List;
        // 
        // button2
        // 
        this.button2.Location = new System.Drawing.Point(225, 259);
        this.button2.Name = "button2";
        this.button2.Size = new System.Drawing.Size(59, 23);
        this.button2.TabIndex = 6;
        this.button2.Text = "轉(zhuǎn)換";
        this.button2.UseVisualStyleBackColor = true;
        this.button2.Click += new System.EventHandler(this.button2_Click);
        // 
        // button3
        // 
        this.button3.Location = new System.Drawing.Point(389, 259);
        this.button3.Name = "button3";
        this.button3.Size = new System.Drawing.Size(59, 23);
        this.button3.TabIndex = 7;
        this.button3.Text = "取消";
        this.button3.UseVisualStyleBackColor = true;
        this.button3.Click += new System.EventHandler(this.button3_Click);
        // 
        // statusStrip1
        // 
        this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
        this.tsslInfo});
        this.statusStrip1.Location = new System.Drawing.Point(0, 285);
        this.statusStrip1.Name = "statusStrip1";
        this.statusStrip1.Size = new System.Drawing.Size(460, 22);
        this.statusStrip1.TabIndex = 8;
        this.statusStrip1.Text = "statusStrip1";
        // 
        // tsslInfo
        // 
        this.tsslInfo.Name = "tsslInfo";
        this.tsslInfo.Size = new System.Drawing.Size(131, 17);
        this.tsslInfo.Text = "toolStripStatusLabel1";
        // 
        // button4
        // 
        this.button4.Location = new System.Drawing.Point(298, 259);
        this.button4.Name = "button4";
        this.button4.Size = new System.Drawing.Size(75, 23);
        this.button4.TabIndex = 9;
        this.button4.Text = "批量轉(zhuǎn)換";
        this.button4.UseVisualStyleBackColor = true;
        this.button4.Click += new System.EventHandler(this.button4_Click);
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(460, 307);
        this.Controls.Add(this.button4);
        this.Controls.Add(this.statusStrip1);
        this.Controls.Add(this.button3);
        this.Controls.Add(this.button2);
        this.Controls.Add(this.groupBox2);
        this.Controls.Add(this.groupBox1);
        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
        this.MaximizeBox = false;
        this.Name = "Form1";
        this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
        this.Text = "Word轉(zhuǎn)換為Html";
        this.groupBox1.ResumeLayout(false);
        this.groupBox1.PerformLayout();
        this.groupBox2.ResumeLayout(false);
        this.statusStrip1.ResumeLayout(false);
        this.statusStrip1.PerformLayout();
        this.ResumeLayout(false);
        this.PerformLayout();

    }

    #endregion

    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.TextBox txtWordPath;
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.GroupBox groupBox1;
    private System.Windows.Forms.GroupBox groupBox2;
    private System.Windows.Forms.Button button2;
    private System.Windows.Forms.Button button3;
    private System.Windows.Forms.StatusStrip statusStrip1;
    private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
    private System.Windows.Forms.ListView listView1;
    private System.Windows.Forms.Button button4;
    private System.Windows.Forms.ToolStripStatusLabel tsslInfo;
}

以上就是C#實現(xiàn)批量Word轉(zhuǎn)換Html的示例代碼的詳細(xì)內(nèi)容,更多關(guān)于C# Word轉(zhuǎn)Html的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • C#調(diào)用exe文件的方法詳解

    C#調(diào)用exe文件的方法詳解

    這篇文章主要為大家詳細(xì)介紹了C#調(diào)用exe文件的相關(guān)方法,文中的示例代碼講解詳細(xì),具有一定的借鑒價值,有需要的小伙伴可以參考一下
    2024-04-04
  • C#在Windows上調(diào)用7-zip實現(xiàn)壓縮文件

    C#在Windows上調(diào)用7-zip實現(xiàn)壓縮文件

    這篇文章主要為大家詳細(xì)介紹了C#如何在Windows上調(diào)用7-zip實現(xiàn)壓縮文件,文中的示例代碼講解詳細(xì),具有一定的借鑒價值,有需要的小伙伴可以學(xué)習(xí)一下
    2023-10-10
  • c#中的常用ToString()方法總結(jié)

    c#中的常用ToString()方法總結(jié)

    很多類都重寫了ToString方法, 導(dǎo)致很多類的tostring到底執(zhí)行了什么,有哪些參數(shù),都不清楚
    2012-10-10
  • C#圖片壓縮的實現(xiàn)方法

    C#圖片壓縮的實現(xiàn)方法

    一般在web應(yīng)用中,對客戶端提交上來的圖片肯定需要進(jìn)行壓縮的。尤其是比較大的圖片,如果不經(jīng)過壓縮會導(dǎo)致頁面變的很大,打開速度比較慢,當(dāng)然了如果是需要高質(zhì)量的圖片也得需要生產(chǎn)縮略圖。
    2013-02-02
  • 詳細(xì)了解C# 枚舉與位枚舉

    詳細(xì)了解C# 枚舉與位枚舉

    這篇文章主要介紹了C# 枚舉與位枚舉的相關(guān)資料,文中講解非常細(xì)致,幫助大家更好的理解和學(xué)習(xí)枚舉和位枚舉,感興趣的朋友可以了解下
    2020-07-07
  • C#圖片處理3種高級應(yīng)用

    C#圖片處理3種高級應(yīng)用

    本文介紹C#圖片處理高級應(yīng)用,這些功能并無多大技術(shù)含量。全部基于.Net Framework類庫完成,代碼中包含了C#圖片處理的一些基礎(chǔ)知識,與大家分享,個人能力有限,不足之處還請及時指正。
    2015-10-10
  • C#實現(xiàn)只運(yùn)行單個實例應(yīng)用程序的方法(使用VB.Net的IsSingleInstance)

    C#實現(xiàn)只運(yùn)行單個實例應(yīng)用程序的方法(使用VB.Net的IsSingleInstance)

    這篇文章主要介紹了C#實現(xiàn)只運(yùn)行單個實例應(yīng)用程序的方法,本文使用的是VB.Net的IsSingleInstance方法實現(xiàn),優(yōu)于Mutex 和 Process 這兩種只運(yùn)行單個應(yīng)用程序?qū)嵗姆椒?需要的朋友可以參考下
    2014-07-07
  • C#中委托的進(jìn)一步理解

    C#中委托的進(jìn)一步理解

    這篇文章主要介紹了C#中委托的進(jìn)一步理解,本文講解了委托類型、建立委托鏈、移除委托鏈等內(nèi)容,需要的朋友可以參考下
    2015-02-02
  • C#中LINQ to Objects查詢的實現(xiàn)

    C#中LINQ to Objects查詢的實現(xiàn)

    LINQ to Objects是LINQ技術(shù)在C#中的一種應(yīng)用,它專門用于對內(nèi)存中的對象集合進(jìn)行查詢和操作,本文就詳細(xì)的介紹C#中LINQ to Objects查詢的實現(xiàn),感興趣的可以了解一下
    2023-08-08
  • C#實現(xiàn)抓取和分析網(wǎng)頁類實例

    C#實現(xiàn)抓取和分析網(wǎng)頁類實例

    這篇文章主要介紹了C#實現(xiàn)抓取和分析網(wǎng)頁類,實例分析了C#抓取及分析網(wǎng)頁中文本及連接的相關(guān)使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-05-05

最新評論

米林县| 林甸县| 旬邑县| 商洛市| 麟游县| 镇康县| 韶关市| 潮安县| 吉隆县| 蕲春县| 邵东县| 土默特左旗| 定南县| 通榆县| 桓仁| 获嘉县| 怀安县| 晋城| 余庆县| 嘉定区| 平阴县| 奇台县| 祥云县| 新河县| 桦川县| 锡林浩特市| 海口市| 麦盖提县| 霍林郭勒市| 毕节市| 迁安市| 吉木萨尔县| 平舆县| 四川省| 张掖市| 青铜峡市| 杭锦后旗| 芜湖县| 农安县| 垫江县| 兰西县|