From 4bcad33a611db75162d4e54755b2384f3970681a Mon Sep 17 00:00:00 2001 From: xue jiahao Date: Sat, 15 Feb 2025 17:59:36 +0800 Subject: [PATCH] fix --- src/utils.js | 30 +++++++++++++++++++----------- src/個別配慮/main.js | 31 +++++++++++++++++-------------- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/src/utils.js b/src/utils.js index ea27462..b5914c6 100644 --- a/src/utils.js +++ b/src/utils.js @@ -372,16 +372,8 @@ async function createExcelAndDownload({ bizLogic, api, excelName, exportName }) showError(true, '帳票出力エラー\n - ' + e); return; } - const buffer = await workbook.xlsx.writeBuffer(); - - saveFile(buffer, exportName); -} - -function saveFile(buffer, fileName) { - const blob = new Blob([buffer], { - type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' - }); - saveAs(blob, fileName); + const blob = await pvc.lib.exceljsUtil.saveWorkbookToBlob(workbook); + saveAs(blob, exportName); } async function getTemplateBuffer(api, excelName) { @@ -413,7 +405,6 @@ function findCellsInfo(worksheet, ids) { result[value].push({ row: rowNumber, col: colNumber, - value }); } lastColVal = value; @@ -436,3 +427,20 @@ function getLabelColsMapping(worksheet, row, fields) { } return changedIndices; } + +function createCopyFromTemplate(worksheet, { startPage, + totalPages, + copyPageRowStart, + copyPageRowEnd, + callback }) { + + const rowCount = copyPageRowEnd - copyPageRowStart + 1; + let newPageRow = copyPageRowEnd + 1; + + for (let p = startPage; p <= totalPages; p++) { + const copyRow = pvc.lib.exceljsUtil.copyRows(worksheet, copyPageRowStart, copyPageRowEnd); + pvc.lib.exceljsUtil.insertRows(worksheet, newPageRow, copyRow); + newPageRow += rowCount; + callback(p, rowCount); + } +} \ No newline at end of file diff --git a/src/個別配慮/main.js b/src/個別配慮/main.js index f907dba..da34c8d 100644 --- a/src/個別配慮/main.js +++ b/src/個別配慮/main.js @@ -70,25 +70,28 @@ const pageSize = 10; const totalPages = Math.ceil(records.length / pageSize); + + // make new copy if (totalPages > 2) { const lastPage = 2; const copyPageRowStart = baseCells['月'][lastPage - 1].row - 1; const copyPageRowEnd = baseCells['児童名'][lastPage - 1].row + pageSize; - const rowCount = copyPageRowEnd - copyPageRowStart + 1; - let newPageRow = copyPageRowEnd + 1; - for (let p = 3; p <= totalPages; p++) { - const copyRow = pvc.lib.exceljsUtil.copyRows(worksheet, copyPageRowStart, copyPageRowEnd); - pvc.lib.exceljsUtil.insertRows(worksheet, newPageRow, copyRow); - newPageRow += rowCount; - ['月', '児童名'].forEach((label) => { - const last = baseCells[label][p - 2]; - baseCells[label].push({ - ...last, - row: last.row + rowCount - }); - }) - } + createCopyFromTemplate(worksheet, { + startPage: lastPage + 1, + totalPages, + copyPageRowStart, + copyPageRowEnd, + callback: (newPage, rowCount) => { + ['月', '児童名'].forEach((label) => { + const last = baseCells[label][newPage - lastPage]; + baseCells[label].push({ + col: last.col, + row: last.row + rowCount + }); + }) + } + }) } const cols = getLabelColsMapping(worksheet, baseCells['児童名'][0].row, ['児童名', '子どもの姿', '保育者援助_配慮_環境構成']);