Creating New Custom Workbooks

You might need to structure the existing data and then create a new custom Excel file.

The following example demonstrates how to create a custom Excel file by using the Excel Export component.

import { Component } from '@angular/core';
import { Workbook, WorkbookSheetColumn, WorkbookSheetRow, WorkbookSheetRowCell, WorkbookSheet } from '@progress/kendo-angular-excel-export';
import { saveAs } from '@progress/kendo-file-saver';

@Component({
    selector: 'my-app',
    template: `
        <button type="button" class="k-button" (click)="exportNewWorkbook()">Export Custom Workbook To Excel</button>
    `
})
export class AppComponent {
    public exportNewWorkbook() {
        const workbook = new Workbook({
            sheets: <WorkbookSheet>[
                {
                    // Column settings (width)
                    columns: <WorkbookSheetColumn>[
                        { autoWidth: true },
                        { autoWidth: true }
                    ],
                    // Title of the sheet
                    title: 'Customers',
                    // Rows of the sheet
                    rows: <WorkbookSheetRow>[
                        // First row (header)
                        {
                            cells: <WorkbookSheetRowCell>[
                                // First cell
                                { value: 'Company Name' },
                                // Second cell
                                { value: 'Contact' }
                            ]
                        },
                        // Second row (data)
                        {
                            cells: <WorkbookSheetRowCell>[
                                { value: 'Around the Horn' },
                                { value: 'Thomas Hardy' }
                            ]
                        },
                        // Third row (data)
                        {
                            cells: <WorkbookSheetRowCell>[
                                { value: 'B Beverages' },
                                { value: 'Victoria Ashworth' }
                            ]
                        }
                    ]
                }
            ]
        });
        workbook.toDataURL().then(dataUrl => {
            saveAs(dataUrl, 'Test.xlsx');
        });
    }
}

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ExcelExportModule } from '@progress/kendo-angular-excel-export';
import { AppComponent } from './app.component';

@NgModule({
  imports:      [ BrowserModule, ExcelExportModule ],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ]
})

export class AppModule { }

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';

enableProdMode();

const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule);

In this article