最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - display a table from a excel sheet - Stack Overflow

programmeradmin4浏览0评论

I want to display a table from a excel sheet in my html page. There are multiple tables in a excel sheet. I want a specific table to be displayed. Please Help..

The HTML code i used to extract information from excel file

 <html>
 <head>
 <title>
 From Excel
 </title>
 <script language="javascript" >
 function GetData(cell,row){
 var excel = new ActiveXObject("Excel.Application");
 var excel_file = excel.Workbooks.Open("C:\\abc.xlsx");
 var excel_sheet = excel.Worksheets("25 PEs");
 var data = excel_sheet.Cells(cell,row).Value;
 document.getElementById('div1').innerText =data;
}
</script>
</head>

<body>

<div id="div1" style="background: #DFDFFF; width:'100%';" align="center">
Click buttons to fetch data from c:\abc.xlsx
</div>

<input name="Button1" type="button" onClick="GetData(1,1)" value="button1">
<input name="Button2" type="button" onClick="GetData(1,2)" value="button2">
<input name="Button3" type="button" onClick="GetData(2,1)" value="button3">
<input name="Button4" type="button" onClick="GetData(2,2)" value="button4">


</body>
</html>

This code extracts one cell at a time. I want to extract an entire table at once. How to do it?

I want to display a table from a excel sheet in my html page. There are multiple tables in a excel sheet. I want a specific table to be displayed. Please Help..

The HTML code i used to extract information from excel file

 <html>
 <head>
 <title>
 From Excel
 </title>
 <script language="javascript" >
 function GetData(cell,row){
 var excel = new ActiveXObject("Excel.Application");
 var excel_file = excel.Workbooks.Open("C:\\abc.xlsx");
 var excel_sheet = excel.Worksheets("25 PEs");
 var data = excel_sheet.Cells(cell,row).Value;
 document.getElementById('div1').innerText =data;
}
</script>
</head>

<body>

<div id="div1" style="background: #DFDFFF; width:'100%';" align="center">
Click buttons to fetch data from c:\abc.xlsx
</div>

<input name="Button1" type="button" onClick="GetData(1,1)" value="button1">
<input name="Button2" type="button" onClick="GetData(1,2)" value="button2">
<input name="Button3" type="button" onClick="GetData(2,1)" value="button3">
<input name="Button4" type="button" onClick="GetData(2,2)" value="button4">


</body>
</html>

This code extracts one cell at a time. I want to extract an entire table at once. How to do it?

Share Improve this question edited Mar 21, 2013 at 16:04 Sourav301 1,2591 gold badge14 silver badges24 bronze badges asked Mar 21, 2013 at 7:56 userXuserX 781 gold badge1 silver badge6 bronze badges 2
  • any limitation? what language you prefer? – Alec Commented Mar 21, 2013 at 7:59
  • Do you understand that this code works only if Excel file are placed on client machine ? – ceth Commented Mar 21, 2013 at 8:25
Add a ment  | 

1 Answer 1

Reset to default 4

A good option is to use the jquery library dataTables. You can then use a tool such as that provided by Mr DataConverter to convert your spreadsheet into json. You then point your datatables to the json file, filter out any columns you dont need, and viola, your data is displayed in a nice html table, and customised to how you like it. I have used this approach just recently and it has made displaying a huge amount of data that much easier.

DataTables - http://www.datatables/

Mr Data Converter - http://www.shancarter./data_converter/index.html

The code to hide individual columns would look something like this in your dataTables intializer:

"aoColumnDefs" : [{
    "bVisible" : false,
    "bSearchable": true, 
    "aTargets" : [0, 1, 4, 6, 9, 10, 11, 12]
}

and to re-order the columns would look something like:

"aoColumns": [//reorder the columns
    { "mDataProp": [0] },
    { "mDataProp": [1] },
    { "mDataProp": [2] },
    { "mDataProp": [7] },
    { "mDataProp": [4] },
],

hope this is of some help...

发布评论

评论列表(0)

  1. 暂无评论