首页 > 解决方案 > Powershell Import-Csv 试图将 CSV 文件转换为 HTML,但我不知道如何将 ID 参数添加到表中(需要 jscript)

问题描述

$bodyformat += 
 '<input type="text" id="search_field_input" onkeyup="search_table()" placeholder="Type to search">'
$bodyformat += 
 '<script>
  function search_table(){
  var input, filter, table, tr, td, i;
  input = document.getElementById("search_field_input");
  filter = input.value.toUpperCase();
  table = document.getElementById("table_id");
  tr = table.getElementsByTagName("tr");

 for (i = 0; i < tr.length; i++) {
  td = tr[i].getElementsByTagName("td") ; 
  for(j=0 ; j<td.length ; j++)
  {
  let tdata = td[j] ;
  if (tdata) {
    if (tdata.innerHTML.toUpperCase().indexOf(filter) > -1) {
      tr[i].style.display = "";
      break ; 
    } else {
      tr[i].style.display = "none";
    }
   } 
  }
 }
}
</script>'

$html = Import-Csv -delimiter ',' -Path D:\Temp\final.csv | Foreach {$ .link= '{1}' -f $ .Link,$ .Title;$ } | 选择ID,链接 | ConvertTo-Html -Head $htmlformat -Body $bodyformat

$html -replace "<","<" -replace """,'"' -replace ">",">" | 出站文件 D:\Outbound\index.html

标签: javascripthtmlpowershellimport-csv

解决方案


推荐阅读