0

GridviewデータをExcelにエクスポートしました。これが私のコードです:

 Protected Sub btnExport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExport.Click
        Try
            Dim dt As New DataTable
            If CReversal.SearchReversal2(txtAccount.Text, txtCustName.Text, txtAmount.Text, dropResponse.SelectedValue.ToString, txtRefNo.Text, txtDate.Text) Then
                dt = CReversal.DT
            Else
                eMessage("System failure: ", CReversal.eMsg)
            End If
            Dim DataGrd As New DataGrid()
            DataGrd.DataSource = dt.DefaultView
            DataGrd.DataBind()

            Dim attachment As String
            attachment = "attachment; filename=Inquiry_Report" & Format(Now, "ddMMMyyyy") & ".xls"
            Response.Buffer = True
            Response.ClearContent()
            Response.ClearHeaders()
            Response.AddHeader("content-disposition", attachment)
            Response.ContentType = "application/ms-excel"
            Dim sw As New StringWriter()
            Dim htw As New HtmlTextWriter(sw)
            DataGrd.RenderControl(htw)
            Response.Write(sw.ToString())
            Response.End()
        Catch ex As Exception
            eMessage("Export Data failure: ", ex.ToString())
        End Try

    End Sub

エクスポート プロセスは、必要に応じて実行されます。しかし、Excelファイルを開くと、いくつかの文字列番号の文字が次のようになります:

ここに画像の説明を入力 しかし、実際には datagridvie の表示は次のようになります。 したほうがいい

プログラムで Excel にエクスポートするときに、文字列の数字をフォーマットすることは可能ですか? ありがとう

4

1 に答える 1