Стилизация файлов и изображений, удаленных после чтения и записи с использованием SheetJS? - PullRequest
0 голосов
/ 28 апреля 2019

Я могу проанализировать файл xlsx через sheetjs, и я внес некоторые изменения в него при разборе.После записи файла обратно в формат 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 () {

    });
});

Сгенерированный файл содержит изменения, но все формулы, изображения и стили больше не используются.Как мне сохранить формулу и все стили, включая изображения и изображения визуализации в сгенерированном файле?

...