-2
Public Function GenerateHtmlReport(ByVal ResultDataset As System.Data.DataSet) As String Implements IValidation.GenerateHtmlReport
        Dim _StrBuil As New StringBuilder()
        Dim clsHtmlBuilder As New HtmlBuilder()
        Try
            _StrBuil.AppendLine(Space(2) & clsHtmlBuilder.AddHr())
            _StrBuil.AppendLine(Space(3) & clsHtmlBuilder.TextBig(ResultDataset.DataSetName))
            _StrBuil.AppendLine(Space(5) & clsHtmlBuilder.AddLineBreak)

            For Each _Tbl As DataTable In ResultDataset.Tables
                If _Tbl Is Nothing OrElse _Tbl.Rows.Count = 0 Then Continue For
                _StrBuil.AppendLine(Space(8) & clsHtmlBuilder.StartTable())

                'set Table Header
                'set Table Name

                _StrBuil.AppendLine(Space(15) & clsHtmlBuilder.StartH4())
                _StrBuil.AppendLine(Space(20) & _Tbl.TableName)
                _StrBuil.AppendLine(Space(15) & clsHtmlBuilder.EndH4())
                _StrBuil.AppendLine(Space(25) & clsHtmlBuilder.StartTableRow())

                'set Column Name
                For Each _col As DataColumn In _Tbl.Columns
                    _StrBuil.AppendLine(Space(35) & clsHtmlBuilder.StartTableHeader())
                    _StrBuil.AppendLine(Space(45) & _col.ColumnName)
                    _StrBuil.AppendLine(Space(35) & clsHtmlBuilder.EndTableHeader())

                Next
                _StrBuil.AppendLine(Space(25) & clsHtmlBuilder.EndTableRow())

                'set Table Rows
                For Each _dr As DataRow In _Tbl.Rows
                    _StrBuil.AppendLine(Space(25) & clsHtmlBuilder.StartTableRow())
                    For Each _col As DataColumn In _Tbl.Columns
                        If (Space(45) & _col.ColumnName = "Result") Then
                            _StrBuil.AppendLine(Space(35) & clsHtmlBuilder.StartTableCell())
                        Else

                            _StrBuil.AppendLine(Space(35) & clsHtmlBuilder.StartTableCell())

                        End If
                        _StrBuil.AppendLine(Space(45) & _dr(_col.ColumnName).ToString())
                        _StrBuil.AppendLine(Space(35) & clsHtmlBuilder.EndTableCell())

                    Next

                    _StrBuil.AppendLine(Space(25) & clsHtmlBuilder.EndTableRow())
                Next

                _StrBuil.AppendLine(Space(8) & clsHtmlBuilder.EndTable())
            Next
            _StrBuil.AppendLine(Space(5) & clsHtmlBuilder.AddLineBreak)
            _StrBuil.AppendLine(Space(2) & clsHtmlBuilder.AddHr())
        Catch ex As Exception
            clsCommon.writeErrorLog("Error in Report Generation", "RuleSet2", "GenerateHtmlReport")
            Throw ex
        End Try
        Return _StrBuil.ToString()
    End Function
End Class

源代码:

 <td nowrap = "nowrap">
         4F0B52DC0001
 </td>
 <td nowrap = "nowrap">
         C006411
 </td>
 <td nowrap = "nowrap">
         Christiansen
 </td>
 <td nowrap = "nowrap">
         Cathy
 </td>
 <td nowrap = "nowrap">
         19570406
 </td>
 <td nowrap = "nowrap">

 </td>
4

1 回答 1

1

你的意思是你想要以下?

<td nowrap = "nowrap">4F0B52DC0001</td>
<td nowrap = "nowrap">C006411</td>
<td nowrap = "nowrap">Christiansen</td>
<td nowrap = "nowrap">Cathy</td>
<td nowrap = "nowrap">19570406</td>
<td nowrap = "nowrap"></td> 

尝试这个:

For Each _col As DataColumn In _Tbl.Columns
    If (Space(45) & _col.ColumnName = "Result") Then
        _StrBuil.Append(Space(35) & clsHtmlBuilder.StartTableCell())
    Else
        _StrBuil.Append(Space(35) & clsHtmlBuilder.StartTableCell())
    End If
    _StrBuil.Append(_dr(_col.ColumnName).ToString())
    _StrBuil.AppendLine(clsHtmlBuilder.EndTableCell())
Next 

(使用 Append 而不是 AppendLine)

如果您尝试提出更清晰的问题,您可能会得到更相关的回答者。


编辑:
作为对您的评论的回应,您可以通过检查以确保“属性”值不是空白或空值来消除最后一个(空)表格单元格之间的间隙。导致您的问题的代码行是:

_StrBuil.AppendLine(Space(45) & _dr(_col.ColumnName).ToString()) 

这将打印一行文本(末尾带有换行符),无论是否_dr(_col.ColumnName)表示非空/非空白值。如果一个 if 块确保它仅在_dr(_col.ColumnName)不为空且不为空时执行,则包装此语句。您可以使用.Trim()从值中删除空格并String.IsNullOrEmpty()确保存在由字符串表示的非空白值。


编辑:
有关更多信息,请参阅以下链接:

想想你想完成什么,然后把它写成一系列步骤(可能先写在纸上,然后写在代码中)。如果你不能这样做,那么你就不能编程(提示:几乎任何人都可以编程)。

于 2012-09-10T17:46:15.127 回答