我创建一些.csv文件并填写导出数据。这是我的代码:
public void ExportGoodList(int id)
{
List<LineItem> lineItems = _lineItemService.FindAllByApplicationId(id).ToList();
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=Carnet" + id + ".csv");
Response.Flush();
Response.Write("Item Description");
Response.Write(",");
Response.Write("No. of Pieces (numbers only are allowed)");
Response.Write(",");
Response.Write("Weight/Volume (numbers only are allowed)");
Response.Write(",");
Response.Write("\"Unit of Measure (the following values are allowed only: g, kg, t, l)\"");
Response.Write(",");
Response.Write("Value (in GBP) (numbers only are allowed)");
Response.Write(",");
Response.Write("Country of Origin (the codes of the countries are allowed only)");
Response.Write(",");
Response.Write(" Goods Type ID (numbers only are allowed)");
Response.Write(",");
Response.Write("\n");
foreach (var item in lineItems)
{
Response.Write(SanitizeData(item.Description));
Response.Write(",");
Response.Write(SanitizeData(item.NumberOfPieces));
Response.Write(",");
Response.Write(SanitizeData(item.Quantity));
Response.Write(",");
Response.Write(SanitizeData(item.QuantityUnits));
Response.Write(",");
Response.Write(SanitizeData(item.ItemValue));
Response.Write(",");
Response.Write(SanitizeData(item.CountryOfOrigin));
Response.Write(",");
Response.Write(SanitizeData(_goodsTypeService.GoodsTypeIdToUserDefinedId(item.GoodsType)));
Response.Write("\n");
}
}
public void ExportGoodList(int id)
{
List<LineItem> lineItems = _lineItemService.FindAllByApplicationId(id).ToList();
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=Carnet" + id + ".csv");
Response.Flush();
Response.Write("Item Description");
Response.Write(",");
Response.Write("No. of Pieces (numbers only are allowed)");
Response.Write(",");
Response.Write("Weight/Volume (numbers only are allowed)");
Response.Write(",");
Response.Write("\"Unit of Measure (the following values are allowed only: g, kg, t, l)\"");
Response.Write(",");
Response.Write("Value (in GBP) (numbers only are allowed)");
Response.Write(",");
Response.Write("Country of Origin (the codes of the countries are allowed only)");
Response.Write(",");
Response.Write(" Goods Type ID (numbers only are allowed)");
Response.Write(",");
Response.Write("\n");
foreach (var item in lineItems)
{
Response.Write(SanitizeData(item.Description));
Response.Write(",");
Response.Write(SanitizeData(item.NumberOfPieces));
Response.Write(",");
Response.Write(SanitizeData(item.Quantity));
Response.Write(",");
Response.Write(SanitizeData(item.QuantityUnits));
Response.Write(",");
Response.Write(SanitizeData(item.ItemValue));
Response.Write(",");
Response.Write(SanitizeData(item.CountryOfOrigin));
Response.Write(",");
Response.Write(SanitizeData(_goodsTypeService.GoodsTypeIdToUserDefinedId(item.GoodsType)));
Response.Write("\n");
}
}
然后下载了这个文件,我看到了所有导出数据。此.csv文件只有一个包含数据的工作表。我的目标是在此.csv文件中使用另一个数据创建另一个附加工作表。我不知道怎么做!
谢谢!
答案 0 :(得分:1)
没有办法做到这一点。 CSV
(以逗号分隔的值)是一种文本格式,它与Sheet和MVC都没有关系。
如果您需要将工作表添加到Excel文件,请参阅f.e。:C# how to add Excel Worksheet programmatically Office XP / 2003