feat: 异步解析大文件WPS报备资料

This commit is contained in:
hectorzhao
2026-09-04 22:51:07 +08:00
parent aaf96db2d0
commit 5925cf493b
22 changed files with 720 additions and 80 deletions
@@ -1,6 +1,11 @@
import ExcelJS from 'exceljs';
import JSZip from 'jszip';
import { compatibleImages, convertWorkbookOutput, loadCompatibleWorkbook } from './workbook-compatibility';
import {
compatibleImagePositions,
compatibleImages,
convertWorkbookOutput,
loadCompatibleWorkbook,
} from './workbook-compatibility';
const PNG = Buffer.from(
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAusB9Y9ZrYQAAAAASUVORK5CYII=',
@@ -39,4 +44,15 @@ describe('WPS workbook compatibility', () => {
const content = Buffer.from(await workbook.xlsx.writeBuffer());
await expect(loadCompatibleWorkbook(content)).rejects.toThrow('不允许的公式');
});
it('reads WPS image positions without inflating image buffers during analysis', async () => {
const converted = await convertWorkbookOutput(await standardWorkbook(), 'wps_cell_image');
const loaded = await loadCompatibleWorkbook(converted, { includeImageData: false });
const wpsImage = loaded.wpsImagesBySheet.get('签名报备')?.[0];
expect(wpsImage).toMatchObject({ row: 2, column: 1, extension: 'png', size: PNG.length });
expect(wpsImage).not.toHaveProperty('buffer');
expect(
compatibleImagePositions(loaded.workbook, loaded.workbook.getWorksheet('签名报备')!, loaded.wpsImagesBySheet),
).toEqual([{ row: 2, column: 1 }]);
});
});