通过Luckysheet ,可以部署一个静态的查看Excel文件的web服务。
(注:Excel文件中不能包含数据连接,否则不能加载)
步骤如下:
一、 部署一个Nginx 静态web服务器
我这里选用Debian+宝塔面板,利用宝塔面板部署一个Nginx服务,优点是简单,易于管理,资源消耗少。
Debian13+宝塔面板的安装,这里就不再叙述了。下面创建这个静态网站。
1、网站->添加站点

域名,填写你的访问域名或IP地址,目录填写你的网站存放目录,其他保持默认。
2、修改配置文件
选中刚刚添加的站点->设置->配置文件,禁用缓存
# 针对所有静态资源禁用缓存,确保实时性
location /
{
expires -1;
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires 0;
}

二、建立index.html文件
在网站目录下,创建index.html,内容如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>库存Excel看板</title>
<!-- 1. 引入样式 -->
<link rel='stylesheet' href='./static/luckysheet.css' />
<style>
body, html { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; }
#luckysheet { width: 100%; height: 100%; position: absolute; }
</style>
</head>
<body>
<div id="luckysheet"></div>
<!-- 2. 引入核心 JS (注意顺序) -->
<script src="./static/plugin.js"></script>
<script src="./static/luckysheet.umd.js"></script>
<script src="./static/luckyexcel.umd.js"></script>
<script>
// 1. 获取 URL 中的参数
function getFileNameFromUrl() {
const urlParams = new URLSearchParams(window.location.search);
// 如果 URL 里没有 file 参数,则默认显示 'data.xlsx'
return urlParams.get('file') || 'data.xlsx';
}
function loadExcel() {
const fileName = getFileNameFromUrl();
// 加上时间戳 t 防止内网 Nginx/浏览器强行缓存
const filePath = "./" + fileName + "?t=" + new Date().getTime();
console.log("正在加载文件:", filePath);
const request = new XMLHttpRequest();
request.open("GET", filePath, true);
request.responseType = "blob";
request.onload = function() {
if (request.status === 200) {
const blob = request.response;
LuckyExcel.transformExcelToLucky(blob, function(exportJson) {
if (exportJson.sheets == null || exportJson.sheets.length == 0) {
console.error("无法解析 Excel 文件内容");
return;
}
window.luckysheet.destroy();
window.luckysheet.create({
container: 'luckysheet',
data: exportJson.sheets,
showinfobar: false,
showtoolbar: false,
allowEdit: false
});
});
} else {
console.error("未找到文件: " + fileName + " (状态码: " + request.status + ")");
// 如果文件不存在,可以提示用户或显示默认画面
document.getElementById('luckysheet').innerHTML = "<h2 style='color:white;padding:20px;'>未找到文件: " + fileName + "</h2>";
}
};
request.send();
}
// 初始加载
window.onload = loadExcel;
// 自动刷新逻辑(保持原本的定时刷新)
setInterval(loadExcel, 60000);
</script>
</body>
</html>
把Luckysheet 4 个核心文件,通过浏览器右键另存下来,放在网站的static目录下
- CSS https://cdn.jsdelivr.net/npm/luckysheet@latest/dist/css/luckysheet.css
- 核心JS https://cdn.jsdelivr.net/npm/luckysheet@latest/dist/luckysheet.umd.js
- 插件JS https://cdn.jsdelivr.net/npm/luckysheet@latest/dist/plugins/js/plugin.js
- LuckyExcel (解析xlsx) https://cdn.jsdelivr.net/npm/luckyexcel@latest/dist/luckyexcel.umd.js
三、使用
把Excel文件放在网站目录下,通过URL访问,
http://x.x.x.x/ 打开的是默认的data.xlsx,
http://x.x.x.x/index.html?file=inventory.xlsx 访问的是指定的Excel文件
四、Excel文件更新
Excel文件的更新, 可以通过Syncthing ,从你本地电脑上同步过去。这样你自己电脑上改动了Excel, 网页上1分钟后也刷新了。
如果原始的Excel比较复杂,可以通过Excel的 power query来呈现一个适合看板的Excel文件
五、在智能屏、电视上显示
在智能电视上显示,就是浏览器访问,不过最好配置一个鼠标, 在智能屏上,本身有触摸屏,比较方便。