1
如何在Web應用程序中用EPPlus刪除.XLSX
文件的列?如何在Web應用程序中用EPPlus刪除XLSX文件的列
我使用EPplus生成Excel報表和存儲過程以從數據庫獲取數據。
的問題是,我想EPplus刪除的報告文件信息的一列(存儲過程不應該改變。)
我會刪除其他列,也想改變頁面佈局方向(從右到左),但它不工作
'----/// Click Report Button ///----
Protected Sub btnExcel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExcel.Click
If "MYcondition is true" Then
GenerateXLSXFile(CreateDataTable())
End If
End Sub
'----/// Generate Report ///----
Private Sub GenerateXLSXFile(ByVal tbl As DataTable)
Dim excelPackage = New ExcelPackage
Dim excelWorksheet = excelPackage.Workbook.Worksheets.Add("My_Worksheet")
excelWorksheet.View.ShowGridLines = False
excelWorksheet.Cells.Style.Border.Bottom.Style = Style.ExcelBorderStyle.Thick
excelWorksheet.Cells("A5").LoadFromDataTable(tbl, True)
'-----/// Hide a Column ///---------
excelWorksheet.Column(2).Hidden = True
'----/// Change PageLayout Direction ///---------------
excelWorksheet.View.PageLayoutView = excelWorksheet.View.RightToLeft
excelWorksheet.Cells("A5").Value = "header_1"
excelWorksheet.Cells("B5").Value = "header_2"
excelWorksheet.Cells("C5").Value = "header_3"
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Response.AddHeader("content-disposition", "attachment; filename=My_ExcelName.xlsx")
Dim stream As MemoryStream = New MemoryStream(excelPackage.GetAsByteArray())
Response.OutputStream.Write(stream.ToArray(), 0, stream.ToArray().Length)
Response.Flush()
Response.Close()
End Sub
'----/// Create Data Table for Exel Report (use stored procedure) ///----
Private Function CreateDataTable() As DataTable
Dim dataTable As New DataTable("tbl_Name")
Dim dataAdapter As New SqlDataAdapter()
Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("ProvidersCS").ToString)
Dim cmd As New SqlCommand("My Select Command", conn)
cmd.CommandType = CommandType.StoredProcedure
Try
conn.Open()
dataAdapter.SelectCommand = cmd
dataAdapter.Fill(dataTable)
Catch ex As Exception
Finally
conn.Close()
End Try
Return dataTable
End Function
應該有類似excelWorksheet.Columns.removeat(99)。 我沒有VS在這裏,所以我不能保密:/ –
嗨....你的幫助dosn't工作 – Cawboy