How to export linq result to succeed just like linqpad

I have an object with a lot of subqueries, and I want the export to be excellent, like Linqpad, here is an example:

enter image description here

Any help?

Tks

+3
source share
4 answers

If you include a link to linqpad.exe in your project, you can use it to export to html

eg,

List<User> users  = ....
var filename = "test.html";

var writer = LINQPad.Util.CreateXhtmlWriter();
writer.Write(users);

System.IO.File.WriteAllText(filename, writer.ToString());

// Open the file in excel
Process.Start("Excel" , filename); 
+7
source

Excel can actually open an HTML document renamed to "xls" - reading in HTML table structures in the form of Excel cells.

You will need to output your data as HTML.

+3
source

, . , , , .

lprun .

lprun -format=html yourQuery.linq > output.xls

Excel html , xls, xlsx. xlsx, , . xls , .

, . linqpad.config, , , lprun . lprun.exe.config, lprun .

0

, LinqPad Excel. HTML Ms-Excel. ( , XLS, EXCEL ).

HTML, LinqPad hyperlinq.

void Main()
{
    var filePath = Path.GetTempPath() + "output.html"; //or output.xls but with ms-excel warning
    var iEnumerbleValue = Enumerable.Range(1, 500).Select(e => new { a = 1, b = e });
    File.WriteAllText(filePath,  CreateHtml(iEnumerbleValue).ToString());
    Process.Start("EXCEL.EXE", filePath); 
}



HDoc CreateHtml<T>(IEnumerable<T> coll)
{
    var fields = typeof(T).GetProperties();

    return H.Doc(
            H.head(H.style()),
            H.body(
             H.table(
                H.tbody(
                    H.tr(fields.Select(f => H.th(f.Name))),
                    from item in coll
                    select H.tr(
                        fields.Select(f => H.td(f.GetValue(item)))
                    )
                        )
                    )
                  )
                );
}
0

All Articles