How to use the write function from xlsx

Find comprehensive JavaScript xlsx.write code examples handpicked from public code repositorys.

62
63
64
65
66
67
68
69
70
71
    var name = worksheet.name || 'Sheet';
    var data = sheet_from_array_of_arrays(worksheet.data || []);
    wb.SheetNames.push(name);
    wb.Sheets[name] = data;
  });
  var data = XLSX.write(wb, _.defaults(options || {}, defaults));
  if(!data) return false;
  var buffer = new Buffer(data, 'binary');
  return buffer;
}
fork icon270
star icon0
watch icon2

63
64
65
66
67
68
69
70
71
72
const bufferFromJson = function(sheetName, values) {
  const options = { bookType: 'xlsx', bookSST: false, type: 'buffer' };
  const workBook = new Workbook([sheetName]);
  workBook.setCellValuesForSheet(sheetName, values);

  return xlsx.write(workBook, options);
};

const bufferFromMultiValues = (values) => {
  const sheetNames = Object.keys(values);
fork icon0
star icon4
watch icon1

+ 3 other calls in file

93
94
95
96
97
98
99
100
101
    /* add worksheet to workbook */
    wb.SheetNames.push(ws_name);
    wb.Sheets[ws_name] = ws;

    var wopts = { bookType:'xlsx', bookSST:false, type:'binary' };
    return XLSX.write(wb,wopts);
    /* write file */
    //XLSX.writeFile(wb, 'test.xlsx');
}
fork icon0
star icon3
watch icon3

36
37
38
39
40
41
42
43
44
45
}));
const workbook = XLSX.utils.book_new();
//const sheetrr= flatten(worksheet, flatRow);
XLSX.utils.book_append_sheet(workbook, worksheet, "Sheet1");
// XLSX.writeFileXLSX(workbook,"MYTABLE.xlsx");
const fileBuffer = XLSX.write(workbook, {
  bookType: "xlsx",
  type: "array"
});
const file = new Blob([fileBuffer], {
fork icon2
star icon0
watch icon0

11
12
13
14
15
16
17
18
19
20
  // Convert the Mongoose documents to plain JavaScript objects
  const jsonData = JSON.parse(JSON.stringify(data))
  const worksheet = XLSX.utils.json_to_sheet(jsonData);
  const workbook = XLSX.utils.book_new();
  XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
  const excelBuffer = XLSX.write(workbook, { bookType: 'xlsx', type: 'buffer' });
  res.set('Content-Type', 'application/octet-stream');
  res.set('Content-Disposition', 'attachment; filename=export.xlsx');
  res.send(excelBuffer);
})
fork icon0
star icon1
watch icon0

332
333
334
335
336
337
338
339
340
const workSheetData = [workSheetColumnName, ...data];
const workSheet = XLSX.utils.aoa_to_sheet(workSheetData);
const workBook = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(workBook, workSheet, "Productos");

const binaryWorkbook = XLSX.write(workBook, {
  type: "buffer",
  bookType: "xlsx"
});
fork icon0
star icon0
watch icon1

122
123
124
125
126
127
128
129
130
131
// Method for converting in to excel Sheet
const convertJsonToExcel = () => {
  const workbook = XLSX.utils.book_new();
  const worksheet = XLSX.utils.json_to_sheet(arr);
  XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
  const excelBuffer = XLSX.write(workbook, { type: 'buffer', bookType: 'xlsx' });


  // Downloading the Excel Sheet 
  res.setHeader('Content-Disposition', `attachment; filename=${results.name}_Data.xlsx`);
fork icon0
star icon0
watch icon1

221
222
223
224
225
226
227
228
229
230
  const content2 = data2Pre.map((row) => Object.values(row));
  const data2 = [headers2, ...content2];
  const wb = XLSX.utils.book_new();
  XLSX.utils.book_append_sheet(wb, XLSX.utils.aoa_to_sheet(data1), 'Productos por cliente');
  XLSX.utils.book_append_sheet(wb, XLSX.utils.aoa_to_sheet(data2), 'Productos agrupados');
  const buf = XLSX.write(wb, { type: 'buffer', bookType: 'xlsx' });
  res.setHeader('Content-Type', 'application/vnd.openxmlformats');
  res.setHeader('Content-Disposition', `attachment; filename=Ordenes_${STATUS_LIST.find((status) => status.value === statusFilter)?.label ?? 'TODOS'}_${fromFullDay.toISOString().split('T')[0]}a${toFullDay.toISOString().split('T')[0]}.xlsx`);
  res.end(buf);
} catch (error) {
fork icon0
star icon0
watch icon1

+ 5 other calls in file

28
29
30
31
32
33
34
35
36
37
/* file is stored in a temp directory, so we can point to that and read it */
const wb = XLSX.read(f.path, {type:"file"});

/* convert to specified output type -- default CSV */
const ext = (fields.bookType || "csv").toLowerCase();
const out = XLSX.write(wb, {type:"string", bookType:ext});

context.res = {
	status: 200,
	headers: { "Content-Disposition": `attachment; filename="download.${ext}";` },
fork icon0
star icon0
watch icon0

62
63
64
65
66
67
68
69
70
71

splitJfu?.forEach((item, index) => {
    const wb = xlsx.utils.book_new();
    const ws = xlsx.utils.json_to_sheet(item);
    xlsx.utils.book_append_sheet(wb, ws, "Sheet1");
    const buffer = xlsx.write(wb, { type: "buffer" });
    excel[indexKey].addFile(
        `data-jfu-${key}-${index}.xlsx`,
        buffer
    );
fork icon0
star icon0
watch icon0

+ 4 other calls in file

1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
});

// debug code do remove
// xlsx.writeFile(wb, 'uploads_tmp/sheetgen.xlsx');
// clustering sheets
var wbout = xlsx.write(wb, {
    bookType: 'xlsx',
    bookSST: false,
    type: 'binary'
});
fork icon0
star icon0
watch icon0

189
190
191
192
193
194
195
196
197
198
const workSheet = XLSX.utils.json_to_sheet(data);
const workBook = XLSX.utils.book_new();

XLSX.utils.book_append_sheet(workBook, workSheet, "students")
// Generate buffer
XLSX.write(workBook, { bookType: 'xlsx', type: "buffer" })

// Binary string
XLSX.write(workBook, { bookType: "xlsx", type: "binary" })
const dirPath0 = __dirname.replace(/\.next.*/i, '');
fork icon0
star icon0
watch icon0

20
21
22
23
24
25
26
27
28
29
const wb = XLSX.utils.book_new();
// buat worksheet baru dengan nama "Data"
const ws = XLSX.utils.json_to_sheet(data);
XLSX.utils.book_append_sheet(wb, ws, "Data");
// simpan file Excel ke dalam bentuk binary string
const wbout = XLSX.write(wb, { bookType: "xlsx", type: "binary" });
// unduh file Excel ke dalam browser
saveAs(
    new Blob([s2ab(wbout)], { type: "application/octet-stream" }),
    "data.xlsx"
fork icon0
star icon0
watch icon0

263
264
265
266
267
268
269
270
271
272
        description: 'XLSX file',
        accept: { "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": ['.xlsx', '.xls'] }
    }]
});

const u8 = XLSX.write(wb, { type: "buffer", bookType: "xlsx" });
const data = new Blob([u8], { type: "application/vnd.ms-excel" });
const writable = await handle.createWritable();
await writable.write(data);
await writable.close();
fork icon0
star icon0
watch icon1