我发现这段代码可以将我的数据结果导出到 Excel:
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);
这会以格式化模式导出数据。仅复制“导出>导出到Excel”的代码是什么?