0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

plunkerでexceljs

Posted at

概要

plunkerでexceljs、やってみた。

サンプルコード


function run() {
	let wb = new ExcelJS.Workbook();
	var sheet1 = wb.addWorksheet("test");
	var worksheet = wb.getWorksheet("test");
	worksheet.getCell(1, 1).value = "商品";
	worksheet.getCell(2, 1).value = "りんご";
	worksheet.getCell(3, 1).value = "みかん";
	worksheet.getCell(4, 1).value = "ぶどう";	
	worksheet.getCell('B1').value = "Item";
	worksheet.getCell('C1').value = "Plice";
	var Item = [["apple", 150], ["orange", 200], ["grape", 280]];
	for (var row = 0; row < Item.length; row++)
	{
		worksheet.getCell(row + 2, 2).value = Item[row][0];
		worksheet.getCell(row + 2, 3).value = Item[row][1];
	}
	worksheet.mergeCells('A5:C5');
	worksheet.getCell('A5').value =  {
		formula: "SUM(C2:C4)"
	};
	wb.xlsx.writeBuffer().then(function(buffer) {
		var blob = new Blob([buffer], {
			type: "application/octet-stream"
		});
		var url = URL.createObjectURL(blob);
		var a = document.createElement('A');
		a.download = 'test.xlsx';
		a.href = url;
		document.body.appendChild(a);
		a.click();
		document.body.removeChild(a);
	});
	alert("ok");
}




成果物

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?