Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export linq result to excel just like Linqpad

I have an object with a lot of subqueries and I want do export to excel just like Linqpad does, here is an example:

enter image description here

Any help?

Tks

like image 565
Alexandre Avatar asked Dec 09 '22 00:12

Alexandre


1 Answers

If you include a reference to linqpad.exe in your project, you can then use it to do the 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); 
like image 100
sgmoore Avatar answered Dec 27 '22 17:12

sgmoore