<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
var spData = null;
function doData(json) {
spData = json.feed.entry;
}
function drawCell(tr, val) {
var td = $("<td/>");
tr.append(td);
td.append(val);
return td;
}
function drawRow(table, rowData) {
if (rowData == null) return null;
if (rowData.length == 0) return null;
var tr = $("<tr/>");
table.append(tr);
for(var c=0; c<rowData.length; c++) {
drawCell(tr, rowData[c]);
if( document.getElementById("kd0").value==rowData[0]){
document.getElementById("kd").value=rowData[0];
document.getElementById("kd2").value=rowData[1];
document.getElementById("kd3").value=rowData[2];
}
}
return tr;
}
function drawTable(parent) {
var table = $("<table/>");
parent.append(table);
return table;
}
function readData(parent) {
var data = spData;
var table = drawTable(parent);
var rowData = [];
for(var r=0; r<data.length; r++) {
var cell = data[r]["gs$cell"];
var val = cell["$t"];
if (cell.col == 1) {
drawRow(table, rowData);
rowData = [];
}
rowData.push(val);
}
drawRow(table, rowData);
}
$(document).ready(function(){
readData($("#data"));
});
</script>
<script src="https://spreadsheets.google.com/feeds/cells/1gywN-HyPkF777531Fa8FYMGkNVmzWOkt-4_-TsjGxK4/1/public/values?alt=json-in-script&callback=doData"></script>
<div id="data"/>
<input type="text" id="kd0" value="1" />
<input type="text" id="kd" value="Show location" />
<input type="text" id="kd2" value="Show location" />
<input type="text" id="kd3" value="Show location" />
thay đường dẫn file
https://docs.google.com/spreadsheets/d/1gywN-HyPkF777531Fa8FYMGkNVmzWOkt-4_-TsjGxK4/edit?ts=56697da5#gid=0
vào đoạn json là ok
ta có thể xử lý file exel như là 1 csdl online miễn phí đọc và ghi google docs
No comments: