我们如何更改 angularjs 中的文件(.xlsx 或任何文件)中的 bytearray
how can we change bytearray in a file(.xlsx or any) in angularjs
我从我的 API 收到一个字节数组作为响应,它是从 .xlsx 文件转换而来的。现在我需要在浏览器中 open/download 这个 bytearray(在转换为它以前的文件扩展名之后)。帮帮我,我该怎么做?我很无奈。
您可以尝试在浏览器中读取数据,客户端 readAsArrayBuffer
more docs on mozilla website .
但我不确定您能否在纯 JS 中解析 .xlsx 的内容,这里是执行此操作的库示例:http://oss.sheetjs.com/js-xlsx/ 即
XLSX / XLSM / XLSB / XLS / SpreadsheetML (Excel Spreadsheet) / ODS
parser and writer
openPDF(data, "DataSheet.pdf");//data is your bytearray intead of pdf try to ur file format
// ...
function openPDF(resData, fileName) {
var ieEDGE = navigator.userAgent.match(/Edge/g);
var ie = navigator.userAgent.match(/.NET/g); // IE 11+
var oldIE = navigator.userAgent.match(/MSIE/g);
var blob = new $window.Blob([resData], {
type: 'application/pdf'
});
if (ie || oldIE || ieEDGE) {
$window.navigator.msSaveBlob(blob, fileName);
} else {
var file = new Blob([resData], {
type: 'application/pdf'
});
var fileURL = URL.createObjectURL(file);
$window.open(fileURL);
}
}
我从我的 API 收到一个字节数组作为响应,它是从 .xlsx 文件转换而来的。现在我需要在浏览器中 open/download 这个 bytearray(在转换为它以前的文件扩展名之后)。帮帮我,我该怎么做?我很无奈。
您可以尝试在浏览器中读取数据,客户端 readAsArrayBuffer
more docs on mozilla website .
但我不确定您能否在纯 JS 中解析 .xlsx 的内容,这里是执行此操作的库示例:http://oss.sheetjs.com/js-xlsx/ 即
XLSX / XLSM / XLSB / XLS / SpreadsheetML (Excel Spreadsheet) / ODS parser and writer
openPDF(data, "DataSheet.pdf");//data is your bytearray intead of pdf try to ur file format
// ...
function openPDF(resData, fileName) {
var ieEDGE = navigator.userAgent.match(/Edge/g);
var ie = navigator.userAgent.match(/.NET/g); // IE 11+
var oldIE = navigator.userAgent.match(/MSIE/g);
var blob = new $window.Blob([resData], {
type: 'application/pdf'
});
if (ie || oldIE || ieEDGE) {
$window.navigator.msSaveBlob(blob, fileName);
} else {
var file = new Blob([resData], {
type: 'application/pdf'
});
var fileURL = URL.createObjectURL(file);
$window.open(fileURL);
}
}