You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

69 lines
2.5 KiB

// 导出按钮点击事件
function ssss() {
debugger;
// 获取jqGrid的数据
/* var gridData = $('#gridList').jqGrid("getRowData");*/
var gridData = [];
var rowIds_Item1 = $("#gridList").getDataIDs();
if (rowIds_Item1.length > 0) {
for (var i = 0; i < rowIds_Item1.length; i++) {
var RowData_Item1 = obj_Item1.getRowData(rowIds_Item1[i]);
var obj = {
送回但: RowData_Item1.ASNCode,
//ContainerCode: SireCode,
//ProjectCode: RowData_Item1.ProjectCode,
//BatchCode: RowData_Item1.BatchCode,
//Version: RowData_Item1.Version,
//Brand: RowData_Item1.Brand,
//cFree1: RowData_Item1.cFree1,
//cFree2: RowData_Item1.cFree2,
//cFree3: RowData_Item1.cFree3,
//cFree4: RowData_Item1.cFree4,
//cFree5: RowData_Item1.cFree5,
//cFree6: RowData_Item1.cFree6,
//cFree7: RowData_Item1.cFree7,
//cFree8: RowData_Item1.cFree8,
//cFree9: RowData_Item1.cFree9,
//cFree10: RowData_Item1.cFree10,
};
gridData.push(obj);
}
}
// 创建一个Workbook对象
var workbook = XLSX.utils.book_new();
// 创建一个Sheet对象
var worksheet = XLSX.utils.json_to_sheet(gridData);
// 添加Sheet到Workbook
XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
// 将Workbook转换为Excel二进制数据
var excelData = XLSX.write(workbook, { type: 'binary' });
// 将Excel数据转换为blob对象
var blob = new Blob([s2ab(excelData)], { type: 'application/octet-stream' });
// 创建下载链接
var downloadLink = document.createElement('a');
downloadLink.href = URL.createObjectURL(blob);
// 设置下载文件名
downloadLink.download = 'grid_data.xlsx';
// 点击下载链接
document.body.appendChild(downloadLink);
downloadLink.click();
}
// 字符串转ArrayBuffer
function s2ab(s) {
var buf = new ArrayBuffer(s.length);
var view = new Uint8Array(buf);
for (var i = 0; i < s.length; i++) {
view[i] = s.charCodeAt(i) & 0xff;
}
return buf;
}