Advertisement
Guest User

CVS2HTML

a guest
Apr 8th, 2020
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. using System;
  2.                    
  3. public class Program
  4. {
  5.     private static string Csv2Html(string[,] fileContent)
  6.     {
  7.         string html = "<html><body><table>";
  8.        
  9.         for(int y = 0; y < fileContent.GetLength(0); y++)
  10.         {
  11.             html += "<tr>";
  12.            
  13.             for(int x = 0; x < fileContent.GetLength(1); x++)
  14.             {
  15.                 // Header
  16.                 if(y == 0)
  17.                 {
  18.                     html += "<th>" + fileContent[y, x] + "</th>";
  19.                 }
  20.                 // The rest
  21.                 else
  22.                 {
  23.                     html += "<td>" + fileContent[y, x] + "</td>";
  24.                 }
  25.             }
  26.            
  27.             html += "</tr>";
  28.         }
  29.        
  30.         return html + "</table></body></html>";
  31.     }
  32.    
  33.     public static void Main()
  34.     {
  35.         string[,] csv = new string[,] {{"c1", "c2"}, {"1.1", "23.3"}, {"3.1", "3.4"}};
  36.         Console.WriteLine(Csv2Html(csv));
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement