.net core word,excel在线预览
电脑版发表于:2020/2/16 10:06
                    可以使用库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的编码方式)
