import { IGrid , ExcelExportProperties , ExcelHeader , ExcelFooter , ExcelRow , ExcelCell , Theme , ThemeStyle , ExcelQueryCellInfoEventArgs , ExcelHeaderQueryCellInfoEventArgs , ExcelStyle } from '../base/interface' ; import * as events from '../base/constant' ; import { Workbook } from '@syncfusion/ej2-excel-export' ; import { isNullOrUndefined , getEnumValue , compile , extend , getValue } from '@syncfusion/ej2-base' ; import { Data } from '../actions/data' ; import { ReturnType } from '../base/type' ; import { ExportHelper , ExportValueFormatter } from './export-helper' ; import { Row } from '../models/row' ; import { Column } from '../models/column' ; import { SummaryModelGenerator , GroupSummaryModelGenerator , CaptionSummaryModelGenerator } from '../services/summary-model-generator' ; import { AggregateColumnModel } from '../models/aggregate-model' ; import { CellType , MultipleExportType } from '../base/enum' ; import { Query , DataManager } from '@syncfusion/ej2-data' ; import { Grid } from '../base/grid' ; hidden export class ExcelExport { private parent : IGrid ; private isExporting : boolean ; private theme : Theme ; private book : any = { } ; private workSheet : any = [ ] ; private rows : any = [ ] ; private columns : any = [ ] ; private styles : any = [ ] ; private data : Data ; private rowLength : number = 1 ; private footer : any ; private expType : MultipleExportType = 'AppendToSheet' ; private includeHiddenColumn : boolean = false ; private isCsvExport : boolean = false ; private isBlob : boolean ; private blobPromise : Promise < { blobData : Blob ; } > ; private exportValueFormatter : ExportValueFormatter ; private isElementIdChanged : boolean = false ; private helper : ExportHelper ; private foreignKeyData : { [ key ] : Object [ ] ; } = { } ; private groupedColLength : number ; hidden constructor ( parent ? ) { this . parent = parent ; this . helper = new ExportHelper ( parent ) ; } /**
     * For internal use only - Get the module name.
     */ private getModuleName ( ) { return 'ExcelExport' ; } private init ( gObj ) { if ( gObj . element !== null && gObj . element . id === '' ) { gObj . element . id = new Date ( ) . toISOString ( ) ; this . isElementIdChanged = true ; } this . parent = gObj ; if ( this . parent . isDestroyed ) { return ; } this . isExporting = undefined ; this . book = { } ; this . workSheet = [ ] ; this . rows = [ ] ; this . columns = [ ] ; this . styles = [ ] ; this . rowLength = 1 ; this . footer = undefined ; this . expType = 'AppendToSheet' ; this . includeHiddenColumn = false ; this . exportValueFormatter = new ExportValueFormatter ( gObj . locale ) ; } param { exportProperties } exportProperties param { isMultipleExport } isMultipleExport param { workbook } workbook param { isCsv } isCsv return { Promise < any > } public Map ( grid , exportProperties , isMultipleExport , workbook , isCsv , isBlob ) { let gObj = grid ; let cancel = 'cancel' ; let isBlb = 'isBlob' ; let csv = 'isCsv' ; let workbk = 'workbook' ; let isMultiEx = 'isMultipleExport' ; let args = { requestType : 'beforeExcelExport' , gridObject : gObj , cancel : false , isMultipleExport : isMultipleExport , workbook : workbook , isCsv : isCsv , isBlob : isBlob } ; gObj . trigger ( events . beforeExcelExport , args ) ; this . data = new Data ( gObj ) ; this . isExporting = true ; this . isBlob = args [ isBlb ] ; if ( args [ csv ] ) { this . isCsvExport = args [ csv ] ; } else { this . isCsvExport = false ; } return this . processRecords ( gObj , exportProperties , args [ isMultiEx ] , args [ workbk ] ) ; } private processRecords ( gObj , exportProperties , isMultipleExport , workbook ) { if ( ! isNullOrUndefined ( exportProperties ) && ! isNullOrUndefined ( exportProperties . dataSource ) && exportProperties . dataSource instanceof DataManager ) { return new Promise ( ( resolve , reject ) => { let dataManager = ( exportProperties . dataSource as DataManager ) . executeQuery ( new Query ( ) ) ; dataManager . then ( ( r ) => { this . init ( gObj ) ; this . processInnerRecords ( gObj , exportProperties , isMultipleExport , workbook , r ) ; resolve ( this . book ) ; } ) ; } ) ; } else { let allPromise = [ ] ; allPromise . push ( this . data . getData ( { } , ExportHelper . getQuery ( gObj , this . data ) ) ) ; allPromise . push ( this . helper . getColumnData ( < Grid > gObj ) ) ; return Promise . all ( allPromise ) . then ( ( e ) => { this . init ( gObj ) ; this . processInnerRecords ( gObj , exportProperties , isMultipleExport , workbook , e [ 0 ] ) ; return this . book ; } ) . catch ( ( e ) => { this . parent . trigger ( events . actionFailure , e ) ; } ) ; } } private processInnerRecords ( gObj , exportProperties , isMultipleExport , workbook , r ) { this . groupedColLength = gObj . groupSettings . columns . length ; let blankRows = 5 ; if ( ! isNullOrUndefined ( exportProperties ) && ! isNullOrUndefined ( exportProperties . multipleExport ) ) { this . expType = ( ! isNullOrUndefined ( exportProperties . multipleExport . type ) ? exportProperties . multipleExport . type : 'AppendToSheet' ) ; if ( ! isNullOrUndefined ( exportProperties . multipleExport . blankRows ) ) { blankRows = exportProperties . multipleExport . blankRows ; } } if ( isNullOrUndefined ( workbook ) ) { this . workSheet = [ ] ; this . rows = [ ] ; this . columns = [ ] ; this . styles = [ ] ; } else if ( this . expType === 'NewSheet' ) { this . workSheet = workbook . worksheets ; this . rows = [ ] ; this . columns = [ ] ; this . styles = workbook . styles ; } else { this . workSheet = [ ] ; this . rows = workbook . worksheets [ 0 ] . rows ; this . columns = workbook . worksheets [ 0 ] . columns ; this . styles = workbook . styles ; this . rowLength = ( this . rows [ this . rows . length - 1 ] . index + blankRows ) ; this . rowLength ++ ; } if ( ! isNullOrUndefined ( exportProperties ) ) { if ( ! isNullOrUndefined ( isMultipleExport ) ) { if ( ! isNullOrUndefined ( exportProperties . header ) && ( isMultipleExport || this . expType === 'NewSheet' ) ) { this . processExcelHeader ( JSON . parse ( JSON . stringify ( exportProperties . header ) ) ) ; } if ( ! isNullOrUndefined ( exportProperties . footer ) ) { if ( this . expType === 'AppendToSheet' ) { if ( ! isMultipleExport ) { this . footer = JSON . parse ( JSON . stringify ( exportProperties . footer ) ) ; } } else { this . footer = JSON . parse ( JSON . stringify ( exportProperties . footer ) ) ; } } } else { if ( ! isNullOrUndefined ( exportProperties . header ) ) { this . processExcelHeader ( JSON . parse ( JSON . stringify ( exportProperties . header ) ) ) ; } if ( ! isNullOrUndefined ( exportProperties . footer ) ) { this . footer = JSON . parse ( JSON . stringify ( exportProperties . footer ) ) ; } } } this . includeHiddenColumn = ( ! isNullOrUndefined ( exportProperties ) ? exportProperties . includeHiddenColumn : false ) ; let headerRow = this . helper . getHeaders ( gObj . columns , this . includeHiddenColumn ) ; let groupIndent = 0 ; if ( ! isNullOrUndefined ( ( ( r . result ) as any ) . level ) ) { groupIndent += ( ( r . result ) as any ) . level ; groupIndent += ( ( r . result ) as any ) . childLevels ; } this . processHeaderContent ( gObj , headerRow , exportProperties , groupIndent ) ; if ( ! isNullOrUndefined ( exportProperties ) && ! isNullOrUndefined ( exportProperties . dataSource ) && ! ( exportProperties . dataSource instanceof DataManager ) ) { this . processRecordContent ( gObj , r , headerRow , isMultipleExport , exportProperties , exportProperties . dataSource as Object [ ] ) ; } else if ( ! isNullOrUndefined ( exportProperties ) && exportProperties . exportType === 'CurrentPage' ) { this . processRecordContent ( gObj , r , headerRow , isMultipleExport , exportProperties , gObj . currentViewData ) ; } else { this . processRecordContent ( gObj , r , headerRow , isMultipleExport , exportProperties ) ; } this . isExporting = false ; gObj . trigger ( events . excelExportComplete , this . isBlob ? { promise : this . blobPromise } : { } ) ; } private processRecordContent ( gObj , returnType , headerRow , isMultipleExport , exportProperties , currentViewRecords ? ) { let column = gObj . columns ; let record = undefined ; if ( ! isNullOrUndefined ( currentViewRecords ) ) { record = currentViewRecords ; } else { record = returnType . result ; } if ( ! isNullOrUndefined ( record . level ) ) { this . processGroupedRows ( gObj , record , headerRow , record . level ) ; } else { this . processRecordRows ( gObj , record , headerRow , 0 ) ; } if ( ! isNullOrUndefined ( returnType . aggregates ) ) { if ( ! isNullOrUndefined ( currentViewRecords ) ) { this . processAggregates ( gObj , returnType . result , currentViewRecords ) ; } else { this . processAggregates ( gObj , returnType . result ) ; } } if ( ! isNullOrUndefined ( this . footer ) ) { if ( ( this . expType === 'AppendToSheet' && ! isMultipleExport ) || ( this . expType === 'NewSheet' ) ) { this . processExcelFooter ( this . footer ) ; } } let sheet = { } ; if ( this . columns . length > 0 ) { sheet . columns = this . columns ; } sheet . rows = this . rows ; this . workSheet . push ( sheet ) ; this . book . worksheets = this . workSheet ; this . book . styles = this . styles ; if ( ! isMultipleExport ) { if ( this . isCsvExport ) { let book = new Workbook ( this . book , 'csv' , gObj . locale ) ; if ( ! this . isBlob ) { if ( ! isNullOrUndefined ( exportProperties ) && exportProperties . fileName ) { book . save ( exportProperties . fileName ) ; } else { book . save ( 'Export.csv' ) ; } } else { this . blobPromise = book . saveAsBlob ( 'text/csv' ) ; } } else { let book = new Workbook ( this . book , 'xlsx' , gObj . locale ) ; if ( ! this . isBlob ) { if ( ! isNullOrUndefined ( exportProperties ) && exportProperties . fileName ) { book . save ( exportProperties . fileName ) ; } else { book . save ( 'Export.xlsx' ) ; } } else { this . blobPromise = book . saveAsBlob ( 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ) ; } } if ( this . isElementIdChanged ) { gObj . element . id = '' ; } } } private processGroupedRows ( gObj , dataSource , headerRow , level ) { for ( let item of dataSource ) { let cells = [ ] ; let index = 1 ; let cell = { } ; cell . index = index + level ; let col = gObj . getColumnByField ( item . field ) ; let args = { value : item . key , column : col , style : undefined , isForeignKey : col . isForeignColumn ( ) , } ; cell . value = this . parent . getColumnByField ( item . field ) . headerText + ': ' + this . exportValueFormatter . formatCellValue ( args ) + ' - ' ; if ( item . count > 1 ) { cell . value += item . count + ' items' ; } else { cell . value += item . count + ' item' ; } cell . style = this . getCaptionThemeStyle ( this . theme ) ; let captionModelGen = new CaptionSummaryModelGenerator ( gObj ) ; let groupCaptionSummaryRows = captionModelGen . generateRows ( item ) ; this . fillAggregates ( gObj , groupCaptionSummaryRows , dataSource . level + dataSource . childLevels , this . rowLength ) ; cells . push ( cell ) ; if ( this . rows [ this . rows . length - 1 ] . cells . length > 0 ) { let lIndex = dataSource . level + dataSource . childLevels + groupCaptionSummaryRows [ 0 ] . cells . length ; let hIndex = 0 ; for ( let tCell of this . rows [ this . rows . length - 1 ] . cells ) { if ( tCell . index < lIndex ) { lIndex = tCell . index ; } if ( tCell . index > hIndex ) { hIndex = tCell . index ; } tCell . style = this . getCaptionThemeStyle ( this . theme ) ; if ( cells [ cells . length - 1 ] . index !== tCell . index ) { cells . push ( tCell ) ; } } if ( ( lIndex - cell . index ) > 1 ) { cell . colSpan = lIndex - cell . index ; } while ( hIndex < ( headerRow . columns . length + level + dataSource . childLevels ) ) { let sCell = { } ; sCell . index = ( hIndex + 1 ) ; sCell . style = this . getCaptionThemeStyle ( this . theme ) ; cells . push ( sCell ) ; hIndex ++ ; } } else { let span = 0 ; for ( let col of headerRow . columns ) { if ( ( col as Column ) . visible ) { span ++ ; } } cell . colSpan = ( dataSource . childLevels + span ) ; } this . rows [ this . rows . length - 1 ] . cells = cells ; this . rowLength ++ ; if ( this . groupedColLength < 8 && level > 1 ) { let grouping = { outlineLevel : level - 1 , isCollapsed : true } ; this . rows [ this . rows . length - 1 ] . grouping = grouping ; } if ( ! isNullOrUndefined ( dataSource . childLevels ) && dataSource . childLevels > 0 ) { this . processGroupedRows ( gObj , item . items , headerRow , item . items . level ) ; } else { this . processRecordRows ( gObj , item . items , headerRow , ( level ) ) ; this . processAggregates ( gObj , item , undefined , ( level ) , true ) ; } } } private processRecordRows ( gObj , record , headerRow , level ) { let rLen = Object . keys ( record ) . length ; let index = 1 ; let cells = [ ] ; for ( let r = 0 ; r < rLen ; r ++ ) { cells = [ ] ; index = 1 ; for ( let c = 0 , len = headerRow . columns . length ; c < len ; c ++ ) { let value = ! isNullOrUndefined ( headerRow . columns [ c ] . field ) ? getValue ( headerRow . columns [ c ] . field , record [ r ] ) : '' ; let column = headerRow . columns [ c ] as Column ; let foreignKeyData ; if ( column . isForeignColumn && column . isForeignColumn ( ) ) { foreignKeyData = this . helper . getFData ( value , column ) ; value = getValue ( column . foreignKeyValue , foreignKeyData ) ; } if ( ! isNullOrUndefined ( value ) ) { let excelCellArgs = { data : record [ r ] , column : headerRow . columns [ c ] , foreignKeyData : foreignKeyData } ; let cell = { } ; gObj . trigger ( events . excelQueryCellInfo , extend ( excelCellArgs , < ExcelQueryCellInfoEventArgs > { column : headerRow . columns [ c ] , data : record [ r ] , value : value , style : undefined , colSpan : 1 , cell : cell } ) ) ; cell = excelCellArgs . cell ; cell . index = index + level ; cell . value = excelCellArgs . value ; if ( excelCellArgs . colSpan > 1 ) { cell . colSpan = excelCellArgs . colSpan ; } if ( ! isNullOrUndefined ( excelCellArgs . style ) ) { let styleIndex = this . getColumnStyle ( gObj , index + level ) ; cell . style = this . mergeOptions ( this . styles [ styleIndex ] , excelCellArgs . style ) ; } else { cell . style = { name : gObj . element . id + 'column' + ( index + level ) } ; } cells . push ( cell ) ; } index ++ ; } if ( this . groupedColLength < 8 && level > 0 ) { let grouping = { outlineLevel : level , isCollapsed : true } ; this . rows . push ( { index : this . rowLength ++ , cells : cells , grouping : grouping } ) ; } else { this . rows . push ( { index : this . rowLength ++ , cells : cells } ) ; } } } private processAggregates ( gObj , rec , currentViewRecords ? , indent ? , byGroup ? ) { let summaryModel = new SummaryModelGenerator ( gObj ) ; let data = undefined ; if ( ! isNullOrUndefined ( currentViewRecords ) ) { data = currentViewRecords ; } else { data = rec ; } if ( indent === undefined ) { indent = 0 ; } if ( gObj . groupSettings . columns . length > 0 && byGroup ) { let groupSummaryModel = new GroupSummaryModelGenerator ( gObj ) ; let groupSummaryRows = groupSummaryModel . generateRows ( < Object > data , { level : data . level } ) ; if ( groupSummaryRows . length > 0 ) { this . fillAggregates ( gObj , groupSummaryRows , indent ) ; } } else { indent = gObj . groupSettings . columns . length > 0 && ! byGroup ? gObj . groupSettings . columns . length : indent ; let sRows = summaryModel . generateRows ( data , < SummaryData > rec . aggregates ) ; if ( sRows . length > 0 && ! byGroup ) { this . fillAggregates ( gObj , sRows , indent ) ; } } } private fillAggregates ( gObj , cells , indent , customIndex ? ) { for ( let row of cells ) { let cells = [ ] ; let index = 0 ; for ( let cell of row . cells ) { let eCell = { } ; if ( ( cell . visible || this . includeHiddenColumn ) ) { index ++ ; if ( cell . isDataCell ) { eCell . index = index + indent ; if ( ! isNullOrUndefined ( cell . column . footerTemplate ) ) { eCell . value = this . getAggreateValue ( CellType . Summary , cell . column . footerTemplate , cell , row ) ; } else if ( ! isNullOrUndefined ( cell . column . groupFooterTemplate ) ) { eCell . value = this . getAggreateValue ( CellType . GroupSummary , cell . column . groupFooterTemplate , cell , row ) ; } else if ( ! isNullOrUndefined ( cell . column . groupCaptionTemplate ) ) { eCell . value = this . getAggreateValue ( CellType . CaptionSummary , cell . column . groupCaptionTemplate , cell , row ) ; } else { for ( let key of Object . keys ( row . data [ cell . column . field ] ) ) { if ( key === cell . column . type ) { if ( ! isNullOrUndefined ( row . data [ cell . column . field ] . Sum ) ) { eCell . value = row . data [ cell . column . field ] . Sum ; } else if ( ! isNullOrUndefined ( row . data [ cell . column . field ] . Average ) ) { eCell . value = row . data [ cell . column . field ] . Average ; } else if ( ! isNullOrUndefined ( row . data [ cell . column . field ] . Max ) ) { eCell . value = row . data [ cell . column . field ] . Max ; } else if ( ! isNullOrUndefined ( row . data [ cell . column . field ] . Min ) ) { eCell . value = row . data [ cell . column . field ] . Min ; } else if ( ! isNullOrUndefined ( row . data [ cell . column . field ] . Count ) ) { eCell . value = row . data [ cell . column . field ] . Count ; } else if ( ! isNullOrUndefined ( row . data [ cell . column . field ] . TrueCount ) ) { eCell . value = row . data [ cell . column . field ] . TrueCount ; } else if ( ! isNullOrUndefined ( row . data [ cell . column . field ] . FalseCount ) ) { eCell . value = row . data [ cell . column . field ] . FalseCount ; } else if ( ! isNullOrUndefined ( row . data [ cell . column . field ] . Custom ) ) { eCell . value = row . data [ cell . column . field ] . Custom ; } } } } eCell . style = this . getCaptionThemeStyle ( this . theme ) ; if ( cell . attributes . style . textAlign ) { eCell . style . hAlign = cell . attributes . style . textAlign ; } cells . push ( eCell ) ; } else { if ( customIndex === undefined ) { eCell . index = index + indent ; eCell . style = this . getCaptionThemeStyle ( this . theme ) ; cells . push ( eCell ) ; } } } } if ( ! isNullOrUndefined ( customIndex ) ) { this . rows . push ( { index : customIndex , cells : cells } ) ; } else { let row = { } ; if ( this . groupedColLength < 8 && this . groupedColLength > 0 ) { let dummyOutlineLevel = 'outlineLevel' ; let dummyGrouping = 'grouping' ; let level = this . rows [ this . rows . length - 1 ] [ dummyGrouping ] [ dummyOutlineLevel ] ; let grouping = { outlineLevel : level , isCollapsed : true } ; row = { index : this . rowLength ++ , cells : cells , grouping } ; } else { row = { index : this . rowLength ++ , cells : cells } ; } this . rows . push ( row ) ; } } } private getAggreateValue ( cellType , template , cell , row ) { let templateFn = { } ; templateFn [ getEnumValue ( CellType , cell . cellType ) ] = compile ( template ) ; let txt = ( templateFn [ getEnumValue ( CellType , cell . cellType ) ] ( row . data [ cell . column . field ? cell . column . field : cell . column . columnName ] ) ) ; return ( < Text > txt [ 0 ] ) . wholeText ; } private mergeOptions ( JSON1 , JSON2 ) { let result = { } ; let attrname = Object . keys ( JSON1 ) ; for ( let index = 0 ; index < attrname . length ; index ++ ) { if ( attrname [ index ] !== 'name' ) { result [ attrname [ index ] ] = JSON1 [ attrname [ index ] ] ; } } attrname = Object . keys ( JSON2 ) ; for ( let index = 0 ; index < attrname . length ; index ++ ) { if ( attrname [ index ] !== 'name' ) { result [ attrname [ index ] ] = JSON2 [ attrname [ index ] ] ; } } return result ; } private getColumnStyle ( gObj , columnIndex ) { let index = 0 ; for ( let style of this . styles ) { if ( style . name === gObj . element . id + 'column' + columnIndex ) { return index ; } index ++ ; } return undefined ; } private processHeaderContent ( gObj , headerRow , exportProperties , indent ) { let column = gObj . columns ; let rowIndex = 1 ; let returnValue = headerRow ; let gridRows = returnValue . rows ; let gridColumns = returnValue . columns ; let spannedCells = [ ] ; if ( indent > 0 ) { let index = 0 ; while ( index !== indent ) { this . columns . push ( { index : index + 1 , width : 30 } ) ; index ++ ; } } for ( let row = 0 ; row < gridRows . length ; row ++ ) { let currentCellIndex = 1 + indent ; let cells = [ ] ; for ( let column = 0 ; column < gridRows [ row ] . cells . length ; column ++ ) { let style = { } ; let cell = { } ; let gridCell = gridRows [ row ] . cells [ column ] ; let result = { contains : true , index : 1 } ; while ( result . contains ) { result = this . getIndex ( spannedCells , rowIndex , currentCellIndex ) ; currentCellIndex = result . index ; if ( ! result . contains ) { cell . index = result . index ; break ; } } if ( ! isNullOrUndefined ( gridCell . rowSpan ) && gridCell . rowSpan !== 1 ) { cell . rowSpan = gridCell . rowSpan ; for ( let i = rowIndex ; i < gridCell . rowSpan + rowIndex ; i ++ ) { let spannedCell = { rowIndex : 0 , columnIndex : 0 } ; spannedCell . rowIndex = i ; spannedCell . columnIndex = currentCellIndex ; spannedCells . push ( spannedCell ) ; } } if ( ! isNullOrUndefined ( gridCell . colSpan ) && gridCell . colSpan !== 1 ) { cell . colSpan = gridCell . colSpan ; currentCellIndex = currentCellIndex + cell . colSpan - 1 ; } cell . value = gridCell . column . headerText ; if ( ! isNullOrUndefined ( exportProperties ) && ! isNullOrUndefined ( exportProperties . theme ) ) { this . theme = exportProperties . theme ; } style = this . getHeaderThemeStyle ( this . theme ) ; if ( ! isNullOrUndefined ( gridCell . column . textAlign ) ) { style . hAlign = gridCell . column . textAlign ; } if ( ! isNullOrUndefined ( gridCell . column . headerTextAlign ) ) { style . hAlign = gridCell . column . headerTextAlign ; } let excelHeaderCellArgs = { cell : cell , gridCell : gridCell , setStyle : style } ; gObj . trigger ( events . excelHeaderQueryCellInfo , extend ( excelHeaderCellArgs , < ExcelHeaderQueryCellInfoEventArgs > { cell : cell , setStyle : style } ) ) ; cell . style = style ; cells . push ( cell ) ; currentCellIndex ++ ; } this . rows . push ( { index : this . rowLength ++ , cells : cells } ) ; } for ( let col = 0 ; col < gridColumns . length ; col ++ ) { this . parseStyles ( gObj , gridColumns [ col ] , this . getRecordThemeStyle ( this . theme ) , indent + col + 1 ) ; } } private getHeaderThemeStyle ( theme ) { let style = { } ; style . fontSize = 12 ; style . borders = { color : '#E0E0E0' } ; if ( ! isNullOrUndefined ( theme ) && ! isNullOrUndefined ( theme . header ) ) { style = this . updateThemeStyle ( theme . header , style ) ; } return style ; } private updateThemeStyle ( themestyle , style ) { if ( ! isNullOrUndefined ( themestyle . fontColor ) ) { style . fontColor = themestyle . fontColor ; } if ( ! isNullOrUndefined ( themestyle . fontName ) ) { style . fontName = themestyle . fontName ; } if ( ! isNullOrUndefined ( themestyle . fontSize ) ) { style . fontSize = themestyle . fontSize ; } if ( ! isNullOrUndefined ( themestyle . borders ) ) { if ( ! isNullOrUndefined ( themestyle . borders . color ) ) { style . borders . color = themestyle . borders . color ; } if ( ! isNullOrUndefined ( themestyle . borders . lineStyle ) ) { style . borders . lineStyle = themestyle . borders . lineStyle ; } } if ( themestyle . bold !== false ) { style . bold = themestyle . bold ; } return style ; } private getCaptionThemeStyle ( theme ) { let style = { } ; style . fontSize = 13 ; style . backColor = '#F6F6F6' ; if ( ! isNullOrUndefined ( theme ) && ! isNullOrUndefined ( theme . caption ) ) { style = this . updateThemeStyle ( theme . caption , style ) ; } return style ; } private getRecordThemeStyle ( theme ) { let style = { } ; style . fontSize = 13 ; style . borders = { color : '#E0E0E0' } ; if ( ! isNullOrUndefined ( theme ) && ! isNullOrUndefined ( theme . record ) ) { style = this . updateThemeStyle ( theme . record , style ) ; } return style ; } private processExcelHeader ( header ) { if ( ! isNullOrUndefined ( header . rows ) && ( this . expType === 'NewSheet' || this . rowLength === 1 ) ) { let noRows ; if ( header . headerRows === undefined ) { this . rowLength = header . rows . length ; } else { this . rowLength = header . headerRows ; } if ( this . rowLength < header . rows . length ) { noRows = this . rowLength ; } else { noRows = header . rows . length ; } this . rowLength ++ ; for ( let row = 0 ; row < noRows ; row ++ ) { let json = header . rows [ row ] ; if ( ! ( json . index !== null && ! isNullOrUndefined ( json . index ) ) ) { json . index = ( row + 1 ) ; } this . updatedCellIndex ( json ) ; } } } private updatedCellIndex ( json ) { let cellsLength = json . cells . length ; for ( let cellId = 0 ; cellId < cellsLength ; cellId ++ ) { let jsonCell = json . cells [ cellId ] ; if ( ! ( jsonCell . index !== null && ! isNullOrUndefined ( jsonCell . index ) ) ) { jsonCell . index = ( cellId + 1 ) ; } } this . rows . push ( json ) ; } private processExcelFooter ( footer ) { if ( ! isNullOrUndefined ( footer . rows ) ) { let noRows ; if ( footer . footerRows === undefined ) { this . rowLength += footer . rows . length ; } else { if ( footer . footerRows > footer . rows . length ) { this . rowLength += ( footer . footerRows - footer . rows . length ) ; noRows = footer . rows . length ; } else { noRows = footer . footerRows ; } } for ( let row = 0 ; row < noRows ; row ++ ) { let json = footer . rows [ row ] ; if ( json . index === null || json . index === undefined ) { json . index = this . rowLength ++ ; } else { json . index += this . rowLength ; } this . updatedCellIndex ( json ) ; } } } private getIndex ( spannedCells , rowIndex , columnIndex ) { for ( let spannedCell of spannedCells ) { if ( ( spannedCell . rowIndex === rowIndex ) && ( spannedCell . columnIndex === columnIndex ) ) { columnIndex = columnIndex + 1 ; return { contains : true , index : columnIndex } ; } } return { contains : false , index : columnIndex } ; } private parseStyles ( gObj , col , style , index ) { if ( ! isNullOrUndefined ( col . format ) ) { if ( typeof col . format === 'object' ) { style . numberFormat = ! isNullOrUndefined ( col . format . format ) ? col . format . format : col . format . skeleton ; if ( ! isNullOrUndefined ( col . format . type ) ) { style . type = col . format . type ; } } else { style . numberFormat = col . format ; style . type = col . type ; } } if ( ! isNullOrUndefined ( col . textAlign ) ) { style . hAlign = col . textAlign ; } if ( Object . keys ( style ) . length > 0 ) { style . name = gObj . element . id + 'column' + index ; this . styles . push ( style ) ; } if ( ! isNullOrUndefined ( col . width ) ) { this . columns . push ( { index : index , width : typeof col . width === 'number' ? col . width : this . helper . getConvertedWidth ( col . width ) } ) ; } } return hidden public destroy ( ) { } } interface SummaryData { aggregates ? : Object ; level ? : number ; }