.NET 3.x Записать из string в html файл - C#
Формулировка задачи:
Долго мучаюсь, но не могу понять, как как занести спарсеные данные в
Занести нужно значения: ( LogName и LogNumber )
Должно получиться такое: (скрин)
html таблицу
?! Создаю файл html так + рисую таблицу:private static string path_to_html = Path.GetTempPath() + "ListGen" + ".html";
new StreamWriter(path_to_html, true, Encoding.UTF8))
{
wrd.Write("<table>");
wrd.Write("<tr>");
wrd.WriteLine("<td height="35" width="25" bgcolor="#10be4a"> <center>{0}</center> </td>", "NN");
wrd.WriteLine("<td width="200" bgcolor="#10be4a"> <center>{0} </center> </td>", "Name");
wrd.WriteLine("<td width="200" bgcolor="#10be4a"> <center>{0} </center> </td>", "Number");
wrd.Write("</tr>");
}string LogName= List.GetValue(i,"name"); string LogNumber = List.GetValue(i,"number");
Решение задачи: «.NET 3.x Записать из string в html файл»
textual
Листинг программы
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Random rnd = new Random();
var data =
Enumerable.Range(0, 20)
.Select((u, i) => new User() {Name = "User" + i, Number = rnd.Next(10000, 10000000)})
.ToArray();
using (var wr=new StreamWriter(File.Create("index.html")))
{
wr.Write("<html><head><title>Rendered Table</title></head><body>");
wr.Write("<table width='600' cellpadding='20' style='color:#10be4a'><tr align='center' style='background:#10be4a;color:#000'><td>NN</td><td>Name</td><td>Number</td></tr>");
foreach (var user in data)
{
wr.Write($"<tr><td>#</td><td>{user.Name}</td><td>{user.Number}</td></tr>");
}
wr.Write("</table></body></html>");
}
Process.Start("index.html");
}
}
class User
{
public string Name;
public double Number;
}
}