Convert excel workbook to byte[]

前端 未结 2 424
挽巷
挽巷 2021-01-21 07:22

I have an \"excel library\" workbook and want to convert it to a byte[] so I could return the data with the File method exist in asp.net mvc controller.
There are \"Save\" a

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-21 07:55

    Do you need to convert it to a byte[]? File can also return a stream.

    Workbook workbook = new Workbook();
    Worksheet worksheet = new Worksheet("First Sheet");
    worksheet.Cells[0, 1] = new Cell(9999999);
    
    workbook.Worksheets.Add(worksheet);
    
    MemoryStream m = new MemoryStream();
    workbook.SaveToStream(m);
    
    return File(m, "application/vnd.ms-excel");
    

提交回复
热议问题