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 3 years have passed since last update.

Rails - Jquery でEXCELシート情報取得

Last updated at Posted at 2020-09-16

下記のソースで取得できるはず!!!
{
①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

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?