下記のソースで取得できるはず!!!
{
①include script
src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js">
src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.8.0/jszip.js">
src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.8.0/xlsx.js">
②自分作るScript:
var ExcelToJSON = function() {
this.parseExcel = function(file) {
var reader = new FileReader();
reader.onload = function(e) {
var data = e.target.result;
var workbook = XLSX.read(data, {
type: 'binary'
});
console.log(workbook)
$('#sheet_name').empty()
$('.txt_sheet').empty()
var itemHtml = ''
workbook.Workbook.Sheets.forEach(function(sheet) {
itemHtml = itemHtml + '' + sheet.name + ''
})
$('#sheet_name').html(itemHtml)
$('.txt_sheet').html(itemHtml)
};
reader.onerror = function(ex) {
console.log(ex);
};
reader.readAsBinaryString(file);
};
};
function handleFileSelect(evt) {
var files = evt.target.files;
var xl2json = new ExcelToJSON();
xl2json.parseExcel(files[0]);
$('#template_file').val($(this).val().replace(/^.*\/, ""));
}
③ファイルコントロールChangeイベント追加
document.getElementById('upload_file').addEventListener('change', handleFileSelect, false);
}
※upload_file →file_field_tag