個別配慮
This commit is contained in:
86
src/utils.js
86
src/utils.js
@@ -192,7 +192,7 @@ function hideSpaceField(ids) {
|
||||
});
|
||||
}
|
||||
|
||||
function getExcelName({ excelName }, nameSuffix = '', suffix = '.xlsx') {
|
||||
function getExcelName(excelName, nameSuffix = '', suffix = '.xlsx') {
|
||||
return excelName + (nameSuffix ? (nameSuffix.startsWith('_') ? nameSuffix : ('_' + nameSuffix)) : '') + suffix;
|
||||
}
|
||||
|
||||
@@ -353,4 +353,86 @@ function createDialogEl({ ok, cancel, onOk, onCancel, onClose, ...options }) {
|
||||
onClose(dialogEl.dataHolder, event);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function createExcelAndDownload({ bizLogic, api, excelName, exportName }) {
|
||||
const arrayBuffer = await getTemplateBuffer(api, excelName);
|
||||
if (!arrayBuffer) {
|
||||
// エラー
|
||||
return;
|
||||
}
|
||||
|
||||
const workbook = new ExcelJS.Workbook();
|
||||
await workbook.xlsx.load(arrayBuffer);
|
||||
|
||||
const worksheet = workbook.getWorksheet();
|
||||
try {
|
||||
await bizLogic(api, worksheet);
|
||||
} catch (e) {
|
||||
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);
|
||||
}
|
||||
|
||||
async function getTemplateBuffer(api, excelName) {
|
||||
try {
|
||||
const templateObj = await api.record.getAllRecordsWithId({
|
||||
app: env["Excelテンプレート"].appId,
|
||||
condition: `テンプレート名 = "${excelName}"`
|
||||
});
|
||||
const fileKey = templateObj[0]["テンプレートファイル"].value[0].fileKey;
|
||||
return await api.file.downloadFile({
|
||||
fileKey
|
||||
});
|
||||
} catch (e) {
|
||||
showError(true, '本アプリのExcelテンプレート読み取りエラー\n - ' + e);
|
||||
}
|
||||
}
|
||||
|
||||
function findCellsInfo(worksheet, ids) {
|
||||
const result = ids.reduce((acc, key) => {
|
||||
acc[key] = [];
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
let lastColVal;
|
||||
worksheet.eachRow((row, rowNumber) => {
|
||||
row.eachCell((cell, colNumber) => {
|
||||
const value = cell.value;
|
||||
if (value !== lastColVal && result[value]) {
|
||||
result[value].push({
|
||||
row: rowNumber,
|
||||
col: colNumber,
|
||||
value
|
||||
});
|
||||
}
|
||||
lastColVal = value;
|
||||
});
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function getLabelColsMapping(worksheet, row, fields) {
|
||||
const arr = worksheet.getRow(row).values;
|
||||
const changedIndices = [];
|
||||
for (let i = 1; i < arr.length; i++) {
|
||||
if (arr[i] !== arr[i - 1]) {
|
||||
changedIndices.push({
|
||||
index: i,
|
||||
field: fields[changedIndices.length]
|
||||
});
|
||||
}
|
||||
}
|
||||
return changedIndices;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user