Convert csv to html table using

眉间皱痕 提交于 2021-02-18 07:31:24

问题


How can I convert a CSV file into html table? I got a csv file with comma "," and I want this file to convert to Html table.


回答1:


OK, you really want it only in bash? Mission accomplished.

cat > input.csv
a,b,c
d,e,f
g,h,i

echo "<table>" ; while read INPUT ; do echo "<tr><td>${INPUT//,/</td><td>}</td></tr>" ; done < input.csv ; echo "</table>"
<table>
<tr><td>a</td><td>b</td><td>c</td></tr>
<tr><td>d</td><td>e</td><td>f</td></tr>
<tr><td>g</td><td>h</td><td>i</td></tr>
</table>

My first try used "cat" but I figured that was cheating, so I rewrote it using "while read"




回答2:


XmlGrid.net has a nice tool to convert a CSV file into HTML table. Here is the link: http://xmlgrid.net/csvToHtml.html



来源:https://stackoverflow.com/questions/5255449/convert-csv-to-html-table-using

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!