簡體   English   中英

打開 ExcelJS 生成的 XLSX 文件時的警告

[英]Warning When Opening XLSX file generated by ExcelJS

我能夠生成並保存一個 xlsx 文件,但是當我打開該文件時,我收到一條警告並顯示以下錯誤。 我可以查看該文件,但每次都會出現此警告。

   <recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><logFileName>Repair Result to fileName-111.xml</logFileName><summary>Errors were detected in file ’/Users/yosefgamble/Downloads/fileName-11.xlsx’</summary><removedFeatures summary="Following is a list of removed features:"><removedFeature>Removed Feature: AutoFilter from /xl/tables/table1.xml part (Table)</removedFeature><removedFeature>Removed Feature: Table from /xl/tables/table1.xml part (Table)</removedFeature></removedFeatures></recoveryLog>

這是我的 javascript 代碼,Vue.Js。 我將我的對象映射到不同的行並使用寫緩沖區和文件保護程序導出為 XLSX。 我使用了可能導致問題的合並,但注釋掉似乎並沒有修復文件。 有什么辦法可以找出問題出在哪里?

async exportToExcel() { // On Click Excel download button
        const workbook = new ExcelJS.Workbook();

        workbook.modified = new Date();
        workbook.creator = 'ProactivComp';
        workbook.lastModifiedBy = "ProactivComp";
        workbook.created = new Date();

        const ws = workbook.addWorksheet('Timesheet Report', {
            headerFooter:{firstHeader: "Hello Exceljs"}
        });

        ws.columns = [
            { header: 'Date', key: 'DATE', width: 12 },
            { header: 'Description', key: 'name', width: 57},
            { header: 'Employee', key: 'EMP', width: 15, outlineLevel: 1 },
            { header: 'Start', key: 'STAR', width: 12, outlineLevel: 1 },
            { header: 'Finish', key: 'FIN', width: 20, outlineLevel: 1 },
            { header: '', key: 'TIME', width: 10, outlineLevel: 1 },
        ];

        let count = 1;

        ws.addTable({
            name: 'Job Information',
            ref: 'A1',
            headerRow: true,
            totalsRow: false,
            style: {
                theme: 'TableStyleDark3',
                showRowStripes: true,
            },
            columns: [
                {name: 'JOB NUMBER ', filterButton: false},
                {name: 'Client', width: 10, filterButton: false},
                {name: 'Attention', filterButton: false},
                {name: 'Job Date', filterButton: false},
                {name: 'Rate', filterButton: false},
                {name: 'Hours Total', filterButton: false},
            ],
            rows: [
            ],
        });

        this.jobsL.forEach(data =>{

            const jobHeader = ws.addRow([data.job_number,data.client_name, data.attention, data.job_date, data.rate]);
            jobHeader.getCell(1).alignment = { vertical: 'top', horizontal: 'left'};
            jobHeader.getCell(1).font = {  size: 16, bold: true};
            jobHeader.getCell(2).font = {  size: 14};
            jobHeader.commit()

            const descriptionHeader = ws.addRow(['',data.description,'','','']);
            count += 2;
            ws.mergeCells('B'+count+':F'+count)
            // count += 2;
            // ws.mergeCells('A'+count+':E'+count);

            ws.addRow(['Date','Description','Employee','Start','Finish','Time (in hours)']);
            data.timesheets.forEach(data => {
                const timesheetRow = ws.addRow([data.date,data.description,data.employee_code,data.start_time,data.end_time,data.total_time])
                timesheetRow.getCell(1).alignment = { vertical: 'top', horizontal: 'left'};
                timesheetRow.getCell(2).alignment = { vertical: 'top', horizontal: 'left', wrapText: true };
                timesheetRow.getCell(3).alignment = { vertical: 'top', horizontal: 'left'};
                timesheetRow.getCell(4).alignment = { vertical: 'top', horizontal: 'left'};
                timesheetRow.getCell(5).alignment = { vertical: 'top', horizontal: 'left'};
                timesheetRow.getCell(6).alignment = { vertical: 'top', horizontal: 'left'};
                timesheetRow.commit();
            });

            ws.addRow(['','','','','Employee','Total Hours'])

            data.employee_hours.forEach(data =>{
                const hoursRow = ws.addRow(['','','','',data.employee_code,data.total_time])
                hoursRow.getCell(5).alignment = { vertical: 'top', horizontal: 'left'};
                hoursRow.getCell(6).alignment = { vertical: 'top', horizontal: 'left'};
                hoursRow.commit();
            });
            ws.addRow(['','','','','',''])


            count += (data.timesheets.length+data.employee_hours.length+3)
            console.log(data)
        });

        const reportedTimeHeader1 = ws.addRow(['','','','','Total Reported Time',''])
        reportedTimeHeader1.getCell(5).font = {  size: 11, bold: true};
        reportedTimeHeader1.commit();

        const reportedTimeHeader2 = ws.addRow(['','','','','Employee','Hours'])
        reportedTimeHeader2.getCell(5).font = {bold: true};
        reportedTimeHeader2.getCell(6).font = {bold: true};
        reportedTimeHeader2.commit();

        this.report_totals.forEach(data =>{
            const totalsRow = ws.addRow(['','','','',data.employee_code,data.total_time])
            totalsRow.getCell(5).alignment = { vertical: 'top', horizontal: 'left'};
            totalsRow.getCell(6).alignment = { vertical: 'top', horizontal: 'left'};
            totalsRow.commit();
        });
        
        
        const buffer = await workbook.xlsx.writeBuffer();
        const fileType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
        const fileExtension = '.xlsx';

        const blob = new Blob([buffer], {type: fileType});

        await workbook.xlsx.writeBuffer(blob);

        FileSaver.saveAs(blob, 'protime_timesheet_export' + fileExtension);
    },

問題是 name 屬性上的空格,刪除字符串上的空格,它不會給你警告:

....
  ws.addTable({
    name: 'Job_Information',
    ref: 'A1',
    headerRow: true,
...

事實證明,excel是這樣做的,在修復文件時,在表屬性上而不是在選項卡名稱上添加下划線。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM