limitng 0.21.68 → 0.21.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,871 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { inject, Injectable } from '@angular/core';
|
|
3
|
+
import saveAs from 'file-saver';
|
|
4
|
+
import { TranslateService } from '@ngx-translate/core';
|
|
5
|
+
import { GlobalFunctions } from 'limitng/api';
|
|
6
|
+
import ExcelJS from 'exceljs';
|
|
7
|
+
import { NumberFormatlar, FontStyle } from 'limitng/api/models/fourDConstants';
|
|
8
|
+
import { XLHAlign, XLVAlign } from 'limitng/api/models/xl/xlConstants';
|
|
9
|
+
|
|
10
|
+
class JsonToExcelParser {
|
|
11
|
+
static async indir(sonuc, dosyaAdi) {
|
|
12
|
+
const blob = await this.blobOlustur(sonuc);
|
|
13
|
+
const normalizeDosyaAdi = this.dosyaAdiDuzenle(dosyaAdi);
|
|
14
|
+
saveAs(blob, `${normalizeDosyaAdi}.xlsx`);
|
|
15
|
+
}
|
|
16
|
+
static async blobOlustur(sonuc) {
|
|
17
|
+
const workbook = this.workbookOlustur(sonuc);
|
|
18
|
+
const buffer = await workbook.xlsx.writeBuffer();
|
|
19
|
+
return new Blob([buffer], {
|
|
20
|
+
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
static standartPageSetupOlustur() {
|
|
24
|
+
return {
|
|
25
|
+
bottomMargin: 1,
|
|
26
|
+
centerHorizontally: true,
|
|
27
|
+
centerVertically: true,
|
|
28
|
+
fitToPagesTall: 1,
|
|
29
|
+
fitToPagesWide: 1,
|
|
30
|
+
leftMargin: 1,
|
|
31
|
+
orientation: 2,
|
|
32
|
+
rightMargin: 1,
|
|
33
|
+
topMargin: 1
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
static ustBilgiEkle(ustBilgi, font) {
|
|
37
|
+
return font ? { font, ustBilgi } : { ustBilgi };
|
|
38
|
+
}
|
|
39
|
+
static workbookOlustur(sonuc) {
|
|
40
|
+
const workbook = new ExcelJS.Workbook();
|
|
41
|
+
workbook.created = new Date();
|
|
42
|
+
workbook.calcProperties.fullCalcOnLoad = true;
|
|
43
|
+
const gridLinesGorunur = sonuc.window.displayGridLines;
|
|
44
|
+
if (this.yeniYapiMi(sonuc)) {
|
|
45
|
+
workbook.creator = sonuc.book.author || 'MedPlan';
|
|
46
|
+
workbook.subject = '';
|
|
47
|
+
workbook.description = '';
|
|
48
|
+
this.yeniFormatSheetsYaz(workbook, sonuc, gridLinesGorunur);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
workbook.creator = sonuc.book.author || 'MedPlan';
|
|
52
|
+
workbook.subject = this.konuVer(sonuc.book, sonuc.ustBilgiler?.[0]?.ustBilgi);
|
|
53
|
+
workbook.description = sonuc.book.comments || '';
|
|
54
|
+
this.eskiFormatSheetsYaz(workbook, sonuc, gridLinesGorunur);
|
|
55
|
+
}
|
|
56
|
+
this.aktifSayfayiAyarla(workbook, sonuc.book.activeSheetNo, workbook.worksheets.length);
|
|
57
|
+
return workbook;
|
|
58
|
+
}
|
|
59
|
+
static yeniYapiMi(sonuc) {
|
|
60
|
+
const ilkSheet = sonuc.sheets[0];
|
|
61
|
+
if (Array.isArray(ilkSheet?.tables)) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
const runtimeSonuc = sonuc;
|
|
65
|
+
return !Array.isArray(runtimeSonuc.tables);
|
|
66
|
+
}
|
|
67
|
+
static yeniFormatSheetsYaz(workbook, sonuc, gridLinesGorunur) {
|
|
68
|
+
for (let index = 0; index < sonuc.sheets.length; index++) {
|
|
69
|
+
const sheet = sonuc.sheets[index];
|
|
70
|
+
const sheetAdi = this.sayfaAdiDuzenle(sheet.sheetName || 'Rapor', index + 1);
|
|
71
|
+
const worksheet = workbook.addWorksheet(sheetAdi);
|
|
72
|
+
const zoomScale = sheet.zoom && sheet.zoom > 0 ? sheet.zoom : undefined;
|
|
73
|
+
worksheet.views = [{ showGridLines: gridLinesGorunur, ...(zoomScale !== undefined && { zoomScale }) }];
|
|
74
|
+
this.sayfaDuzeniniBelirle(worksheet, sheet);
|
|
75
|
+
const ustBilgiler = sheet.ustBilgiler ?? [];
|
|
76
|
+
this.yeniFormatUstBilgileriYaz(worksheet, ustBilgiler, sonuc.defaultFont);
|
|
77
|
+
let sonSatir = ustBilgiler.length + 1;
|
|
78
|
+
for (const table of sheet.tables ?? []) {
|
|
79
|
+
sonSatir = Math.max(sonSatir, this.tabloyuYaz(worksheet, sonuc, table));
|
|
80
|
+
}
|
|
81
|
+
if (sheet.notlar?.length) {
|
|
82
|
+
this.notlariYazList(worksheet, sheet.notlar, sheet.not?.font, sonSatir + 2, sonuc.defaultFont);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (sonuc.sheets.length === 0) {
|
|
86
|
+
const worksheet = workbook.addWorksheet('Rapor');
|
|
87
|
+
worksheet.views = [{ showGridLines: gridLinesGorunur }];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
static eskiFormatSheetsYaz(workbook, sonuc, gridLinesGorunur) {
|
|
91
|
+
const tablesBySheet = this.sheetBazliTablolar(sonuc);
|
|
92
|
+
const ustBilgiler = sonuc.ustBilgiler ?? [];
|
|
93
|
+
const notlar = sonuc.notlar ?? [];
|
|
94
|
+
for (const sheetGrup of tablesBySheet) {
|
|
95
|
+
const worksheet = workbook.addWorksheet(sheetGrup.sheetName);
|
|
96
|
+
worksheet.views = [{ showGridLines: gridLinesGorunur }];
|
|
97
|
+
this.ustBilgileriYaz(worksheet, ustBilgiler, sonuc.defaultFont);
|
|
98
|
+
let sonSatir = 1;
|
|
99
|
+
for (const table of sheetGrup.tables) {
|
|
100
|
+
sonSatir = Math.max(sonSatir, this.tabloyuYaz(worksheet, sonuc, table));
|
|
101
|
+
}
|
|
102
|
+
this.notlariYazList(worksheet, notlar, sonuc.not?.font, sonSatir + 2, sonuc.defaultFont);
|
|
103
|
+
}
|
|
104
|
+
if (tablesBySheet.length === 0) {
|
|
105
|
+
const worksheet = workbook.addWorksheet(this.bosRaporSheetAdiniVer(sonuc));
|
|
106
|
+
worksheet.views = [{ showGridLines: gridLinesGorunur }];
|
|
107
|
+
this.ustBilgileriYaz(worksheet, ustBilgiler, sonuc.defaultFont);
|
|
108
|
+
this.notlariYazList(worksheet, notlar, sonuc.not?.font, ustBilgiler.length + 2, sonuc.defaultFont);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
static sheetBazliTablolar(sonuc) {
|
|
112
|
+
const grouped = new Map();
|
|
113
|
+
for (const table of sonuc.tables ?? []) {
|
|
114
|
+
const sheetNo = this.tableSheetNoVer(table);
|
|
115
|
+
const sheetKey = this.sheetKeyVer(table, sheetNo, grouped.size + 1);
|
|
116
|
+
const existing = grouped.get(sheetKey);
|
|
117
|
+
if (existing) {
|
|
118
|
+
existing.tables.push(table);
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
grouped.set(sheetKey, {
|
|
122
|
+
sheetName: this.sheetAdiniBelirle(sonuc, table, grouped.size + 1, sheetNo),
|
|
123
|
+
...(sheetNo !== undefined && { sheetNo }),
|
|
124
|
+
tables: [table]
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return Array.from(grouped.values()).sort((a, b) => this.sheetGrupSirasiVer(a) - this.sheetGrupSirasiVer(b));
|
|
128
|
+
}
|
|
129
|
+
static tableSheetNoVer(table) {
|
|
130
|
+
const runtimeTable = table;
|
|
131
|
+
return runtimeTable.sheetNo;
|
|
132
|
+
}
|
|
133
|
+
static sheetKeyVer(table, sheetNo, index) {
|
|
134
|
+
if (sheetNo !== undefined) {
|
|
135
|
+
return `sheet-no-${sheetNo}`;
|
|
136
|
+
}
|
|
137
|
+
const eskiSheetName = table.sheetName?.trim();
|
|
138
|
+
if (eskiSheetName) {
|
|
139
|
+
return `sheet-name-${eskiSheetName}`;
|
|
140
|
+
}
|
|
141
|
+
return `sheet-index-${index}`;
|
|
142
|
+
}
|
|
143
|
+
static sheetAdiniBelirle(sonuc, table, index, sheetNo) {
|
|
144
|
+
const jsonSheet = this.jsonSheetBul(sonuc.sheets, sheetNo, index);
|
|
145
|
+
if (jsonSheet?.sheetName?.trim()) {
|
|
146
|
+
return this.sayfaAdiDuzenle(jsonSheet.sheetName, index);
|
|
147
|
+
}
|
|
148
|
+
return this.sayfaAdiDuzenle(table.sheetName || 'Rapor', index);
|
|
149
|
+
}
|
|
150
|
+
static jsonSheetBul(sheets, sheetNo, index) {
|
|
151
|
+
if (sheetNo !== undefined) {
|
|
152
|
+
return sheets.find(sheet => sheet.sheetNo === sheetNo);
|
|
153
|
+
}
|
|
154
|
+
return sheets.find(sheet => sheet.sheetNo === index) ?? sheets[index - 1];
|
|
155
|
+
}
|
|
156
|
+
static konuVer(book, ilkUstBilgi) {
|
|
157
|
+
return book.subject || ilkUstBilgi || 'Rapor';
|
|
158
|
+
}
|
|
159
|
+
static bosRaporSheetAdiniVer(sonuc) {
|
|
160
|
+
const ilkSheetAdi = sonuc.sheets[0]?.sheetName;
|
|
161
|
+
return this.sayfaAdiDuzenle(ilkSheetAdi || 'Rapor', 1);
|
|
162
|
+
}
|
|
163
|
+
static aktifSayfayiAyarla(workbook, activeSheetNo, toplamSheetSayisi) {
|
|
164
|
+
const aktifTab = this.aktifTabNoVer(activeSheetNo, toplamSheetSayisi);
|
|
165
|
+
if (aktifTab === undefined) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
workbook.views = [{
|
|
169
|
+
activeTab: aktifTab,
|
|
170
|
+
firstSheet: aktifTab,
|
|
171
|
+
height: 20000,
|
|
172
|
+
visibility: 'visible',
|
|
173
|
+
width: 20000,
|
|
174
|
+
x: 0,
|
|
175
|
+
y: 0
|
|
176
|
+
}];
|
|
177
|
+
}
|
|
178
|
+
static aktifTabNoVer(activeSheetNo, toplamSheetSayisi) {
|
|
179
|
+
if (toplamSheetSayisi <= 0) {
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
const aktifSheetNo = Number.isFinite(activeSheetNo) && activeSheetNo > 0 ? activeSheetNo : 1;
|
|
183
|
+
return Math.min(aktifSheetNo - 1, toplamSheetSayisi - 1);
|
|
184
|
+
}
|
|
185
|
+
static sheetGrupSirasiVer(sheetGrup) {
|
|
186
|
+
return sheetGrup.sheetNo ?? Number.MAX_SAFE_INTEGER;
|
|
187
|
+
}
|
|
188
|
+
static yeniFormatUstBilgileriYaz(worksheet, ustBilgiler, defaultFont) {
|
|
189
|
+
for (let index = 0; index < ustBilgiler.length; index++) {
|
|
190
|
+
const ustBilgi = ustBilgiler[index];
|
|
191
|
+
const hucre = worksheet.getCell(index + 1, 1);
|
|
192
|
+
hucre.value = ustBilgi.ustBilgi;
|
|
193
|
+
this.hucreFontunuUygula(hucre, ustBilgi.font, defaultFont);
|
|
194
|
+
hucre.alignment = { horizontal: 'left', vertical: 'middle', wrapText: false };
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
static ustBilgileriYaz(worksheet, ustBilgiler, defaultFont) {
|
|
198
|
+
for (const ustBilgi of ustBilgiler) {
|
|
199
|
+
const hucre = worksheet.getCell(ustBilgi.rowNo ?? 1, 1);
|
|
200
|
+
hucre.value = ustBilgi.ustBilgi;
|
|
201
|
+
this.hucreFontunuUygula(hucre, ustBilgi.font, defaultFont);
|
|
202
|
+
hucre.alignment = { horizontal: 'left', vertical: 'middle', wrapText: false };
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
static notlariYazList(worksheet, notlar, notFont, baslangicSatiri, defaultFont) {
|
|
206
|
+
let satirNo = baslangicSatiri;
|
|
207
|
+
for (const not of notlar) {
|
|
208
|
+
const cell = worksheet.getCell(satirNo, 1);
|
|
209
|
+
cell.value = not;
|
|
210
|
+
this.hucreFontunuUygula(cell, notFont, defaultFont);
|
|
211
|
+
cell.alignment = { vertical: 'middle', wrapText: true };
|
|
212
|
+
satirNo++;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
static sayfaDuzeniniBelirle(worksheet, sheet) {
|
|
216
|
+
const { pageSetup } = sheet;
|
|
217
|
+
if (!pageSetup) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (pageSetup.orientation === 2) {
|
|
221
|
+
worksheet.pageSetup.orientation = 'landscape';
|
|
222
|
+
}
|
|
223
|
+
else if (pageSetup.orientation === 1) {
|
|
224
|
+
worksheet.pageSetup.orientation = 'portrait';
|
|
225
|
+
}
|
|
226
|
+
const hasMargin = pageSetup.leftMargin !== undefined ||
|
|
227
|
+
pageSetup.rightMargin !== undefined ||
|
|
228
|
+
pageSetup.topMargin !== undefined ||
|
|
229
|
+
pageSetup.bottomMargin !== undefined ||
|
|
230
|
+
pageSetup.headerMargin !== undefined ||
|
|
231
|
+
pageSetup.footerMargin !== undefined;
|
|
232
|
+
if (hasMargin) {
|
|
233
|
+
worksheet.pageSetup.margins = {
|
|
234
|
+
left: pageSetup.leftMargin ?? 0.7,
|
|
235
|
+
right: pageSetup.rightMargin ?? 0.7,
|
|
236
|
+
top: pageSetup.topMargin ?? 0.75,
|
|
237
|
+
bottom: pageSetup.bottomMargin ?? 0.75,
|
|
238
|
+
header: pageSetup.headerMargin ?? 0.3,
|
|
239
|
+
footer: pageSetup.footerMargin ?? 0.3
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
if (pageSetup.centerHorizontally !== undefined) {
|
|
243
|
+
worksheet.pageSetup.horizontalCentered = pageSetup.centerHorizontally;
|
|
244
|
+
}
|
|
245
|
+
if (pageSetup.centerVertically !== undefined) {
|
|
246
|
+
worksheet.pageSetup.verticalCentered = pageSetup.centerVertically;
|
|
247
|
+
}
|
|
248
|
+
const fitTall = pageSetup.fitToPagesTall;
|
|
249
|
+
const fitWide = pageSetup.fitToPagesWide;
|
|
250
|
+
if (fitTall !== undefined || fitWide !== undefined || pageSetup.fitToPagesTAut || pageSetup.fitToPagesWAut) {
|
|
251
|
+
worksheet.pageSetup.fitToPage = true;
|
|
252
|
+
worksheet.pageSetup.fitToHeight = pageSetup.fitToPagesTAut ? 0 : (fitTall ?? 1);
|
|
253
|
+
worksheet.pageSetup.fitToWidth = pageSetup.fitToPagesWAut ? 0 : (fitWide ?? 1);
|
|
254
|
+
}
|
|
255
|
+
if (typeof pageSetup.zoom === 'number' && pageSetup.zoom > 0) {
|
|
256
|
+
worksheet.pageSetup.scale = pageSetup.zoom;
|
|
257
|
+
}
|
|
258
|
+
if (pageSetup.printArea) {
|
|
259
|
+
worksheet.pageSetup.printArea = pageSetup.printArea;
|
|
260
|
+
}
|
|
261
|
+
const pageHeader = this.baslikAltbilgiMetniOlustur(pageSetup.leftHeader, pageSetup.centerHeader, pageSetup.rightHeader);
|
|
262
|
+
const pageFooter = this.baslikAltbilgiMetniOlustur(pageSetup.leftFooter, pageSetup.centerFooter, pageSetup.rightFooter);
|
|
263
|
+
if (pageHeader) {
|
|
264
|
+
worksheet.headerFooter.oddHeader = pageHeader;
|
|
265
|
+
}
|
|
266
|
+
if (pageFooter) {
|
|
267
|
+
worksheet.headerFooter.oddFooter = pageFooter;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
static baslikAltbilgiMetniOlustur(sol, orta, sag) {
|
|
271
|
+
const parcalar = [];
|
|
272
|
+
if (sol) {
|
|
273
|
+
parcalar.push(`&L${sol}`);
|
|
274
|
+
}
|
|
275
|
+
if (orta) {
|
|
276
|
+
parcalar.push(`&C${orta}`);
|
|
277
|
+
}
|
|
278
|
+
if (sag) {
|
|
279
|
+
parcalar.push(`&R${sag}`);
|
|
280
|
+
}
|
|
281
|
+
return parcalar.length ? parcalar.join('') : undefined;
|
|
282
|
+
}
|
|
283
|
+
static tabloyuYaz(worksheet, sonuc, table) {
|
|
284
|
+
if (!table.columns.length) {
|
|
285
|
+
return table.ust ?? 1;
|
|
286
|
+
}
|
|
287
|
+
const startRow = Math.max(1, table.ust ?? 1);
|
|
288
|
+
const startCol = Math.max(1, table.sol ?? 1);
|
|
289
|
+
const gecerliTableStyle = this.gecerliTableStyleVer(sonuc.currentTableStyle);
|
|
290
|
+
const headerTitlelari = table.columns.map(column => this.baslikMetniniHazirla(column.header.title || ''));
|
|
291
|
+
const gorunenBaslikMetinleri = headerTitlelari.map(title => title.replaceAll('\n', ' '));
|
|
292
|
+
const tabloKolonAdlari = this.benzersizKolonAdlariOlustur(gorunenBaslikMetinleri);
|
|
293
|
+
const headerFont = table.header?.font;
|
|
294
|
+
const uygulanacakHeaderFont = headerFont?.color ? headerFont : {
|
|
295
|
+
...headerFont,
|
|
296
|
+
color: 'FFFFFFFF'
|
|
297
|
+
};
|
|
298
|
+
const dataFont = table.data?.font;
|
|
299
|
+
const hiddenRowSet = new Set(table.hiddenRows ?? []);
|
|
300
|
+
const formulCeller = [];
|
|
301
|
+
const satirlar = table.collection.map((rowData, rowIndex) => table.columns.map((column, colIndex) => {
|
|
302
|
+
const deger = this.hucreDegeriniHazirla(rowData, column, sonuc.sifirlariBasmaSayi);
|
|
303
|
+
if (deger !== null && typeof deger === 'object' && 'formula' in deger) {
|
|
304
|
+
formulCeller.push({ rowIndex, colIndex, column, formula: deger });
|
|
305
|
+
return '';
|
|
306
|
+
}
|
|
307
|
+
return deger;
|
|
308
|
+
}));
|
|
309
|
+
this.kolonGrubuYaz(worksheet, startRow, startCol, table);
|
|
310
|
+
const tableStyle = this.tableStyleDonustur(gecerliTableStyle);
|
|
311
|
+
worksheet.addTable({
|
|
312
|
+
name: this.tabloAdiOlustur(worksheet.name, startRow, startCol),
|
|
313
|
+
ref: worksheet.getCell(startRow, startCol).address,
|
|
314
|
+
headerRow: true,
|
|
315
|
+
totalsRow: false,
|
|
316
|
+
...(tableStyle && { style: tableStyle }),
|
|
317
|
+
columns: tabloKolonAdlari.map(ad => ({ name: ad, filterButton: true })),
|
|
318
|
+
rows: satirlar
|
|
319
|
+
});
|
|
320
|
+
this.kolonGenislikleriniUygula(worksheet, startCol, table.columns, satirlar);
|
|
321
|
+
const headerRow = worksheet.getRow(startRow);
|
|
322
|
+
for (let colIndex = 0; colIndex < table.columns.length; colIndex++) {
|
|
323
|
+
const column = table.columns[colIndex];
|
|
324
|
+
const cell = headerRow.getCell(startCol + colIndex);
|
|
325
|
+
cell.alignment = {
|
|
326
|
+
horizontal: this.yatayHizaDonustur(column.header.horizontalAlignment),
|
|
327
|
+
vertical: 'bottom',
|
|
328
|
+
wrapText: false
|
|
329
|
+
};
|
|
330
|
+
this.hucreFontunuUygula(cell, uygulanacakHeaderFont, sonuc.defaultFont);
|
|
331
|
+
}
|
|
332
|
+
for (let rowIndex = 0; rowIndex < table.collection.length; rowIndex++) {
|
|
333
|
+
const wsRow = worksheet.getRow(startRow + 1 + rowIndex);
|
|
334
|
+
const satir1Bazli = rowIndex + 1;
|
|
335
|
+
if (hiddenRowSet.has(satir1Bazli)) {
|
|
336
|
+
wsRow.hidden = true;
|
|
337
|
+
}
|
|
338
|
+
const rowHeight = table.rowHeights?.find(rh => rh.rowNo === satir1Bazli);
|
|
339
|
+
if (rowHeight?.height) {
|
|
340
|
+
wsRow.height = rowHeight.height;
|
|
341
|
+
}
|
|
342
|
+
for (let colIndex = 0; colIndex < table.columns.length; colIndex++) {
|
|
343
|
+
const column = table.columns[colIndex];
|
|
344
|
+
const cell = wsRow.getCell(startCol + colIndex);
|
|
345
|
+
const hucreDegeri = satirlar[rowIndex][colIndex];
|
|
346
|
+
cell.value = hucreDegeri;
|
|
347
|
+
this.hucreFontunuUygula(cell, dataFont, sonuc.defaultFont);
|
|
348
|
+
const numFmt = this.numberFormatDonustur(column.format);
|
|
349
|
+
if (numFmt) {
|
|
350
|
+
cell.numFmt = numFmt;
|
|
351
|
+
}
|
|
352
|
+
cell.alignment = {
|
|
353
|
+
horizontal: this.hucreYatayHizasiniBelirle(hucreDegeri, column),
|
|
354
|
+
vertical: this.dikeyHizaDonustur(column.verticalAlignment),
|
|
355
|
+
wrapText: false
|
|
356
|
+
};
|
|
357
|
+
// Sütun rengi
|
|
358
|
+
const colFontColor = table.columnFontColors?.[colIndex];
|
|
359
|
+
if (colFontColor) {
|
|
360
|
+
const argb = this.argbDonustur(colFontColor);
|
|
361
|
+
if (argb) {
|
|
362
|
+
cell.font = { ...(cell.font ?? {}), color: { argb } };
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
const colIntColor = table.columnInteriorColors?.[colIndex];
|
|
366
|
+
if (colIntColor) {
|
|
367
|
+
const argb = this.argbDonustur(colIntColor);
|
|
368
|
+
if (argb) {
|
|
369
|
+
cell.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb } };
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
// Satır rengi (sütun rengini ezer)
|
|
373
|
+
const rowFontColor = table.rowFontColors?.find(rc => rc.rowNo === satir1Bazli);
|
|
374
|
+
if (rowFontColor) {
|
|
375
|
+
const argb = this.argbDonustur(rowFontColor.color);
|
|
376
|
+
if (argb) {
|
|
377
|
+
cell.font = { ...(cell.font ?? {}), color: { argb } };
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
const rowIntColor = table.rowInteriorColors?.find(rc => rc.rowNo === satir1Bazli);
|
|
381
|
+
if (rowIntColor) {
|
|
382
|
+
const argb = this.argbDonustur(rowIntColor.color);
|
|
383
|
+
if (argb) {
|
|
384
|
+
cell.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb } };
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
for (const { rowIndex, colIndex, column, formula } of formulCeller) {
|
|
390
|
+
const cell = worksheet.getRow(startRow + 1 + rowIndex).getCell(startCol + colIndex);
|
|
391
|
+
cell.value = formula;
|
|
392
|
+
cell.alignment = {
|
|
393
|
+
...(cell.alignment ?? {}),
|
|
394
|
+
horizontal: this.hucreYatayHizasiniBelirle(formula, column)
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
let sonSatir = startRow + table.collection.length;
|
|
398
|
+
// Footer satırları
|
|
399
|
+
const footer = table.footer;
|
|
400
|
+
if (footer?.basilacak) {
|
|
401
|
+
const ustBosluk = footer.ustBosluk ?? 0;
|
|
402
|
+
const satirSayisi = footer.satirSayisi ?? 1;
|
|
403
|
+
const footerBasSatir = sonSatir + 1 + ustBosluk;
|
|
404
|
+
for (let fi = 0; fi < satirSayisi; fi++) {
|
|
405
|
+
const footerRow = worksheet.getRow(footerBasSatir + fi);
|
|
406
|
+
for (let colIndex = 0; colIndex < table.columns.length; colIndex++) {
|
|
407
|
+
const column = table.columns[colIndex];
|
|
408
|
+
const cell = footerRow.getCell(startCol + colIndex);
|
|
409
|
+
this.hucreFontunuUygula(cell, footer.font, sonuc.defaultFont);
|
|
410
|
+
const colFooter = column.footer;
|
|
411
|
+
if (!colFooter?.isFunction && colFooter?.title) {
|
|
412
|
+
cell.value = colFooter.title;
|
|
413
|
+
}
|
|
414
|
+
cell.alignment = {
|
|
415
|
+
horizontal: this.yatayHizaDonustur(colFooter?.horizontalAlignment),
|
|
416
|
+
vertical: 'middle',
|
|
417
|
+
wrapText: false
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
sonSatir = footerBasSatir + satirSayisi - 1;
|
|
422
|
+
}
|
|
423
|
+
return sonSatir;
|
|
424
|
+
}
|
|
425
|
+
static kolonGenislikleriniUygula(worksheet, startCol, columns, satirlar) {
|
|
426
|
+
const filtreButonuBoslukPayi = 1.25;
|
|
427
|
+
const veriSagBoslukPayi = 1;
|
|
428
|
+
for (let index = 0; index < columns.length; index++) {
|
|
429
|
+
const worksheetColumn = worksheet.getColumn(startCol + index);
|
|
430
|
+
const baslikUzunlugu = this.metinUzunlugu(this.baslikMetniniHazirla(columns[index].header.title));
|
|
431
|
+
const veriUzunlugu = satirlar.reduce((max, satir) => Math.max(max, this.hucreMetinUzunlugu(satir[index])), 0);
|
|
432
|
+
const tasarimGenisligi = (columns[index].width ?? 0) > 0 ? Math.round(columns[index].width / 7) : 0;
|
|
433
|
+
worksheetColumn.width = Math.max(10, tasarimGenisligi, baslikUzunlugu + 2 + filtreButonuBoslukPayi, veriUzunlugu + 2 + veriSagBoslukPayi);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
static baslikMetniniHazirla(metin) {
|
|
437
|
+
return metin
|
|
438
|
+
.replaceAll('\r\n', ' ')
|
|
439
|
+
.replaceAll('\r', ' ')
|
|
440
|
+
.replaceAll('\n', ' ')
|
|
441
|
+
.trim();
|
|
442
|
+
}
|
|
443
|
+
static hucreMetinUzunlugu(deger) {
|
|
444
|
+
if (deger === null || deger === undefined) {
|
|
445
|
+
return 0;
|
|
446
|
+
}
|
|
447
|
+
if (typeof deger === 'string') {
|
|
448
|
+
return this.metinUzunlugu(deger);
|
|
449
|
+
}
|
|
450
|
+
if (typeof deger === 'number' || typeof deger === 'boolean') {
|
|
451
|
+
return String(deger).length;
|
|
452
|
+
}
|
|
453
|
+
if (deger instanceof Date) {
|
|
454
|
+
return '14.05.2026 09:13:29'.length;
|
|
455
|
+
}
|
|
456
|
+
if (typeof deger === 'object' && 'formula' in deger) {
|
|
457
|
+
return this.metinUzunlugu(String(deger.formula));
|
|
458
|
+
}
|
|
459
|
+
return this.metinUzunlugu(String(deger));
|
|
460
|
+
}
|
|
461
|
+
static hucreYatayHizasiniBelirle(deger, column) {
|
|
462
|
+
if (typeof deger === 'number') {
|
|
463
|
+
return 'right';
|
|
464
|
+
}
|
|
465
|
+
if (typeof deger === 'object' && deger !== null && 'formula' in deger && this.sayisalFormatMi(column.format)) {
|
|
466
|
+
return 'right';
|
|
467
|
+
}
|
|
468
|
+
return this.yatayHizaDonustur(column.horizontalAlignment);
|
|
469
|
+
}
|
|
470
|
+
static sayisalFormatMi(format) {
|
|
471
|
+
switch (format) {
|
|
472
|
+
case NumberFormatlar.long:
|
|
473
|
+
case NumberFormatlar.real:
|
|
474
|
+
case NumberFormatlar.yuzde_BirHane:
|
|
475
|
+
case 2:
|
|
476
|
+
case 5:
|
|
477
|
+
case 7:
|
|
478
|
+
case 11:
|
|
479
|
+
case 12:
|
|
480
|
+
return true;
|
|
481
|
+
default:
|
|
482
|
+
return false;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
static metinUzunlugu(metin) {
|
|
486
|
+
return metin
|
|
487
|
+
.replaceAll('\r', '')
|
|
488
|
+
.split('\n')
|
|
489
|
+
.reduce((max, parca) => Math.max(max, parca.trim().length), 0);
|
|
490
|
+
}
|
|
491
|
+
static kolonGrubuYaz(worksheet, startRow, startCol, table) {
|
|
492
|
+
const columnGroups = table.columnGroup;
|
|
493
|
+
if (!columnGroups?.length || startRow <= 1) {
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
const grupSatiri = startRow - 1;
|
|
497
|
+
for (const columnGroup of columnGroups) {
|
|
498
|
+
const baslangicIndex = table.columns.findIndex(column => column.property === columnGroup.groupStart);
|
|
499
|
+
const bitisIndex = table.columns.findIndex(column => column.property === columnGroup.groupEnd);
|
|
500
|
+
const baslangicKolonu = baslangicIndex >= 0 ? startCol + baslangicIndex : undefined;
|
|
501
|
+
const bitisKolonu = bitisIndex >= 0 ? startCol + bitisIndex : undefined;
|
|
502
|
+
if (!baslangicKolonu || !bitisKolonu || bitisKolonu < baslangicKolonu) {
|
|
503
|
+
continue;
|
|
504
|
+
}
|
|
505
|
+
worksheet.mergeCells(grupSatiri, baslangicKolonu, grupSatiri, bitisKolonu);
|
|
506
|
+
const grupHucre = worksheet.getCell(grupSatiri, baslangicKolonu);
|
|
507
|
+
grupHucre.value = columnGroup.groupName;
|
|
508
|
+
grupHucre.alignment = { horizontal: 'center', vertical: 'middle' };
|
|
509
|
+
grupHucre.font = { bold: true, size: 11, color: { argb: 'FFF79646' } };
|
|
510
|
+
grupHucre.fill = {
|
|
511
|
+
type: 'pattern',
|
|
512
|
+
pattern: 'solid',
|
|
513
|
+
fgColor: { argb: 'FFFFFFFF' }
|
|
514
|
+
};
|
|
515
|
+
for (let col = baslangicKolonu; col <= bitisKolonu; col++) {
|
|
516
|
+
const hucre = worksheet.getCell(grupSatiri, col);
|
|
517
|
+
hucre.border = {
|
|
518
|
+
...hucre.border,
|
|
519
|
+
top: { style: 'medium', color: { argb: 'FFF79646' } },
|
|
520
|
+
...(col === baslangicKolonu ? { left: { style: 'medium', color: { argb: 'FFF79646' } } } : (hucre.border?.left ? { left: hucre.border.left } : {})),
|
|
521
|
+
...(col === bitisKolonu ? { right: { style: 'medium', color: { argb: 'FFF79646' } } } : (hucre.border?.right ? { right: hucre.border.right } : {}))
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
static hucreDegeriniHazirla(row, column, sifirlariBasmaSayi) {
|
|
527
|
+
const value = row[column.property];
|
|
528
|
+
if ((typeof value === 'string') && value.startsWith('=')) {
|
|
529
|
+
return { formula: this.excelFormuluneDonustur(value) };
|
|
530
|
+
}
|
|
531
|
+
if ((typeof value === 'number') && sifirlariBasmaSayi && (value === 0)) {
|
|
532
|
+
return '';
|
|
533
|
+
}
|
|
534
|
+
if (value === null || value === undefined) {
|
|
535
|
+
return '';
|
|
536
|
+
}
|
|
537
|
+
if (typeof value === 'boolean' || typeof value === 'number' || typeof value === 'string' || value instanceof Date) {
|
|
538
|
+
return value;
|
|
539
|
+
}
|
|
540
|
+
return String(value);
|
|
541
|
+
}
|
|
542
|
+
static benzersizKolonAdlariOlustur(adlar) {
|
|
543
|
+
const sayaclar = new Map();
|
|
544
|
+
return adlar.map(ad => {
|
|
545
|
+
const temelAd = ad || ' ';
|
|
546
|
+
const sayi = sayaclar.get(temelAd) ?? 0;
|
|
547
|
+
sayaclar.set(temelAd, sayi + 1);
|
|
548
|
+
return sayi === 0 ? temelAd : `${temelAd}_${sayi}`;
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
static hucreFontunuUygula(cell, font, defaultFont) {
|
|
552
|
+
const style = font?.style ?? 0;
|
|
553
|
+
const excelFont = {};
|
|
554
|
+
const fontName = font?.name || defaultFont?.name;
|
|
555
|
+
if (fontName) {
|
|
556
|
+
excelFont.name = fontName;
|
|
557
|
+
}
|
|
558
|
+
const fontSize = (font?.size && font.size > 0) ? font.size : defaultFont?.size;
|
|
559
|
+
if (fontSize && fontSize > 0) {
|
|
560
|
+
excelFont.size = fontSize;
|
|
561
|
+
}
|
|
562
|
+
if (font?.color) {
|
|
563
|
+
const color = this.argbDonustur(font.color);
|
|
564
|
+
if (color) {
|
|
565
|
+
excelFont.color = { argb: color };
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
excelFont.bold = Boolean(style & FontStyle.bold);
|
|
569
|
+
excelFont.italic = Boolean(style & FontStyle.italic);
|
|
570
|
+
excelFont.underline = Boolean(style & FontStyle.underline);
|
|
571
|
+
cell.font = excelFont;
|
|
572
|
+
}
|
|
573
|
+
static gecerliTableStyleVer(tableStyle) {
|
|
574
|
+
if (!tableStyle) {
|
|
575
|
+
return undefined;
|
|
576
|
+
}
|
|
577
|
+
const style = tableStyle.trim();
|
|
578
|
+
if (/^TableStyleLight([1-9]|1\d|2[0-1])$/.test(style)) {
|
|
579
|
+
return style;
|
|
580
|
+
}
|
|
581
|
+
if (/^TableStyleMedium([1-9]|1\d|2[0-1])$/.test(style)) {
|
|
582
|
+
return style;
|
|
583
|
+
}
|
|
584
|
+
if (/^TableStyleDark([1-9]|10|11)$/.test(style)) {
|
|
585
|
+
return style;
|
|
586
|
+
}
|
|
587
|
+
return undefined;
|
|
588
|
+
}
|
|
589
|
+
static tableStyleDonustur(theme) {
|
|
590
|
+
if (!theme) {
|
|
591
|
+
return undefined;
|
|
592
|
+
}
|
|
593
|
+
return {
|
|
594
|
+
theme: theme,
|
|
595
|
+
showRowStripes: true
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
static tabloAdiOlustur(sheetName, startRow, startCol) {
|
|
599
|
+
const temizSheetName = sheetName.replaceAll(/[^A-Za-z0-9]/g, '_');
|
|
600
|
+
return `T_${temizSheetName}_R${startRow}C${startCol}`;
|
|
601
|
+
}
|
|
602
|
+
static yatayHizaDonustur(value) {
|
|
603
|
+
switch (value) {
|
|
604
|
+
case XLHAlign.xlHAlignCenter: return 'center';
|
|
605
|
+
case XLHAlign.xlHAlignCenterAcrossSelection: return 'centerContinuous';
|
|
606
|
+
case XLHAlign.xlHAlignDistributed: return 'distributed';
|
|
607
|
+
case XLHAlign.xlHAlignFill: return 'fill';
|
|
608
|
+
case XLHAlign.xlHAlignGeneral: return 'left';
|
|
609
|
+
case XLHAlign.xlHAlignJustify: return 'justify';
|
|
610
|
+
case XLHAlign.xlHAlignLeft: return 'left';
|
|
611
|
+
case XLHAlign.xlHAlignRight: return 'right';
|
|
612
|
+
default: return 'left';
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
static dikeyHizaDonustur(value) {
|
|
616
|
+
switch (value) {
|
|
617
|
+
case XLVAlign.xlVAlignTop: return 'top';
|
|
618
|
+
case XLVAlign.xlVAlignBottom: return 'bottom';
|
|
619
|
+
case XLVAlign.xlVAlignDistributed: return 'distributed';
|
|
620
|
+
case XLVAlign.xlVAlignJustify: return 'justify';
|
|
621
|
+
default: return 'middle';
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
static argbDonustur(color) {
|
|
625
|
+
if (!color) {
|
|
626
|
+
return undefined;
|
|
627
|
+
}
|
|
628
|
+
if (/^[0-9A-Fa-f]{8}$/.test(color)) {
|
|
629
|
+
return color.toUpperCase();
|
|
630
|
+
}
|
|
631
|
+
const numericColor = Number(color);
|
|
632
|
+
if (!Number.isFinite(numericColor)) {
|
|
633
|
+
return undefined;
|
|
634
|
+
}
|
|
635
|
+
const r = numericColor & 255;
|
|
636
|
+
const g = (numericColor >> 8) & 255;
|
|
637
|
+
const b = (numericColor >> 16) & 255;
|
|
638
|
+
return `FF${[r, g, b].map(value => value.toString(16).padStart(2, '0')).join('').toUpperCase()}`;
|
|
639
|
+
}
|
|
640
|
+
static excelFormuluneDonustur(formul) {
|
|
641
|
+
const ceviriler = {
|
|
642
|
+
'TOPLA': 'SUM',
|
|
643
|
+
'EĞER': 'IF',
|
|
644
|
+
'VE': 'AND',
|
|
645
|
+
'VEYA': 'OR',
|
|
646
|
+
'YUVARLA': 'ROUND',
|
|
647
|
+
'EĞERSAY': 'COUNTIF',
|
|
648
|
+
'ETOPLA': 'SUMIF',
|
|
649
|
+
'ORTALAMA': 'AVERAGE',
|
|
650
|
+
'MİN': 'MIN',
|
|
651
|
+
'MAK': 'MAX'
|
|
652
|
+
};
|
|
653
|
+
let sonuc = formul.slice(1).replaceAll(';', ',');
|
|
654
|
+
for (const [kaynak, hedef] of Object.entries(ceviriler)) {
|
|
655
|
+
const pattern = new RegExp(`\\b${kaynak}\\b`, 'g');
|
|
656
|
+
sonuc = sonuc.replace(pattern, hedef);
|
|
657
|
+
}
|
|
658
|
+
return sonuc;
|
|
659
|
+
}
|
|
660
|
+
static sayfaAdiDuzenle(sheetName, index) {
|
|
661
|
+
const temizAd = sheetName
|
|
662
|
+
.replaceAll(/[\\/*?:[\]]/g, ' ')
|
|
663
|
+
.trim()
|
|
664
|
+
.slice(0, 31);
|
|
665
|
+
if (temizAd) {
|
|
666
|
+
return temizAd;
|
|
667
|
+
}
|
|
668
|
+
return `Sheet${index}`;
|
|
669
|
+
}
|
|
670
|
+
static dosyaAdiDuzenle(dosyaAdi) {
|
|
671
|
+
const temizAd = dosyaAdi
|
|
672
|
+
.replaceAll(/[<>:"/\\|?*]/g, ' ')
|
|
673
|
+
.trim()
|
|
674
|
+
.replaceAll(/\s+/g, ' ');
|
|
675
|
+
if (temizAd) {
|
|
676
|
+
return temizAd;
|
|
677
|
+
}
|
|
678
|
+
return 'Rapor';
|
|
679
|
+
}
|
|
680
|
+
static numberFormatDonustur(format) {
|
|
681
|
+
switch (format) {
|
|
682
|
+
case NumberFormatlar.long:
|
|
683
|
+
case 2:
|
|
684
|
+
case 5:
|
|
685
|
+
case 11:
|
|
686
|
+
return '#,##0';
|
|
687
|
+
case NumberFormatlar.real:
|
|
688
|
+
case 7:
|
|
689
|
+
case 12:
|
|
690
|
+
return '#,##0.00';
|
|
691
|
+
case 8:
|
|
692
|
+
return 'hh:mm';
|
|
693
|
+
case NumberFormatlar.tarih:
|
|
694
|
+
return 'dd.mm.yyyy';
|
|
695
|
+
case NumberFormatlar.tarih_yyyymmdd_tireli:
|
|
696
|
+
return 'yyyy-mm-dd';
|
|
697
|
+
case NumberFormatlar.tarih_AAAAYYYY:
|
|
698
|
+
return 'mmmm yyyy';
|
|
699
|
+
case NumberFormatlar.tarih_GGAAAAYYYY:
|
|
700
|
+
return 'dd mmmm yyyy';
|
|
701
|
+
case NumberFormatlar.tarih_YYYYMMDD:
|
|
702
|
+
return 'yyyy/mm/dd';
|
|
703
|
+
case NumberFormatlar.tarih_LongDate:
|
|
704
|
+
return 'dd mmmm yyyy dddd';
|
|
705
|
+
case NumberFormatlar.tarih_ga:
|
|
706
|
+
return 'd.m;@';
|
|
707
|
+
case NumberFormatlar.tarih_ggaa:
|
|
708
|
+
return 'dd.mm';
|
|
709
|
+
case NumberFormatlar.tarih_gaaaa:
|
|
710
|
+
return 'd.mmmm';
|
|
711
|
+
case NumberFormatlar.tarih_ggaaa:
|
|
712
|
+
return 'dd.mmm';
|
|
713
|
+
case NumberFormatlar.tarih_ggaaaa:
|
|
714
|
+
return 'dd.mmmm';
|
|
715
|
+
case NumberFormatlar.yuzde_BirHane:
|
|
716
|
+
return '0.0%';
|
|
717
|
+
case NumberFormatlar.genel:
|
|
718
|
+
return 'General';
|
|
719
|
+
case NumberFormatlar.metin:
|
|
720
|
+
return '@';
|
|
721
|
+
case NumberFormatlar.imp:
|
|
722
|
+
return '#,##0 "imp"';
|
|
723
|
+
case NumberFormatlar.clicks:
|
|
724
|
+
return '#,##0 "Clicks"';
|
|
725
|
+
case NumberFormatlar.gun:
|
|
726
|
+
return '#,##0 "Gün"';
|
|
727
|
+
case NumberFormatlar.view:
|
|
728
|
+
return '#,##0 "View"';
|
|
729
|
+
case NumberFormatlar.session:
|
|
730
|
+
return '#,##0 "Session"';
|
|
731
|
+
case NumberFormatlar.kisi:
|
|
732
|
+
return '#,##0 "Kişi"';
|
|
733
|
+
case NumberFormatlar.okunma:
|
|
734
|
+
return '#,##0 "Okunma"';
|
|
735
|
+
case NumberFormatlar.dinlenme:
|
|
736
|
+
return '#,##0 "Dinlenme"';
|
|
737
|
+
case NumberFormatlar.lead:
|
|
738
|
+
return '#,##0 "Lead"';
|
|
739
|
+
case NumberFormatlar.gizli:
|
|
740
|
+
return ';;;';
|
|
741
|
+
default:
|
|
742
|
+
return undefined;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
class BlobResponseHandlerService {
|
|
748
|
+
constructor() {
|
|
749
|
+
this.translateService = inject(TranslateService);
|
|
750
|
+
}
|
|
751
|
+
handleReportResponse(response, successDetailKey, htmlTitle = 'Rapor Sonucu') {
|
|
752
|
+
const body = response.body;
|
|
753
|
+
if (!body) {
|
|
754
|
+
return null;
|
|
755
|
+
}
|
|
756
|
+
const contentDisposition = response.headers.get('content-disposition');
|
|
757
|
+
const contentType = response.headers.get('Content-Type') ?? body.type;
|
|
758
|
+
if (contentDisposition) {
|
|
759
|
+
return this.handleDownload(body, contentDisposition, contentType, successDetailKey);
|
|
760
|
+
}
|
|
761
|
+
this.handleViewHtml(body, htmlTitle);
|
|
762
|
+
return null;
|
|
763
|
+
}
|
|
764
|
+
downloadResponse(response) {
|
|
765
|
+
const body = response.body;
|
|
766
|
+
if (!body) {
|
|
767
|
+
return false;
|
|
768
|
+
}
|
|
769
|
+
const contentDisposition = response.headers.get('content-disposition');
|
|
770
|
+
if (!contentDisposition) {
|
|
771
|
+
return false;
|
|
772
|
+
}
|
|
773
|
+
const contentType = response.headers.get('Content-Type') ?? (body instanceof Blob ? body.type : 'application/octet-stream');
|
|
774
|
+
this.downloadBlob(body, contentDisposition, contentType);
|
|
775
|
+
return true;
|
|
776
|
+
}
|
|
777
|
+
viewHtmlBody(body, htmlTitle = 'Rapor Sonucu') {
|
|
778
|
+
if (!body) {
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
781
|
+
this.handleViewHtml(body, htmlTitle);
|
|
782
|
+
}
|
|
783
|
+
async handleJsonExcelResponse(body, options) {
|
|
784
|
+
if (!body) {
|
|
785
|
+
return null;
|
|
786
|
+
}
|
|
787
|
+
try {
|
|
788
|
+
const jsonStr = await body.text();
|
|
789
|
+
const result = Object.assign(options.createResult(), JSON.parse(jsonStr));
|
|
790
|
+
const fileName = options.getFileName?.(result) ?? options.fileName;
|
|
791
|
+
if (!fileName) {
|
|
792
|
+
return null;
|
|
793
|
+
}
|
|
794
|
+
await JsonToExcelParser.indir(result, fileName);
|
|
795
|
+
return {
|
|
796
|
+
severity: 'success',
|
|
797
|
+
summary: this.translateService.instant('genel.bilgi'),
|
|
798
|
+
detail: options.successDetail ?? this.translateService.instant(options.successDetailKey ?? '')
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
catch (error) {
|
|
802
|
+
console.error(options.errorLogMessage, error);
|
|
803
|
+
return null;
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
handleDownload(body, contentDisposition, contentType, successDetailKey) {
|
|
807
|
+
this.downloadBlob(body, contentDisposition, contentType);
|
|
808
|
+
return {
|
|
809
|
+
severity: 'success',
|
|
810
|
+
summary: this.translateService.instant('genel.bilgi'),
|
|
811
|
+
detail: this.translateService.instant(successDetailKey)
|
|
812
|
+
};
|
|
813
|
+
}
|
|
814
|
+
downloadBlob(body, contentDisposition, contentType) {
|
|
815
|
+
const decodedContentDisposition = contentDisposition.replaceAll(/\\u([0-9A-Fa-f]{4})/g, (_, code) => String.fromCodePoint(Number.parseInt(code, 16)));
|
|
816
|
+
const filename = GlobalFunctions.getFilenameFromContentDisposition(decodedContentDisposition);
|
|
817
|
+
const blob = new Blob([body], { type: contentType });
|
|
818
|
+
saveAs(blob, filename);
|
|
819
|
+
}
|
|
820
|
+
handleViewHtml(body, htmlTitle) {
|
|
821
|
+
body.text().then((html) => {
|
|
822
|
+
const wnd = window.open('', '_blank');
|
|
823
|
+
if (!wnd) {
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
wnd.document.title = htmlTitle;
|
|
827
|
+
const iframe = wnd.document.createElement('iframe');
|
|
828
|
+
iframe.style.width = '100%';
|
|
829
|
+
iframe.style.height = '100%';
|
|
830
|
+
iframe.style.border = 'none';
|
|
831
|
+
iframe.setAttribute('srcdoc', html);
|
|
832
|
+
wnd.document.body.style.margin = '0';
|
|
833
|
+
wnd.document.body.style.padding = '0';
|
|
834
|
+
wnd.document.body.appendChild(iframe);
|
|
835
|
+
});
|
|
836
|
+
}
|
|
837
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.15", ngImport: i0, type: BlobResponseHandlerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
838
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.15", ngImport: i0, type: BlobResponseHandlerService, providedIn: 'root' }); }
|
|
839
|
+
}
|
|
840
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.15", ngImport: i0, type: BlobResponseHandlerService, decorators: [{
|
|
841
|
+
type: Injectable,
|
|
842
|
+
args: [{ providedIn: 'root' }]
|
|
843
|
+
}] });
|
|
844
|
+
|
|
845
|
+
class ExcelRaporuSonuc {
|
|
846
|
+
constructor() {
|
|
847
|
+
this.book = {
|
|
848
|
+
author: 'MedPlan',
|
|
849
|
+
activeSheetNo: 1
|
|
850
|
+
};
|
|
851
|
+
this.defaultFont = {
|
|
852
|
+
name: 'Calibri',
|
|
853
|
+
size: 11
|
|
854
|
+
};
|
|
855
|
+
this.currentTableStyle = '';
|
|
856
|
+
this.sifirlariBasmaSayi = false;
|
|
857
|
+
this.sifirlariBasmaTarih = false;
|
|
858
|
+
// Yeni format: her sheet kendi tablolarını, üst bilgilerini ve notlarını taşır
|
|
859
|
+
this.sheets = [];
|
|
860
|
+
this.window = {
|
|
861
|
+
displayGridLines: false
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
/**
|
|
867
|
+
* Generated bundle index. Do not edit.
|
|
868
|
+
*/
|
|
869
|
+
|
|
870
|
+
export { BlobResponseHandlerService, ExcelRaporuSonuc, JsonToExcelParser };
|
|
871
|
+
//# sourceMappingURL=limitng-blob-response-handler.mjs.map
|