这篇文章介绍了C#将Word或Excel文档转换为Html文件的方法,文中通过示例代码介绍的非常详细。对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
这个是CodeProject上的一篇文章:Microsoft Interop API to convert the .doc, .docx, .dot, .dotx and .xls,.xlsx, .rtf to HTML。该文介绍了一种通过Microsoft office Interop library转换word或excel文档为html的方法,这里转录一下,以供更多需要的人参考。
要使用Microsoft office Interop library库,首先得在电脑上安装Office,然后添加如下三个com组件的引用:
Microsoft Office Excel library.
Microsoft Office Word library
Microsoft Office object library
作者编写了两个类DocToHtml和XlsToHtml用以转换Word和Excel文档。
public static IConverter Converter(string fullFilePath, string fileToSave)
{
switch (Path.GetExtension(fullFilePath).ToLower())
{
case ".doc":
case ".docx":
case ".dot":
case ".dotx":
case ".rtf":
return new DocToHtml { FileToSave = fileToSave, FullFilePath = fullFilePath };
case ".xls":
case ".xlsx":
return new XlsToHtml { FileToSave = fileToSave, FullFilePath = fullFilePath };
default:
throw new NotSupportedException();
}
}
使用方法如下:
static void Main(string[] args)
{
var converter = ConverterLocator.Converter(@"r:\1.xlsx", @"r:\1.html");
var html = converter.Convert();
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持得得之家。
本文标题为:C#将Word或Excel文档转换为Html文件


基础教程推荐
- c#读取XML多级子节点 2022-11-05
- C#集合查询Linq在项目中使用详解 2023-06-09
- Unity shader实现多光源漫反射以及阴影 2023-03-04
- 京东联盟C#接口测试示例分享 2022-12-02
- C# – NetUseAdd来自Windows Server 2008和IIS7上的NetApi32.dll 2023-09-20
- c#中利用Tu Share获取股票交易信息 2023-03-03
- C# Winform实现石头剪刀布游戏 2023-01-11
- C#中类与接口的区别讲解 2023-06-04
- C#通过GET/POST方式发送Http请求 2023-04-28
- 使用c#从分隔文本文件中插入SQL Server表中的批量数据 2023-11-24