故如虹,知恩;故如月,知明
排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2024TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
欢迎加群交流技术

.net core word,excel在线预览

4859人阅读 2020/2/16 10:06 总访问:3842530 评论:0 收藏:0 手机
分类: .NET Core

可以使用库ce.office.extension,库内部会使用到NPOI

下载依赖后使用就非常简单了,可以直接转成html在页面上显示即可

word转 html

string html = ce.office.extension.WordHelper.ToHtml("word地址");

excel 转 html

string html = ce.office.extension.ExcelHelper.ToHtml("excel地址")


具体转一个word示例:

public IActionResult Index()
{
    string rootpath = _webHostEnvironment.ContentRootPath;
    string html = ce.office.extension.WordHelper.ToHtml(rootpath + "/words/bb.docx");
    ViewBag.html = html;
    return View();
}

前台直接按html方式输出即可:

@Html.Raw(ViewBag.html)


转换后在页面显示的效果如下:
word的标题样式,代码样式,图片都可以正常显示(图片内部是使用的base64的编码方式)

欢迎加群讨论技术,群:677373950(满了,可以加,但通过不了),2群:656732739

评价