【问题标题】:MVC3 Download Excel Workbook from CSV dataMVC3 从 CSV 数据下载 Excel 工作簿
【发布时间】:2011-08-30 18:40:53
【问题描述】:

我有一组以 CSV 格式存在于内存中的数据。我的控制器中有这个方法:

     public FileContentResult ItemsAsExcelExport(){
         var model = _itemService.GetExcelExportModel();
        return new FileContentResult(model.CSVData, model.MimeType){FileDownloadName = model.FileName};
     }

这里的问题是我的 model.CSVData 属性返回一组简单的逗号分隔值。我不确定如何满足 FileContentResult 构造函数的 fileContents 参数。它要求一个字节数组。

提前致谢。

【问题讨论】:

    标签: asp.net-mvc-3 export-to-excel filecontentresult


    【解决方案1】:

    看看这个问题How do I get a consistent byte representation of strings in C# without manually specifying an encoding?

    解决办法是

      byte[] b1 = System.Text.Encoding.UTF8.GetBytes (myString); 
    

    【讨论】:

    • 这会改变我的数据吗?
    • 不,当然不是。它只是将您的字符串转换为字节数组。仅此而已
    猜你喜欢
    • 2019-04-27
    • 1970-01-01
    • 2015-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多