-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDocumentService.cs
More file actions
62 lines (58 loc) · 2.49 KB
/
DocumentService.cs
File metadata and controls
62 lines (58 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.IO;
using System.Threading.Tasks;
using BlazorAppSpreadsheet;
using DevExpress.Spreadsheet;
namespace BlazorAppSpreadsheet
{
public class DocumentService
{
public async Task<byte[]> GetHtmlDocumentAsync(double loanAmount,
int periodInYears, double interestRate, DateTime startDateOfLoan)
{
// Generate a workbook
// that contains an amortization schedule.
using var workbook = await GenerateDocumentAsync(loanAmount, periodInYears,
interestRate, startDateOfLoan);
// Export the document to HTML.
using var ms = new MemoryStream();
await workbook.ExportToHtmlAsync(ms, workbook.Worksheets[0]);
return ms.ToArray();
}
public async Task<byte[]> GetXlsxDocumentAsync(double loanAmount,
int periodInYears, double interestRate, DateTime startDateOfLoan)
{
// Generate a workbook
// that contains an amortization schedule.
using var workbook = await GenerateDocumentAsync(loanAmount, periodInYears,
interestRate, startDateOfLoan);
// Save the document as XLSX.
return await workbook.SaveDocumentAsync(DocumentFormat.Xlsx);
}
public async Task<byte[]> GetPdfDocumentAsync(double loanAmount,
int periodInYears, double interestRate, DateTime startDateOfLoan)
{
// Generate a workbook
// that contains an amortization schedule.
using var workbook = await GenerateDocumentAsync(loanAmount, periodInYears,
interestRate, startDateOfLoan);
// Export the document to HTML.
using var ms = new MemoryStream();
await workbook.ExportToPdfAsync(ms);
return ms.ToArray();
}
async Task<Workbook> GenerateDocumentAsync(double loanAmount,
int periodInYears, double interestRate, DateTime loanStartDate)
{
var workbook = new Workbook();
// Load the document template.
await workbook.LoadDocumentAsync("Data/LoanAmortizationScheduleTemplate.xltx");
// Generate a loan amortization schedule
// based on the template and specified loan information.
new LoanAmortizationScheduleGenerator(workbook)
.GenerateDocument(loanAmount, periodInYears,
interestRate, loanStartDate);
return workbook;
}
}
}