1

Currently I am using EPPlus Library mainly because EPPPlus doesn't need of office installed on End user pc but right now i've been specifying(insert) each row and column in to worksheet on this library.

I want to generate the excel file from GRIDVIEW data on server side without office tool.

So i need some other solution or Library file that could meet my expectation.

Thanks in advance.

Joe Mike
  • 1,150
  • 1
  • 9
  • 16
  • 1
    What is the exact problem you encountered with `EPPLus`? – Tim Schmelter Aug 21 '14 at 11:37
  • Gridiview isn't a data structure, it's a UI. Which means your data is either a DataTable or a list of objects. Writing a few lines of code to iterate over this and set cell values is almost trivial – Panagiotis Kanavos Aug 21 '14 at 11:38
  • I need to specify each cell value with rows and columns to insert in excel file @Tim Schmelter – Joe Mike Aug 21 '14 at 11:39
  • Why is that a problem and what do you want to do something else? Creating a generic method to do the job isn't difficult and doesn't need any external tool. What problem are you really trying to solve? – Panagiotis Kanavos Aug 21 '14 at 11:41
  • 1
    @JoeMike: you can do that with `EPPLus`, but i don't understand why you want to use the complicated way if you can use the `LoadFromDataTable` or `LoadFromCollection`. – Tim Schmelter Aug 21 '14 at 11:43
  • possible duplicate of [Export DataTable to excel with EPPlus](http://stackoverflow.com/questions/13669733/export-datatable-to-excel-with-epplus) – Panagiotis Kanavos Aug 21 '14 at 11:44

1 Answers1

5

I must admit that i don't understand why you can't use EPPlus with the GridView.

You could use the DataSource of the GridView, for example if it's a DataTable:

try {
    var pck = new OfficeOpenXml.ExcelPackage();
    var ws = pck.Workbook.Worksheets.Add("Sheet-Name");
    ws.Cells["A2"].LoadFromDataTable(tbl, false);
    Response.Clear();
    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
    Response.AddHeader("content-disposition", "attachment;  filename=FileName.xlsx");
    Response.BinaryWrite(pck.GetAsByteArray());
} catch (Exception ex) {
    //log error
}
Response.End();
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939