https://github.com/angular-ru/angular-ru-excel-example-app
Demo: https://angular-ru.github.io/angular-ru-excel-example-app/
https://github.com/angular-ru/angular-ru-excel-example-app
Last synced: 3 months ago
JSON representation
Demo: https://angular-ru.github.io/angular-ru-excel-example-app/
- Host: GitHub
- URL: https://github.com/angular-ru/angular-ru-excel-example-app
- Owner: Angular-RU
- Created: 2020-07-02T09:52:47.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-07-07T14:02:55.000Z (almost 4 years ago)
- Last Synced: 2025-01-24T15:29:56.206Z (5 months ago)
- Language: HTML
- Homepage:
- Size: 3.46 MB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Excel Builder
> Small library for generate xls files via web worker
```ts
import { NgModule } from '@angular/core';
import { TranslateModule } from '@ngx-translate/core';
import { ExcelBuilderModule } from '@angular-ru/ng-excel-builder';@NgModule({
imports: [TranslateModule.forRoot(), ExcelBuilderModule.forRoot()]
})
export class AppModule {}
```## About
This builder we made for simple and fast generation xls files on client-side. It works with small & medium data size. Files wil open only in Microsoft Excel(!).
Google Spreadsheets, LibreOffice and another programs are not supported.## Install
```
$ npm install @angular-ru/ng-excel-builder --save
```## Example with NGX Translate
```ts
import { HttpClient, HttpClientModule } from '@angular/common/http';
import { NgModule } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatListModule } from '@angular/material/list';
import { MatSidenavModule } from '@angular/material/sidenav';
import { MatToolbarModule } from '@angular/material/toolbar';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { RouterModule } from '@angular/router';
import { EXCEL_BUILDER_NGX_TRANSLATE_FALLBACK_PROVIDER, ExcelBuilderModule } from '@angular-ru/ng-excel-builder';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';import { AppComponent } from './app.component';
// ts-prune-ignore-next
export function createTranslateLoader(http: HttpClient): TranslateHttpLoader {
return new TranslateHttpLoader(http, './assets/i18n/', `.json`);
}@NgModule({
bootstrap: [AppComponent],
declarations: [AppComponent],
imports: [
BrowserModule,
MatListModule,
HttpClientModule,
MatToolbarModule,
MatSidenavModule,
MatButtonModule,
BrowserAnimationsModule,
TranslateModule.forRoot({
loader: {
deps: [HttpClient],
provide: TranslateLoader,
useFactory: createTranslateLoader
}
}),
RouterModule.forRoot([]),
ExcelBuilderModule.forRoot()
],
providers: [EXCEL_BUILDER_NGX_TRANSLATE_FALLBACK_PROVIDER]
})
export class AppModule {}
```when we have `ru.json`
```json
{
"APP_KEYS": {
"TITLE": "Название файла",
"WORKSHEET_NAME": "Лист 1",
"MODELS": {
"id": "id",
"name": "Имя",
"description": "Описание"
}
}
}
``````ts
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
public data: Any[] = [
{
id: 'id',
name: 'Maria',
description: 'Fugiat tempor sunt nostrud ad fugiat. Laboris velit duis incididunt culpa'
}
];constructor(protected excel: ExcelService, private readonly translate: TranslateService) {
this.translate.setDefaultLang('ru');
}public exportExcel(): void {
this.excel.exportExcel({
filename: 'My excel file',
worksheets: [
{
table: this.data,
prefixKeyForTranslate: 'PATH_TO_KEYS',
worksheetName: 'worksheet name'
}
],
translatedKeys: {
PATH_TO_KEYS: {
id: 'ID',
name: 'Name',
description: 'Description'
}
}
});
}public exportExcelWithI18n(): void {
this.excel.exportExcel({
filename: 'APP_KEYS.TITLE',
worksheets: [
{
table: this.data,
prefixKeyForTranslate: 'APP_KEYS.MODELS',
worksheetName: 'APP_KEYS.WORKSHEET_NAME'
}
]
});
}
}
```- `filename` - the generated file will be named like this.
- `worksheets` - array of objects with your data.- `prefixKeyForTranslate` will be used in translate function.
- `worksheetName` - name of the sheet.
- `entries` is an array of objects, which contains data for a sheet.- `translatedKeys` - it's a dictionary for you column headers, you can leave it empty and then the column keys will be
generated as is.### Custom translate service
```ts
import { Injectable } from '@angular/core';@Injectable()
class MyCustomTranslateService implements ExcelBuilderTextColumnInterceptor {
// ...
}@NgModule({
// ...
providers: [
{
provide: EXCEL_BUILDER_INTERCEPTOR_TOKEN,
useClass: MyCustomTranslateService
}
]
})
export class AppModule {}
```