<分区>
我已将 excel 文件保存为 .csv 文件,我想将该数据导入 HTML 表格中
例如.csv 文件中的数据为
Name, Father's Name, Roll No., Attendance
abc,xyz,11011519-059,P
abs,ijk,11011519-007,A
这段代码运行良好。它从 .csv 或 .txt 文件中成功读取数据,但我的问题是我想要 HTML 表中的数据。您能否提供一个我可以在此代码上实现的简单解决方案。
<!DOCTYPE html>
<html>
<head>
<title>Read File (via User Input selection)</title>
<script type="text/javascript">
var reader; //GLOBAL File Reader object for demo purpose only
/**
* Check for the various File API support.
*/
function checkFileAPI() {
if (window.File && window.FileReader && window.FileList && window.Blob) {
reader = new FileReader();
return true;
} else {
alert('The File APIs are not fully supported by your browser. Fallback required.');
return false;
}
}
/**
* read text input
*/
function readText(filePath) {
var output = ""; //placeholder for text output
if (filePath.files && filePath.files[0]) {
reader.onload = function (e) {
output = e.target.result;
displayContents(output);
};//end onload()
reader.readAsText(filePath.files[0]);
}//end if html5 filelist support
else { //this is where you could fallback to Java Applet, Flash or similar
return false;
}
return true;
}
/**
* display content using a basic HTML replacement
*/
function displayContents(txt) {
var el = document.getElementById('main');
el.innerHTML = txt; //display output in DOM
}
</script>
</head>
<body>
</body>
</html>