Created
February 25, 2013 08:07
-
-
Save do-aki/5028435 to your computer and use it in GitHub Desktop.
Excel 向け日本語 CSV ファイル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="ja"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>日本語csv sample</title> | |
</head> | |
<body> | |
<a id="js-download" href="dummy">download</a> | |
<script> | |
// (1) BOM の用意 | |
var bom = new Uint8Array([0xEF, 0xBB, 0xBF]); | |
// (2) CSV データの用意 | |
var csv_data = [ | |
['日本語の', 'CSVだと', '思いなせぇ'], | |
['"クォ""テーション"', '"セル内\n改行"', '="00001"'] | |
].map(function(l){return l.join(',')}).join('\r\n'); | |
// (3) BOM 付き CSV ファイルの元となる Blob を作成 | |
var blob = new Blob([bom, csv_data], { type: 'text/csv' }); | |
// (4) createObjectURL を使って Blob URL を構築 | |
var url = (window.URL || window.webkitURL).createObjectURL(blob); | |
// (5) Blob URL をダウンロードさせるリンクを作る | |
var a = document.getElementById('js-download'); | |
a.download = 'filename.csv'; | |
a.href = url; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment