@@ -33,7 +33,15 @@ export type ExportVTableToExcelOptions = {
3333 skipImageExportCellType ?: SkipImageExportCellType [ ] ;
3434} ;
3535
36- export async function exportVTableToExcel ( tableInstance : IVTable , options ?: ExportVTableToExcelOptions ) {
36+ function requestIdleCallbackPromise ( options ?: IdleRequestOptions ) {
37+ return new Promise < IdleDeadline > ( ( resolve ) => {
38+ requestIdleCallback ( ( deadline ) => {
39+ resolve ( deadline ) ;
40+ } , options ) ;
41+ } ) ;
42+ }
43+
44+ export async function exportVTableToExcel ( tableInstance : IVTable , options ?: ExportVTableToExcelOptions , optimization = false ) {
3745 const workbook = new ExcelJS . Workbook ( ) ;
3846 const worksheet = workbook . addWorksheet ( 'sheet1' ) ;
3947 worksheet . properties . defaultRowHeight = 40 ;
@@ -49,9 +57,9 @@ export async function exportVTableToExcel(tableInstance: IVTable, options?: Expo
4957 const SLICE_SIZE = 100 ;
5058 let currentRow = minRow ;
5159
52- function processSlice ( deadline : IdleDeadline ) {
60+ function processSlice ( deadline ? : IdleDeadline ) {
5361 return new Promise < void > ( async resolve => {
54- while ( currentRow <= maxRow && deadline . timeRemaining ( ) > 0 ) {
62+ while ( currentRow <= maxRow && ( ! optimization || ( deadline ? .timeRemaining ( ) > 0 ) ) ) {
5563 const endRow = Math . min ( currentRow + SLICE_SIZE - 1 , maxRow ) ;
5664 for ( let col = minCol ; col <= maxCol ; col ++ ) {
5765 const colWidth = tableInstance . getColWidth ( col ) ;
@@ -84,19 +92,23 @@ export async function exportVTableToExcel(tableInstance: IVTable, options?: Expo
8492 if ( currentRow > maxRow ) {
8593 resolve ( ) ;
8694 } else {
87- requestIdleCallback ( async nextDeadline => {
88- await processSlice ( nextDeadline ) ;
89- resolve ( ) ;
90- } ) ;
95+ let nextDeadline : IdleDeadline | undefined ;
96+ if ( optimization ) {
97+ nextDeadline = await requestIdleCallbackPromise ( )
98+ }
99+ await processSlice ( nextDeadline ) ;
100+ resolve ( ) ;
91101 }
92102 } ) ;
93103 }
94104
95- await new Promise < void > ( resolve => {
96- requestIdleCallback ( async deadline => {
97- await processSlice ( deadline ) ;
98- resolve ( ) ;
99- } ) ;
105+ await new Promise < void > ( async resolve => {
106+ let deadline : IdleDeadline | undefined ;
107+ if ( optimization ) {
108+ deadline = await requestIdleCallbackPromise ( )
109+ }
110+ await processSlice ( deadline ) ;
111+ resolve ( ) ;
100112 } ) ;
101113
102114 worksheet . columns = columns ;
0 commit comments