Files
ihaleist/src/services/tenderWorkbook.js
T

22 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// User/source text stays a string cell, including leading '=' and embedded newlines.
export async function createTenderWorkbook(tenders) {
if (!Array.isArray(tenders) || !tenders.length) throw new Error('Dışa aktarılacak ihale bulunamadı.');
const {default:ExcelJS} = await import('exceljs');
const book = new ExcelJS.Workbook();
book.creator = 'İhaleist';
const sheet = book.addWorksheet('İhale Listesi');
sheet.columns = [
['İKN',20],['Başlık',65],['Kurum',45],['Şehir',20],['İhale tarihi',18],
['İhale saati',15],['Alım türü',25],['Sektör',30],['CPV',35],['Kaynak',55],
].map(([header,width])=>({header,width}));
for (const t of tenders) {
sheet.addRow([t.ikn,t.baslik,t.kurum,t.sehir,t.tarih,t.saat,t.alimTuru,t.sektor,
t.cpvLabel || (Array.isArray(t.cpv) ? t.cpv.join(', ') : t.cpv),t.kaynakUrl].map(v=>String(v ?? '')));
}
sheet.views = [{state:'frozen',ySplit:1}];
sheet.autoFilter = {from:'A1',to:`J${tenders.length+1}`};
sheet.getRow(1).font = {bold:true};
sheet.eachRow(row=>{row.alignment={vertical:'top',wrapText:true};});
return book.xlsx.writeBuffer();
}