3

I am using ExcelLibrary dll .

I want to Freeze the Header Row .. Can any body suggest how I might do this?

I have tried the following code..

Imports System.Data.SqlClient
Imports ExcelLibrary
Imports ExcelLibrary.SpreadSheet



Partial Class DownloadExcel
Inherits System.Web.UI.Page

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    Try
        Dim wb As New Workbook()
        Dim sheetrowcounter As Integer
        sheetrowcounter = 0
        Dim sheet As New ExcelLibrary.SpreadSheet.Worksheet("ExcelSheet")

        sheet.Cells(sheetrowcounter, 0) = New Cell("DELIVERY MONITORING SUMMARY(PROJECT GRANDE) ")
        sheet.Cells(sheetrowcounter, 2) = New Cell("")

        sheet.Cells(sheetrowcounter, 3) = New Cell("Report Date: '" & DateTime.Now.ToString("yyyy/MM/dd H:mm:ss tt") & "                                                                                                                   ")

        sheetrowcounter += 1
        sheetrowcounter += 1
        sheet.Cells(sheetrowcounter, 0) = New Cell("Sl No")
        sheet.Cells.ColumnWidth(0) = 10000
        sheet.Cells(sheetrowcounter, 1) = New Cell("Name")
        sheet.Cells.ColumnWidth(1) = 6000

        sheetrowcounter += 1
        Dim t As DataTable = Session("exceltable")
        For i As Integer = 1 To t.Rows.Count - 1
            Try
                sheet.Cells(sheetrowcounter, 0) = New Cell(t.DefaultView.Item(i)(0))
                sheet.Cells(sheetrowcounter, 1) = New Cell(t.DefaultView.Item(i)(1))
                sheetrowcounter += 1
            Catch ex As Exception

            End Try

        Next
        sheet.Cells(0, 0).Format.FormatString = "freeze"

        wb.Worksheets.Add(sheet)


        Response.Clear()
        Response.ContentType = "application/vnd.ms-excel"
        Response.AddHeader("content-disposition", "attachment;filename=DeliveryMonitoringSummaryDaily.xls")

        Dim m As System.IO.MemoryStream = New System.IO.MemoryStream()
        wb.SaveToStream(m)
        m.WriteTo(Response.OutputStream)

    Catch ex As Exception

    End Try
End Sub

End Class

I am Storing a Datatable with 2 columns and some Rows in the Session("exceltable") object..

4

2 回答 2

2

我没有使用您指定的 Excel 库的经验,但我可以建议迁移到http://epplus.codeplex.com/网站上免费提供的 EPPlus 库。这是一个非常易于使用的库,具有清晰的 API,旨在在服务器上创建高级 Excel 2007/2010 电子表格。我们在多个生产项目中成功使用了它。使用它,您可以使用 ExcelSheet.View.FreezePanes 方法来实现您所需要的。我知道我的回答不能回答您的问题,但它可以被视为您问题的替代解决方案(我真的不知道您是否可以使用您指定的 Excel 库来实现您所需要的)。

于 2013-06-17T15:32:41.837 回答
-1

尝试这个:

Dim e As Worksheet
...
e.Application.ActiveWindow.SplitRow = 1
e.Application.ActiveWindow.FreezePanes = True
于 2013-06-17T21:00:46.363 回答