Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/416.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 打开ExcelJS生成的XLSX文件时发出警告_Javascript_Excel_Vue.js_Exceljs - Fatal编程技术网

Javascript 打开ExcelJS生成的XLSX文件时发出警告

Javascript 打开ExcelJS生成的XLSX文件时发出警告,javascript,excel,vue.js,exceljs,Javascript,Excel,Vue.js,Exceljs,我能够生成并保存xlsx文件,但当我打开该文件时,会收到一个警告,其中包含以下错误。我可以查看该文件,但每次都会出现此警告 <recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><logFileName>Repair Result to fileName-111.xml</logFileName><summary>Err

我能够生成并保存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>
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);
    },