0

如何在 excel 中查看的 html 表中显示尾随零?

我已经检查了记事本++ 中的 html,所以我知道它们在那里。

该表是在 .ashx 中构建的,扩展名为 .xls。

细节

我希望为用户自动格式化数字。

我希望仍然能够将数字操作为数字(如果显示为文本)。

我如何在 ashx 中建表

If sqlDataset.Tables(0).Rows.Count > 0 Then
    context.Response.BufferOutput = False
    Dim response As HttpResponse = context.Response

    context.Response.AddHeader("content-disposition", "attachment; filename=Total Quote Sheet " & DateTime.Now() & ".xls")
    context.Response.ContentType = "application/ms-excel"
    Dim outputHTML As String

    Using sw As StringWriter = New StringWriter
        Using ht As HtmlTextWriter = New HtmlTextWriter(sw)

            Dim table As New Table

            Dim headings = {"Article Number", "Quantity Quote", "SAP Supplier #", "Cost Code", "Unit Cost", "Extended Cost", "SAP Description", "Status"}
            Dim HeaderRow As New TableRow
            HeaderRow.ForeColor = Drawing.Color.White
            For Each heading As String In headings
                Dim Cell As New TableCell
                Cell.Text = heading
                Cell.BorderWidth = 1
                Cell.BorderColor = Drawing.Color.Black
                Cell.BorderStyle = BorderStyle.Solid
                Cell.BackColor = System.Drawing.ColorTranslator.FromHtml("#003797")
                HeaderRow.Cells.Add(Cell)
            Next

            table.Rows.Add(HeaderRow)

            For u As Integer = 0 To sqlDataset.Tables(0).Rows.Count - 1

                Dim DataRow As New TableRow
                Dim dataColumnNames = {"AN", "QB", "SSN", "CC", "UC", "EC", "AD", "BAI"}
                For Each dataColumnName As String In dataColumnNames
                    Dim Cell As New TableCell
                    Cell.Text = sqlDataset.Tables(0).Rows(u).Field(Of Object)(dataColumnName)
                    Cell.BorderWidth = 1
                    Cell.BorderColor = Drawing.Color.Black
                    Cell.BorderStyle = BorderStyle.Solid
                    If dataColumnName = "BAI" Then
                        Select Case sqlDataset.Tables(0).Rows(u).Field(Of Object)(dataColumnName)
                            Case "U"
                                Cell.Text = "Undecided"
                            Case "A"
                                Cell.Text = "Accepted"
                            Case "R"
                                Cell.Text = "Rejected"
                        End Select
                    End If
                    DataRow.Cells.Add(Cell)
                Next

                table.Rows.Add(DataRow)
            Next
            table.RenderControl(ht)
            outputHTML = sw.ToString()
            context.Response.Write(outputHTML)
        End Using
    End Using

End If
4

1 回答 1

0

您需要将值显示为文本。有三种方法可以做到这一点,一种是将单元格格式设置为文本,使用 text() 函数,或者如果您正在导入它,您可以将数据类型更改为文本。

于 2013-04-11T16:50:25.980 回答