Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert csv to html table using

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.

like image 210
sreekanth Avatar asked Mar 10 '11 04:03

sreekanth


People also ask

How do I convert a CSV file to a table?

The steps to import a TXT or CSV file into Excel are similar for Excel 2007, 2010, 2013, and 2016: Open the Excel spreadsheet where you want to save the data and click the Data tab. In the Get External Data group, click From Text. Select the TXT or CSV file you want to convert and click Import.

How do I convert a CSV file to a table in Python?

You can read a CSV file into a DataFrame using the read_csv() function (this function should be familiar to you, but you can run help(pd. read_csv) in the console to refresh your memory!). Then, you can call the . to_sql() method on the DataFrame to load it into a SQL table in a database.

How do I export a table from CSV to website?

right-click anywhere in the table and select 'copy whole table' start up a spreadsheet application such as LibreOffice Calc. paste into the spreadsheet (select appropriate separator character as needed) save/export the spreadsheet as CSV.


1 Answers

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"

like image 82
dj_segfault Avatar answered Jan 01 '23 08:01

dj_segfault