簡體   English   中英

Excel 數據轉換成 html 輸出

[英]Excel data into html output

我已經設法找出如何將數據從 excel 文件中提取到 HTML 中。

我現在正在嘗試研究如何在一組單元格中搜索值。 有誰知道如何實現這一目標?

提前致謝!

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

jQuery 很可能會幫助你。 在構建 HTML 時,我還會添加 data-[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

希望這可以幫助

從您提出問題的方式來看,聽起來您的 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;
}

由於您已經在使用 jQuery,請嘗試DataTables ,它是一個 jQuery 插件,它為您做的不僅僅是過濾。 它允許客戶端和服務器端過濾,因此如果您的表很大,這不是問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM