console
$(function(){
$('#file').change(_=>{
console.log('change');
});
$('#export').click(_=>{
console.log('click');
const file = $('#file')[0].files[0];
console.log(file);
const reader = new FileReader();
reader.onload = function (e) {
let data = e.target.result;
let workbook = XLSX.read(data, {type: 'binary'});
console.log(workbook);
const sheetNames = workbook.SheetNames;
$.each(sheetNames, (index, sheetName) => {
let worksheet = workbook.Sheets[sheetName];
const jsonArray = XLSX.utils.sheet_to_json(worksheet);
});
};
reader.readAsBinaryString(file);
})
$('#create').click(_=>{
console.log('create');
var wb = XLSX.utils.book_new();
var ws = XLSX.utils.aoa_to_sheet([["a","b"],[1,2,3]]);
XLSX.utils.book_append_sheet(wb, ws, "SheetJS");
XLSX.writeFile(wb, "SheetJS.xlsb", {compression:true});
})
})
<table id="table" class="table table-bordered">
<thead>
<tr>
<th>名称</th>
<th>城市</th>
<th>邮编</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tanmay</td>
<td>Bangalore</td>
<td>560001</td>
</tr>
<tr>
<td>Sachin</td>
<td>Mumbai</td>
<td>400003</td>
</tr>
<tr>
<td>Uma</td>
<td>Pune</td>
<td>411027</td>
</tr>
</tbody>
</table>
<input type="file" id="file">
<input type="button" id="export" value="导出excel"/>
<input type="button" id="create" value="生成excel"/>