日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

c# html文件转换word,C#实现word转换成html文档 源码

發布時間:2023/12/15 C# 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c# html文件转换word,C#实现word转换成html文档 源码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

【實例簡介】C#實現word轉換成html文檔

【實例截圖】

【核心代碼】

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.IO;

namespace WordToHtml

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

public static void BatchConvert(string docDir)//如果批量轉換

{

//創建數組保存文件夾下的文件名

string[] docFiles = Directory.GetFiles(docDir, "*.doc");

for (int i = 0; i < docFiles.Length; i )

{

WordToHtmlFile(docFiles[i]);

}

MessageBox.Show("轉換完畢!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);

}

//將word轉換為html

public static void WordToHtmlFile(string WordFilePath)

{

try

{

Word.Application wApp = new Word.Application();

//指定原文件和目標文件

object docPath = WordFilePath;

string htmlPath = WordFilePath.Substring(0, WordFilePath.Length - 3) "html";

object Target = htmlPath;

//缺省參數

object Unknown = Type.Missing;

//只讀方式打開

object readOnly = true;

//打開doc文件

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 = Word.WdSaveFormat.wdFormatHTML;

// 轉換格式

document.SaveAs(ref Target, ref format,

ref Unknown, ref Unknown, ref Unknown,

ref Unknown, ref Unknown, ref Unknown,

ref Unknown, ref Unknown, ref Unknown);

// 關閉文檔和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 = "文件數量:" listView1.Items.Count.ToString();

}

}

private void button2_Click(object sender, EventArgs e)//單個轉換

{

if (listView1.Items.Count > 0)

{

if (listView1.SelectedItems.Count > 0)

{

if (MessageBox.Show("確定將此文檔轉換為HTML文件嗎?", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)

{

string docPath = txtWordPath.Text.Trim() "\\" listView1.SelectedItems[0].Text;

WordToHtmlFile(docPath);

MessageBox.Show("轉換完畢!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);

}

}

else

{

MessageBox.Show("請選擇要轉換的Word文檔!");

}

}

}

private void button4_Click(object sender, EventArgs e)//批量轉換

{

if (listView1.Items.Count > 0)

{

if (MessageBox.Show("確定將批量將文檔轉換為HTML文件嗎?", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)

{

BatchConvert(txtWordPath.Text.Trim());

}

}

}

private void button3_Click(object sender, EventArgs e)

{

Application.Exit();

}

}

}

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的c# html文件转换word,C#实现word转换成html文档 源码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。