- Java锁的逻辑(结合对象头和ObjectMonitor)
- 还在用饼状图?来瞧瞧这些炫酷的百分比可视化新图形(附代码实现)⛵
- 自动注册实体类到EntityFrameworkCore上下文,并适配ABP及ABPVNext
- 基于Sklearn机器学习代码实战
在WEB项目中经常遇到excel文档在线预览的需求,基本的解决思路有以下几大类:excel文档转PDF、excel文档直接转html、后台读取excel数据返回给前端利用Excel效果的表格插件如(HandsonTable)将数据进行展示、部署微软Office Online服务(office web apps)实现在线预览、在线的office预览服务(如谷歌docs、微软officeapps).
EXCEL转HTML 。
excel转html可以通过第三方工具openoffice、微软office或者第三方类库如POI/NPOI、aspose.cell等转换为html文件。其中POI组件是开源免费的,Java版本叫POI,C#版本叫NPOI。但是转换的效果不是很好,有多个sheet页面的时候,POI会将所有sheet表格展示在一个网页里面,表格顶部会显示sheet名称,如果sheet很多的话页面会很长,出现滚动条页面样式不是很美观.
aspose.cells是收费组件,支持java、.net、.net core,免费使用时候转换出的html页面会有水印“Evaluation Only. Created with Aspose.Cells”如果excel存在多个sheet,aspose转换出来的网页会带选项卡,点击选项卡会展示对应的sheet页面内容,展示效果比POI转换出的html效果的好.
首先在后台使用aspose读取excel文件并返回转换好的html文件目录返回给前台 。
private readonly ILogger _logger; private readonly IWebHostEnvironment _webHostEnvironment,
public HomeController(ILogger<HomeController> logger, IWebHostEnvironment webHostEnvironment)
{
_logger = logger;
_webHostEnvironment = webHostEnvironment;
}
public IActionResult Index()
{
return View();
}
public IActionResult Privacy()
{
return View();
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
/// <summary>
/// 返回html地址
/// </summary>
/// <returns></returns>
public string ExcelToHtml()
{
//程序根目录
string rootpath = _webHostEnvironment.ContentRootPath;
//程序下webroot根目录
string webRootPath = _webHostEnvironment.WebRootPath;
string filepath = webRootPath + "\\excelFile\\test.xlsx";
//读取模板路径
Workbook book = new Workbook(filepath);
//filePath为保存文件的地址,需要服务端底下可以正常访问的路径
book.Save(webRootPath+ "\\excelFile\\test.html", SaveFormat.Html);
return "\\excelFile\\test.html";
}
前端接收到后台返回的地址进行一个展示 。
@{
ViewData["Title"] = "Home Page";
}
<script type="text/javascript">
//预览excel
function ExcelToHtml() {
$.ajax({
url: "/Home/ExcelToHtml",
data: "",
type: "get",
async: false,
success: function (data) {
debugger
console.log(data)
//获得窗口的垂直位置
var iWidth = 1400;
var iHeight = 800;
var iTop = (window.screen.availHeight - 30 - iHeight) / 2;
//获得窗口的水平位置
var iLeft = (window.screen.availWidth - 10 - iWidth) / 2;
window.open(data, '_blank', 'height=' + iHeight + ',innerHeight=' + iHeight + ',width=' + iWidth + ',innerWidth=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ',status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=0,titlebar=no');
},error(err)
{
debugger
}
});
}
</script>
<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
<button onclick="ExcelToHtml()">预览excel</button>
</div>
效果如下 。
最后此篇关于Aspose.Cells实现excel预览的文章就讲到这里了,如果你想了解更多关于Aspose.Cells实现excel预览的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
有没有办法获取其他网站页面的屏幕截图? 例如:您在输入中引入一个网址,按 Enter 键,然后脚本会为您提供所输入网站的屏幕截图。我设法使用 headless 浏览器来完成此操作,但我担心这可能会占用
我如何在 UICollectionView 中添加下一个单元格的预览,当当前单元格被滑动时显示?这样感觉就像一堆卡片。我从 Chrome 的 iOS 应用程序及其标签切换器的实现中汲取了很多灵感。任何
HTML javascript 编程新手,我的页面实现有问题。我创建了多页 HTML 表单布局(使用 div),它运行 4 个页面,大约有 140 个输入值(大多数是可选值)。我需要在实际提交之前实现
我正在尝试让 Qt5 QFileDialog 在选择图像打开时显示图像预览。 方法一:扩展QFileDialog 我用了this implementation of the dialog它适用于 Qt
我是 TFS 的新手,并尝试通过托管的 TFS (tfspreview.com) 进行我的第一次自动构建,但由于缺少程序集而失败。 我在解决方案中的一个项目引用了 Microsoft.WindowsA
我正在使用 SwiftUI 并编写了以下示例来展示我遇到的问题。当我添加多个按钮或多个文本时,它会创建两个单独的预览,但是当我在设备上运行应用程序时,它们会同时加载。附上一张照片: 我清理了我的构建文
我无法将代码覆盖率提高到最低。 90% 因为 XCode 考虑了 PreviewProvider。 我该怎么办?删除所有 SwiftUI 预览?或者有没有一种方法可以排除一些带有“PreviewPro
首先,请注意我搜索了一个 SocialMediaStackExchange 来问这个问题,但似乎没有。 这就是我想知道的。向 twitter 发布推文时,如果它是 youtube 链接或特定网站的
我正在使用谷歌地图 API 自动完成来获取搜索的机构的城市和国家/地区。为此,我有一个输入字段和搜索位置的 map 预览。这是 jsfiddle,但它目前不起作用(https://jsfiddle.n
在 OpenCart 商店中提供音频预览的最佳方法和播放器是什么?这将涉及上传完整轨道,然后提取要播放的部分 最佳答案 m3psplt是迄今为止您最好的选择。 有时安装起来有点冒险(特别是在 Cent
如果我运行: 127.0.0.1:8000/document/1/preview 此 pdf 文件已下载。 我需要在 HTML 中显示它(带有打印功能的预览)。怎么做? views.py from x
我在预览 Wagtail 页面时遇到错误,但在发布和实时查看时一切正常。我的设置是这样的: from django.db import models from modelcluster.fields
我是一个新手,我一直在尝试在 docker 上安装 Mattermost(slack 替代方案)的预览版来尝试一下。我一直遵循官方指南。 拱门 Install Docker using the fol
如果我运行: 127.0.0.1:8000/document/1/preview 此 pdf 文件已下载。 我需要在 HTML 中显示它(带有打印功能的预览)。怎么做? views.py from x
我在预览 Wagtail 页面时遇到错误,但在发布和实时查看时一切正常。我的设置是这样的: from django.db import models from modelcluster.fields
VS 调试器给我: _Color = "{Name=ff000040, ARGB=(255, 0, 0, 64)}" 我怎样才能“看到”什么颜色? 我尝试了一个 html 页面: ________
我想显示来自 ImageField 的图像。我正在使用 Django crispy forms 。似乎我需要使用 HTML 布局助手,但我不确定如何在此处访问模板变量。 以下呈现一个空白图像标签: H
The following classes could not be instantiated: androidx.fragment.app.FragmentContainerView (Open C
我正在从事一个涉及数据集之间连接的项目,我们需要允许预览任意数据集之间的任意连接。这很疯狂,但这就是它有趣的原因。这是使用面向所以给定一个连接我想快速显示 ~10 行结果。 我一直在围绕不同的方法进行
我正在尝试上传图像并在用户提交之前进行预览,但由于某种原因我无法更改 div 或图像的宽度或高度,并且它会以正常尺寸进行预览。我什至将它设置为 1px x 1px,但它仍然不起作用。 $(functi
我是一名优秀的程序员,十分优秀!