-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c8a4a3
commit 8286302
Showing
9 changed files
with
101 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { ExcelService } from './excel.service'; | ||
|
||
describe('ExcelService', () => { | ||
let service: ExcelService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [ExcelService], | ||
}).compile(); | ||
|
||
service = module.get<ExcelService>(ExcelService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { CommonEntity } from 'src/common/models/common.entity'; | ||
import * as excel from 'exceljs'; | ||
import { format } from 'date-fns-jalali'; | ||
|
||
@Injectable() | ||
export class ExcelService { | ||
|
||
async exportExcel( | ||
sheetName: string, | ||
records: CommonEntity[] = [], | ||
columns: object[] = [] | ||
): Promise<excel.Buffer> { | ||
|
||
//creating workbook | ||
let workbook = new excel.Workbook(); | ||
let worksheet = workbook.addWorksheet(sheetName); | ||
|
||
// change time | ||
if (process.env.LANGUAGE === "fa") { | ||
|
||
records.forEach((record: CommonEntity) => { | ||
|
||
if (record.updated_at) { | ||
record.updated_at = format(record.updated_at as any, "yyyy-MM-dd"); | ||
} | ||
|
||
|
||
if (record.created_at) { | ||
record.created_at = format(record.created_at as any, "yyyy-MM-dd"); | ||
} | ||
}); | ||
|
||
} | ||
worksheet.columns = columns; | ||
worksheet.addRows(records); | ||
|
||
const buffer = await workbook.xlsx.writeBuffer(); | ||
|
||
return buffer; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters