简体   繁体   English

如何将HTML表格列中的每个单元格转换为引用本地zip文件的可下载链接?

[英]How can I convert each cell in HTML table column to a downloadable link, that references a local zip file?

I am currently designing a web application that would read an XLSX file and convert it into an HTML table. 我目前正在设计一个Web应用程序,它将读取XLSX文件并将其转换为HTML表格。 The XLSX file contains columns that is concatenated into the "Info" column XLSX文件包含连接到“信息”列的列

I have three columns, "FileName", "Info", "Download", that becomes populated with a for loop. 我有三列,“FileName”,“Info”,“Download”,它们将填充for循环。 In this for loop, I would like to add a link in each cell under the "Download" column, that references a zip file in my local directory. 在这个for循环中,我想在“下载”列下的每个单元格中添加一个链接,该链接引用我本地目录中的zip文件。

I have already tried createElement('a') within my loop 我已经在循环中尝试了createElement('a')

for (var i = 0; i < excelRows.length; i++) {
    //Add the data row.
    var row = table.insertRow(-1);

    //Add the data cells.
    var cell = row.insertCell(-1);

    if(headerCell.getElementById = 'FileName'){
    cell.innerHTML = excelRows[i].FileName;
    //cell.setAttribute("id", "FileName");

    }
    cell = row.insertCell(-1);
    cell.innerHTML = excelRows[i].Title + " ; " + excelRows[i].Summary + " ; " + excelRows[i].Author;

    if(headerCell.getElementById = 'Download'){
    cell = row.insertCell(-1);



    cell.innerHTML = document.createElement('a');
      //cell.innerHTML = excelRows[i].FileName + ".zip";

    }
var a = document.createElement('a');

a.href = excelRows[i].FileName + ".zip";
a.innerText = 'Some Link';

cell.appendChild(a);

or 要么

cell.innerHTML += '<a href="' + excelRows[i].FileName + '.zip">Some Link</a>';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何在 HTML JS 中打开带有变量链接的本地文件 - how can i open local file with a variable link in HTML JS 如何定位我单击的表格行中每个单元格的内部 html? - How can I target the inner html of each cell in a table row that I've clicked on? 对于HTML Table列中的每个单元格做X? - For each cell in HTML Table column do X? 如何将数组复制到从某个单元格开始的列的每个单元格,而不是复制到行的每个单元格? - How can I copy an array to each cell of a column starting from a certain cell, instead of to each cell of a row? 如何将二进制文件转换为可下载的文件扩展名? - How to convert binary to downloadable file extension? 如何创建一个HTML表,每行的列数未知,如何使列对齐,并为每个单元格/行设置一个ID? - How can I create an html table, with unknown number of columns per row, get the columns to be aligned, and have an id for each cell/row? 如何在 html 中使文件/结果可下载 - How to make file/result downloadable in html 如何使用HTML构建自定义的可下载文件 - How to build a custom, downloadable file using HTML 如何使用指定的公式将html表转换为Excel文件? - How can I convert a html table to an excel file with formulas I specify? Angular:如何获取表中每个单元格都有下拉列表的列,并在每个下拉列表中设置不同的值? - Angular: How do I get a column in a table with a dropdown in each cell and set different values in each of these dropdowns?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM