将Excel数据转换为html输出

时间:2014-05-22 13:24:49

标签: javascript jquery html

我已经设法找出如何将excel文件中的数据提取到HTML中。

我现在正在尝试查看如何在一组单元格中搜索值。有谁知道如何实现这个目标?

提前致谢!

4 个答案:

答案 0 :(得分:0)

<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>

答案 1 :(得分:0)

jQuery可能会帮助你。在构建HTML时,我还会添加数据 - [somethingHelpfulWhenSearching]或添加可能有用的类值。

然后您可以按类

搜索该项目
$('.[searchableClassName]')

或通过数据属性:

$('[data-[somethingHelpfulWhenSearching]') //only looking that the tag exists
$('[data-[somethingHelpfulWhenSearching]="something im looking for"') //only looking that the tag and checking the value

希望这会有所帮助

答案 2 :(得分:0)

从表达问题的方式来看,听起来好像您的HTML中有一个表格,并且您只想遍历所有单元格以检查哪些单元格包含给定值,并返回包含该单元格的DOM节点。在其文本内容内提供搜索字符串。如果这是正确的解释,请使用Vanilla JS解决方案:

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;
}

答案 3 :(得分:0)

由于您已经在使用jQuery,请尝试使用DataTables,它是一个jQuery插件,它不仅可以为您过滤。它允许客户端和服务器端筛选,因此如果您的表很大,这不是问题。