我能够通过sheetjs解析xlsx文件,并且在解析时对其进行了一些更改。将文件写回xlsx格式后,样式消失,所有可视化图像和公式均不起作用。
这是预期的吗 这是我解析文件的代码:
chrome.runtime.getPackageDirectoryEntry(function (root) {
root.getFile("CodeReview_Template.xlsx", {}, function (fileEntry) {
fileEntry.file(function (file) {
debugger;
const fileReader = new FileReader();
fileReader.onloadend = function (e) {
var filename = file.name;
// pre-process data
var binary = "";
var bytes = new Uint8Array(e.target.result);
var length = bytes.byteLength;
for (var i = 0; i < length; i++) {
binary += String.fromCharCode(bytes[i]);
}
// call 'xlsx' to read the file
var oFile = XLSX.read(binary, {type: 'binary', cellDates: true, cellStyles: true});
oFile.SheetNames.forEach(function (eachSheet) {
if (eachSheet === "Apex Code") {
let intRowCountA = 3;
let intRowCountJ = 3;
let lstA = {};
let lstJ = {};
let classList = [];
commentsResponse.forEach(function (eachComment) {
if (eachComment.path.endsWith('.cls') || eachComment.path.endsWith('.trigger')) {
if(classList.includes(eachComment.path)){
lstJ['J3'].h = lstJ['J3'].h + ' /n ' +'Line Number : '+ eachComment.position + ' -- '+ eachComment.body;
lstJ['J3'].m = lstJ['J3'].m + ' /n ' +'Line Number : '+ eachComment.position + ' -- '+ eachComment.body;
lstJ['J3'].r = lstJ['J3'].r.replace('<t>', '').replace('</t>', '');
lstJ['J3'].r = '<t>'+lstJ['J3'].r + ' /n ' +'Line Number : '+ eachComment.position + ' -- '+ eachComment.body+'</t>';
lstJ['J3'].v = lstJ['J3'].v + ' /n ' +'Line Number : '+ eachComment.position + ' -- '+ eachComment.body;
} else {
let a = {};
a.h = eachComment.path;
a.r = '<t>' + eachComment.path + '</t>';
a.s = {patternType: "none"};
a.t = "s";
a.v = eachComment.path;
a.m = eachComment.path;
let j = {};
j.h = 'Line Number : ' + eachComment.position + ' -- ' + eachComment.body;
j.r = '<t>' + 'Line Number : ' + eachComment.position + ' -- ' + eachComment.body + '</t>';
j.s = {patternType: "none"};
j.t = "s";
j.v = 'Line Number : ' + eachComment.position + ' -- ' + eachComment.body;
j.m = 'Line Number : ' + eachComment.position + ' -- ' + eachComment.body;
lstA['A' + intRowCountA++] = a;
lstJ['J' + intRowCountJ++] = j;
classList.push(eachComment.path);
}
}
});
Object.keys(lstA).forEach(function(key) {
oFile.Sheets["Apex Code"][key] = lstA[key];
});
Object.keys(lstJ).forEach(function(key) {
oFile.Sheets["Apex Code"][key] = lstJ[key];
});
}
if (eachSheet === "Front-End (VFP, VFC, Lightning)") {
let intRowCountA = 3;
let intRowCountJ = 3;
let lstA = {};
let lstJ = {};
let classList = [];
commentsResponse.forEach(function (eachComment) {
if (eachComment.path.endsWith('.page') || eachComment.path.endsWith('.component') ||
eachComment.path.endsWith('.js') || eachComment.path.endsWith('.cmp')) {
if(classList.includes(eachComment.path)){
lstJ['J3'].h = lstJ['J3'].h + ' /n ' +'Line Number : '+ eachComment.position + ' -- '+ eachComment.body;
lstJ['J3'].m = lstJ['J3'].m + ' /n ' +'Line Number : '+ eachComment.position + ' -- '+ eachComment.body;
lstJ['J3'].r = lstJ['J3'].r.replace('<t>', '').replace('</t>', '');
lstJ['J3'].r = '<t>'+lstJ['J3'].r + ' /n ' +'Line Number : '+ eachComment.position + ' -- '+ eachComment.body+'</t>';
lstJ['J3'].v = lstJ['J3'].v + ' /n ' +'Line Number : '+ eachComment.position + ' -- '+ eachComment.body;
} else {
let a = {};
a.h = eachComment.path;
a.r = '<t>' + eachComment.path + '</t>';
a.s = {patternType: "none"};
a.t = "s";
a.v = eachComment.path;
a.m = eachComment.path;
let j = {};
j.h = 'Line Number : ' + eachComment.position + ' -- ' + eachComment.body;
j.r = '<t>' + 'Line Number : ' + eachComment.position + ' -- ' + eachComment.body + '</t>';
j.s = {patternType: "none"};
j.t = "s";
j.v = 'Line Number : ' + eachComment.position + ' -- ' + eachComment.body;
j.m = 'Line Number : ' + eachComment.position + ' -- ' + eachComment.body;
lstA['A' + intRowCountA++] = a;
lstJ['J' + intRowCountJ++] = j;
classList.push(eachComment.path);
}
}
});
Object.keys(lstA).forEach(function(key) {
oFile.Sheets["Front-End (VFP, VFC, Lightning"][key] = lstA[key];
});
Object.keys(lstJ).forEach(function(key) {
oFile.Sheets["Front-End (VFP, VFC, Lightning"][key] = lstJ[key];
});
}
})
XLSX.writeFile(oFile, 'CodeReview.xlsx', {type: 'binary', cellDates: true, bookType: 'xlsx'});
};
fileReader.readAsArrayBuffer(file);
}, function () {
});
}, function () {
});
});
生成的文件进行了更改,但是所有公式,图像和样式均已消失。如何在生成的文件中维护公式和所有样式,包括图像和可视化图像?