doubi5127 2019-05-01 02:22
浏览 56

有没有办法将电子表格信息链接到我的HTML文件?

I have a CSV file with 3 columns and 223 rows. The columns go from items (A column), description (B column), to type (C column). Each row contains information about each item. I want to insert data from all this spreadsheet into my HTML file. Along with this, I want to save time by not copy and pasting 233 sets of information manually.

Originally the information I needed was on a website, however, I found a suggestion to use a webscraper to get all the information I needed. I did this by using python and now I have all the information in the spreadsheet.

The template I would like to follow is shown (using spreadsheet terms). If I were manually doing this the next line of code would look this but with a B instead of an A (A1->B1)

<p class="item-title">(A1 in spreadsheet)</p>
<p class="w-itemid">ItemID: N/A</p>
<p>&#8226;      (A2 in spreadsheet)</p>
<ul>
    <p>Type: (A3 in spreadsheet</p>
    <p>Item Pool: N/A</p>
</ul>

I want the solution to be able to link the information from my spreadsheet into my HTML without spending an immense amount of time copy and pasting 233 items. I do not mind using Javascript, jQuery, or PHP as long as it helps me finish this task.

  • 写回答

1条回答 默认 最新

  • dsfs23434 2019-05-01 02:39
    关注

    you can try this solution:

    $row = 1;
    $columnArray = [];
    $resultArray = [];
    if (($handle = fopen("test.csv", "r")) !== FALSE) {
        while (($data = fgetcsv($handle)) !== FALSE) {
    
            if($row == 1){
                $columnArray = $data;
            }else{
                $tmpArray = [];
                for($i=0;$i<count($columnArray);$i++){
                    $tmpArray[$columnArray[$i]] = $data[$i];
                }
                $resultArray[] = $tmpArray;
            }
            $row++;
        }
        fclose($handle);
    }
    

    I'm assuming that the first row of your CSV holds the column names. At the end you will have $resultArray associative array holding all your data.

    UPDATE

    If your CSV does not contain field names at the first row you can use this code:

    $row = 1;
    $resultArray = [];
    if (($handle = fopen("test.csv", "r")) !== FALSE) {
        while (($data = fgetcsv($handle)) !== FALSE) {
            $resultArray[] = $data;
            $row++;
        }
        fclose($handle);
    }
    

    In this case $resultArray will hold the data as a normal nested array and you can show the info by iterating trough it:

    if(count($resultArray)>0){
        for($i=0;$i<count($resultArray);$i++){
            echo '<p>Item: '.$resultArray[$i][0].'</p>';
            echo '<p>Description: '.$resultArray[$i][1].'</p>';
            echo '<p>Type: '.$resultArray[$i][2].'</p>';
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错