admin管理员组文章数量:1399916
I have managed to find out how to pull data from a excel file into HTML.
I am now trying to look how to search for values within a set of cells. Does anyone know how to achieve this?
Thanks in advance!
I have managed to find out how to pull data from a excel file into HTML.
I am now trying to look how to search for values within a set of cells. Does anyone know how to achieve this?
Thanks in advance!
Share Improve this question asked May 22, 2014 at 13:24 KM123KM123 1,3871 gold badge11 silver badges21 bronze badges 2- if my answer is not helpful, i think i will need some more info, an example of what you are trying to search for/against and what you are looking to do with the results. – workabyte Commented May 22, 2014 at 13:37
- Please provide code how you were able to convert the Excel data to HTML. That will help to answer how to search in the data. – Petr Hejda Commented May 30, 2018 at 12:43
4 Answers
Reset to default 0jQuery is likely going to help you with that. when building the HTML i would also add data-[somethingHelpfulWhenSearching] or add class values that could help.
then you can search for the item by class
$('.[searchableClassName]')
or by data attribute:
$('[data-[somethingHelpfulWhenSearching]') //only looking that the tag exists
$('[data-[somethingHelpfulWhenSearching]="something im looking for"') //only looking that the tag and checking the value
hope this helps
From the way you worded the question, it sounds like you have a table in your HTML, and you just want to loop over all of the cells to check which cells contain a given value, and return those DOM nodes that contain the provided search string within their text content. If that's an accurate interpretation, here is a Vanilla JS solution:
function findCells(str) {
var allCells = document.querySelectorAll("td");
var matchingCells = [];
for (var i = 0; i < allCells.length; i++) {
if (allCells[i].textContent.indexOf(str) !== -1) {
matchingCells.push(allCells[i]);
}
}
return matchingCells;
}
<html>
<script>
function mytest1() {
var Excel, Book; // Declare the variables
Excel = new ActiveXObject("Excel.Application"); // Create the Excel application object.
Excel.Visible = false; // Make Excel invisible.
Book = Excel.Workbooks.Add() // Create a new work book.
Book.ActiveSheet.Cells(2, 2).Value = document.all.my_textarea1.value;
Book.SaveAs("C:/temp/TEST.xls");
Excel.Quit(); // Close Excel with the Quit method on the Application object.
}
function mytest2() {
var Excel;
Excel = new ActiveXObject("Excel.Application");
Excel.Visible = false;
form1.my_textarea2.value = Excel.Workbooks.Open("C:/temp/TEST.xls").ActiveSheet.Cells(1, 1).Value;
Excel.Quit();
}
</script>
<body>
<form name="form1">
<input type=button onClick="mytest1();" value="Send Excel Data">
<input type=text name="my_textarea1" size=70 value="enter ur data here">
<br><br>
<input type=button onClick="mytest2();" value="Get Excel Data">
<input type=text name="my_textarea2" size=70 value="no data collected yet">
</form>
</body>
</html>
Since you're already using jQuery, try DataTables, which is a jQuery plugin and does a lot more than filtering for you. It allows for both client side and server side filtering, so it's not a problem if your table is large.
本文标签: javascriptExcel data into html outputStack Overflow
版权声明:本文标题:javascript - Excel data into html output - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744241143a2596795.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论