Export Excel by EPPlus
Export Excel in ASP.NET problem was solved by EPPlus is completed.It can export to "xlsx" file but can not export to "xls" file.I use EPPlus version 3.1
Step for use
- Download EPPLus DLL file
- Add Reference to your Project Application
- Coding Program
Imports System
Imports System.Collections.Generic
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports OfficeOpenXml
Imports OfficeOpenXml.Style
Imports System.Drawing
Imports System.Text
Private Sub ExportExcel()
Dim pck As New ExcelPackage
Dim ws = pck.Workbook.Worksheets.Add("Sheet1")
ws.Cells("A1").Value = "Sample 2"
ws.Cells("A1").Style.Font.Bold = true
Dim shape = ws.Drawings.AddShape("Shape1", eShapeStyle.Rect)
shape.SetPosition(50, 200)
shape.SetSize(200, 100)
shape.Text = "Sample 2 outputs the sheet using the Response.BinaryWrite method"
Response.BinaryWrite(pck.GetAsByteArray())
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Response.AddHeader("content-disposition", "attachment; filename=Sample2.xlsx")
Response.End()
End
Notes.
Version 5.4.1 (from Nuget) - add syntax to web.config
<appSettings>
<!--The license context used-->
<add key="EPPlus:ExcelPackage.LicenseContext" value="NonCommercial" />
</appSettings>
Comments
Post a Comment