c# - 在 C# 中打印数组/列表到 Excel

标签 c# asp.net asp.net-mvc arrays list

我能够将单个值保存到 Excel 中,但我需要帮助将完整列表/数组保存到 Excel 工作表中。

我到目前为止的代码:

var MovieNames = session.Query<Movie>()
                          .ToArray();

List<string> MovieList = new List<string>();

foreach (var movie in MovieNames)
 {                   
  MovieList.Add(movie.MovieName);               
 }

//If I want to print a single value or a string, 
//I can use the following to print/save to excel
// How can I do this if I want to print that entire
//list thats generated in "MovieList" 

return File(new System.Text.UTF8Encoding().GetBytes(MovieList), "text/csv", "demo.csv");

最佳答案

您可以使用FileHelpers将一些强类型对象序列化为 CSV。只要答应我never roll your own CSV parser .

关于c# - 在 C# 中打印数组/列表到 Excel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8811470/

相关文章:

c# - 自动属性初始化与构造函数初始化哪个优先?

c# - 无法使用 C# 或 VB 检索 Web 服务响应

c# - 显示 TreeNode 的图像

asp.net - 即使在服务器上也不会显示详细的500错误消息

c# - 在局部 View mvc 中显示三篇随机文章

asp.net-mvc - 有关网站安全的建议

c# - C# wpf 中的绑定(bind)问题

c# - 无法序列化 session 状态

c# - 字符串的第一个字符到上层 ASP.Net

c# - Ninject.Web.Common 和 Ninject.Mvc 未将 DependencyResolver 设置为使用 NinjectDependencyResolver