-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Plugin: Export XLSX
EN
Luckysheet is exported to an XLSX file, the front end passes in the luckysheet json, and the back end returns the XLSX file stream.
Online experience address: Luckysheet Demo
The following Luckysheet configurations already support exporting to xlsx files
sheet.data[row][column]
- v: the original value of the content
- bg: background
- ff: font
- fc: font color
- bl: bold font
- it: font italic
- fs: font size
- cl: enable strikethrough
- ht: center horizontally
- vt: vertical center
- tr: text rotation
- tb: Text word wrapping
- ct: number format (beta)
- f: formula (beta)
- ps: comments
- rich text
- sheet.defaultRowHeight: default row height
- sheet.defaultColWidth: default column width
- sheet.hyperlink: hyperlink
- sheet.config.borderInfo: border
- sheet.config.merge: merge cells
- sheet.config.rowlen: row height
- sheet.config.columnlen: column width
- sheet.config.rowhidden: hide rows
- sheet.config.colhidden: Hidden columns
- scaling ratio
- Maximum line number
- Maximum column number
- Activate now
- sheet name
- Activate selection
- Horizontal scroll bar position
- Vertical scroll bar position
Download the executable lucky-export-linux for deployment to a linux server
Address: [to be released]
Use an FTP tool such as FileZilla to transfer the lucky-export-linux file to any empty directory on the server, such as the /software/lucky directory
Fix Permission denied issue
cd /software/lucky
chmod 777 lucky-export-linuxlinux
cd /software/lucky
# Run the test directly in the current window, you can change the port as needed
./lucky-export-linux -p 3001
# Keep running in the background
nohup ./lucky-export-linux -p 3001 >lucky-export-linux.out 2>&1 &After execution, Ctrl+C can exit the interaction
Check whether the startup is successful
ps aux | grep lucky-export-linuxPrinting out information like this means that the startup is successful
The front end of Luckysheet already supports the export button on the toolbar through configuration
luckysheet. create({
plugins:[{
name: 'exportXlsx',
config:{
url:'http://[YOUR_SERVER_IP]:3001/luckyToXlsx'
}
}]
})Among them, you need to update your own server interface address url
custom export button
<button id="export-xlsx">Export XLSX</button>Listen and request the interface to export XLSX files
const exportBtn = document. getElementById('export-xlsx');
exportBtn.addEventListener('click', fetchAndDownloadXlsx);
function downloadXlsx(data, filename) {
const blob = new Blob([data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
const url = URL.createObjectURL(blob);
const link = document. createElement('a');
link.href = url;
link.download = filename;
link. click();
URL.revokeObjectURL(url);
}
function fetchAndDownloadXlsx(url,success,fail) {
// Pay attention to initialize luckysheet in advance
const luckyJson = luckysheet.toJson();
fetch('http://localhost:3001/luckyToXlsx', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(luckyJson)
})
.then((response) => response.blob())
.then((blob) => {
const filename = luckyJson.title + '.xlsx';
downloadXlsx(blob, filename);
})
.catch((error) => {
console.error('fetch error:', error);
});
}ZH
Luckysheet导出到XLSX文件,前端传入luckysheet json,后端返回XLSX文件流。
在线体验地址:Luckysheet Demo
以下Luckysheet的配置已支持导出到xlsx文件
sheet.data[row][column]
- v: 内容的原始值
- bg: 背景
- ff: 字体
- fc: 字体颜色
- bl: 字体加粗
- it: 字体斜体
- fs: 字体大小
- cl: 启用删除线
- ht: 水平居中
- vt: 垂直居中
- tr: 文字旋转
- tb: 文本自动换行
- ct: 数字格式(beta)
- f: 公式(beta)
- ps: 批注
- 富文本
- sheet.defaultRowHeight:默认行高
- sheet.defaultColWidth:默认列宽
- sheet.hyperlink:超链接
- sheet.config.borderInfo:边框
- sheet.config.merge:合并单元格
- sheet.config.rowlen:行高
- sheet.config.columnlen:列宽
- sheet.config.rowhidden:隐藏行
- sheet.config.colhidden:隐藏列
- 缩放比例
- 最大行号
- 最大列号
- 是否激活
- sheet 名称
- 激活选区
- 横向滚动条位置
- 竖向滚动条位置
下载用于部署到linux服务器上的可执行文件 lucky-export-linux
地址:[待发布]
使用 FTP 工具比如 FileZilla,传输 lucky-export-linux 文件到服务器任意空白目录,比如/software/lucky目录下
修复 Permission denied 问题
cd /software/lucky
chmod 777 lucky-export-linuxlinux
cd /software/lucky
# 当前窗口直接运行测试,可以根据需要更改端口
./lucky-export-linux -p 3001
# 保持后台运行
nohup ./lucky-export-linux -p 3001 >lucky-export-linux.out 2>&1 &执行后 Ctrl+C 退出交互即可
查询是否启动成功
ps aux|grep lucky-export-linux打印出类似这样的信息就是启动成功
Luckysheet前端已经支持通过配置开启工具栏的导出按钮
luckysheet.create({
plugins:[{
name:'exportXlsx',
config:{
url:'http://[YOUR_SERVER_IP]:3001/luckyToXlsx'
}
}]
})其中需要更新自己服务器接口地址url
自定义导出按钮
<button id="export-xlsx">Export XLSX</button>监听并请求接口导出XLSX文件
const exportBtn = document.getElementById('export-xlsx');
exportBtn.addEventListener('click', fetchAndDownloadXlsx);
function downloadXlsx(data, filename) {
const blob = new Blob([data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = filename;
link.click();
URL.revokeObjectURL(url);
}
function fetchAndDownloadXlsx(url,success,fail) {
// 注意提前初始化luckysheet
const luckyJson = luckysheet.toJson();
fetch('http://localhost:3001/luckyToXlsx', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(luckyJson)
})
.then((response) => response.blob())
.then((blob) => {
const filename = luckyJson.title + '.xlsx';
downloadXlsx(blob, filename);
})
.catch((error) => {
console.error('fetch error:', error);
});
}