owc导出的datagrid生成的xls问题是xml格式,并不是正式的xls文件,必须用excel另存为xls。是否可以直接生正式的excel文件
strurl = "SZY.xls"
        'Response.Write(strurl)
        'Response.End()
        Dim strurl2 As String = Request.ServerVariables("Local_addr")
        Dim strurl3 As String = Request.ServerVariables("path_info")
        Dim strurl5 As String = Mid(strurl3, 1, InStrRev(strurl3, "/"))
        Dim strurl4 As String = strurl2 + strurl5
        'Response.Write(Server.MapPath("."))
        'Response.End()
        'Response.End()        'Response.Write(strurl5)
        'Response.End()        ''objadapter = New SqlDataAdapter(strsql, objconnection)
        ''objadapter.Fill(objdataset, "tmpkq")
        ''If objdataset.Tables("tmpkq").Rows.Count <= 0 Then        ''    Response.Write("<script language=javascript>alert ('尚无该月考勤!');history.back(-1)</script>")        ''Else
        ''    DataGridCond.DataSource = objdataset.Tables("tmpkq").DefaultView
        ''    DataGridCond.DataBind()
        ''    ''  Response.End()
        Dim xlsheet As New SpreadsheetClass
        Dim i As Integer = 0
        Dim j As Integer = 0
        'Response.End()
        ' 输出标题
        Dim oItem As DataGridColumn
        For Each oItem In DataGridCond.Columns
            xlsheet.ActiveSheet.Cells(1, 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(1, 1), xlsheet.Cells(1, i + 1)).Font.Bold = False
            xlsheet.Range(xlsheet.Cells(1, 1), xlsheet.Cells(1, i + 1)).Font.Color = "black"
            xlsheet.Range(xlsheet.Cells(1, 1), xlsheet.Cells(1, i + 1)).Font.Name = "黑体"
            'xlsheet.Range(xlsheet.Cells(1, 1), xlsheet.Cells(1, i + 1)).Font.Size = "14px"
            'xlsheet.Range(xlsheet.Cells(1, 1), xlsheet.Cells(1, i + 1)).width = "150px"
            i = i + 1
        Next        Dim numbercols As Integer = DataGridCond.Items.Item(0).Cells.Count
        ' 输出字段内容
        For j = 0 To DataGridCond.Items.Count - 1
            For i = 0 To numbercols - 1
                'xlsheet.Range(xlsheet.Cells(2, 2), xlsheet.Cells(j + 2, i + 1)).Font.Color = "blue"
                ''xlsheet.Range("A2:B14").WrapText = True
                'xlsheet.Range(xlsheet.Cells(2, 1), xlsheet.Cells(j + 2, i + 1)).AutoFit()                xlsheet.ActiveSheet.Cells(j + 2, i + 1) = DataGridCond.Items.Item(j).Cells(i).Text
            Next
        Next
        Try
            ' xlsheet.Export(Server.MapPath(".") + "\doc\" + strurl, OWC10.SheetExportActionEnum.ssExportActionNone)
            xlsheet.Export(Server.MapPath(".") + "\doc\" + strurl, SheetExportActionEnum.ssExportActionNone)
            ''  xlsheet.Export(strurl, SheetExportActionEnum.ssExportActionNone)        Catch ei As System.Runtime.InteropServices.COMException
            Response.Write("错误:" + ei.Message)
        End Try
        Dim strexcel As String = strurl5 & "\doc\" & strurl        Response.Redirect(strexcel)