2

I create some .csv file and fill in with export data. This is my code:

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");
            }
        }

Then this file downloaded and I see all export data. This .csv file have only one sheet with data. My target is to create another additional sheet in this .csv file with another data. I don't know how to do it!

Thanks!

tereško
  • 58,060
  • 25
  • 98
  • 150
IFrizy
  • 1,705
  • 4
  • 17
  • 33

1 Answers1

1

There's no way of doing this. CSV (comma-separated values) is a text format and it has no relation neither to Sheet nor to MVC.

If you need to add a Sheet to Excel file, see f.e.: C# how to add Excel Worksheet programmatically Office XP / 2003

Community
  • 1
  • 1
astef
  • 8,575
  • 4
  • 56
  • 95