|
emozley (TechnicalUser) |
23 Apr 12 8:31 |
Hi there, I have a website written in ASP classic that presents data from a SQL database. I would now like to export the data as Excel and after some research have found that using EP Plus and .NET is one of the better ways of doing this. I am totally new to this and so far I have: 1. Downloaded and installed Visual Web Developer 2010 Express on my PC 2. Created a folder on the IIS server and converted it to an application 3. Installed .NET framework 4 on server and configured application to use this. 4. Added a line to my web.config file <customErrors mode="Off"/> 5. Copied EPPLUS.DLL to the folder on the IIS server where my project is. Some sample code has been supplied on the EP Plus website: CODEprivate void DumpExcel(DataTable tbl) { using (ExcelPackage pck = new ExcelPackage()) { //Create the worksheet ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Demo");
//Load the datatable into the sheet, starting from cell A1. Print the column names on row 1 ws.Cells["A1"].LoadFromDataTable(tbl, true);
//Format the header for column 1-3 using (ExcelRange rng = ws.Cells["A1:C1"]) { rng.Style.Font.Bold = true; rng.Style.Fill.PatternType = ExcelFillStyle.Solid; //Set Pattern for the background to Solid rng.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(79, 129, 189)); //Set color to dark blue rng.Style.Font.Color.SetColor(Color.White); }
//Example how to Format Column 1 as numeric using (ExcelRange col = ws.Cells[2, 1, 2 + tbl.Rows.Count, 1]) { col.Style.Numberformat.Format = "#,##0.00"; col.Style.HorizontalAlignment = ExcelHorizontalAlignment.Right; }
//Write it back to the client Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader("content-disposition", "attachment; filename=ExcelDemo.xlsx"); Response.BinaryWrite(pck.GetAsByteArray()); } } So my questions for now are... 1. I want to add a button to my default.aspx folder that runs the above code. How do I 'tell' default.aspx about the epplus.dll file? 2. Do I need to make a default.aspx.cs file and stick the code in there? I can see there is a default.aspx.vb file so I think somehow I have selected the wrong language for the website? Thanks very much Ed Mozley |
|