我是用owc组件生成的excel文档这里面的datagrid没有rows,怪事。
Dim xlsheet As New SpreadsheetClass()
        Dim i As Integer = 0
        Dim j As Integer = 0
        'Response.End()
        ' 输出标题
        'xlsheet.ActiveSheet.Cells (a1:a5)="123456"        Dim oItem As DataGridColumn
        For Each oItem In DataGrid1.Columns
            xlsheet.ActiveSheet.Cells(2, i + 1) = oItem.HeaderText
            'xlsheet.ActiveSheet.Range(xlsheet.ActiveSheet.Cells(1, 1),xlsheet.ActiveSheet.Cells(1, i + 1)).Font.Bold = True
            '设置格式
            xlsheet.Range(xlsheet.Cells(2, 1), xlsheet.Cells(2, i + 1)).Font.Bold = False
            xlsheet.Range(xlsheet.Cells(2, 1), xlsheet.Cells(2, i + 1)).Font.Color = "black"
            xlsheet.Range(xlsheet.Cells(2, 1), xlsheet.Cells(2, i + 1)).Font.Name = "黑体"
            xlsheet.Range(xlsheet.Cells(2, 1), xlsheet.Cells(2, i + 1)).Font.Size = "12"
            xlsheet.Range(xlsheet.Cells(2, 1), xlsheet.Cells(2, i + 1)).ColumnWidth = "170"
            i = i + 1
        Next        Dim numbercols As Integer = DataGrid1.Items.Item(0).Cells.Count
        'Dim dataitem As
        'Dim viewcount As Integer
        'viewcount = dataitem.Rows.Count
        'Response.Write("viewcount")
        'Response.End()        Dim l As Integer = 1        ' 输出字段内容
        For j = 0 To DataGrid1.Items.Count - 1
            '   For j = 0 To DataGrid1.rows.count
            For i = 0 To numbercols - 1
                ' xlsheet.Range(xlsheet.Cells(3, 1), xlsheet.Cells(l + 2, i + 1)).Font.Color = "black"
                xlsheet.Range(xlsheet.Cells(3, 1), xlsheet.Cells(l + 2, i + 1)).Font.Bold = False
                xlsheet.Range(xlsheet.Cells(3, 1), xlsheet.Cells(l + 2, i + 1)).Font.Color = "black"
                xlsheet.Range(xlsheet.Cells(3, 1), xlsheet.Cells(l + 2, i + 1)).Font.Name = "arial black"
                xlsheet.Range(xlsheet.Cells(3, 1), xlsheet.Cells(l + 2, i + 1)).Font.Size = "12"
                xlsheet.Range(xlsheet.Cells(3, 1), xlsheet.Cells(l + 2, i + 1)).ColumnWidth = "170"
                ''xlsheet.Range("A2:B14").WrapText = True
                'xlsheet.Range(xlsheet.Cells(3, 1), xlsheet.Cells(l + 2, i + 1)).AutoFitColumns()
                xlsheet.ActiveSheet.Cells(l + 2, i + 1) = DataGrid1.Items.Item(j).Cells(i).Text.Replace(" ", " ")
            Next
            l = l + 1
        Next
        Try
            xlsheet.ActiveSheet.Export(Server.MapPath(".") + "\doc\" + strurl, OWC.SheetExportActionEnum.ssExportActionNone)
        Catch e As System.Runtime.InteropServices.COMException
            Response.Write("错误:" + e.Message)
        End Try
        Dim strdoc As String = strurl4 & "doc/" & strurl        Response.Redirect("doc/" & strurl)    End Sub