2012-09-10 2 views
-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 

souce에 코드를 브레이크 라인을 제거소스 코드에 TD 사이

<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> 
+1

http://www.WhatHaveYouTried.com – JDB

+0

@ Cyborgx37이 지적했듯이 _ 시도한 것을 _ 보여주십시오. 문제가있는 곳을 지적하고 불필요한 코드를 제거한 후 [StringBuilder.Append] (http://msdn.microsoft.com/en-us/library/system.text.stringbuilder)와 다른 점을 확인하십시오. append.aspx) 및 [.AppendLine] (http://msdn.microsoft.com/en-us/library/system.text.stringbuilder.appendline.aspx) –

+0

무엇이 당신의 질문입니까 ?? –

답변

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 

(대신 AppendLine의 사용 추가]) 당신이 명확하게 질문을하려고하면, 좀 더 적절한 회답을 얻을 수 있습니다.


편집 : 귀하의 코멘트에 대한 응답으로
, 당신은 "속성"값이 공백 또는 널 (null)하지 있는지 확인하는 검사하여 마지막 (빈) 테이블 셀 사이의 간격을 제거 할 수 있습니다. 문제를 일으키는 코드 줄은 다음과 같습니다

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

_dr(_col.ColumnName)이 null이 아닌/공백이 아닌 값을 나타냅니다 여부 (마지막에 새 줄 문자로) 한 줄의 텍스트를 인쇄합니다. _dr(_col.ColumnName)이 null이 아니고 비어 있지 않은 경우에만 실행되도록 보장하는 if 블록이있는 경우이 satement를 래핑하십시오. .Trim()을 사용하여 값에서 공백을 제거하고 String.IsNullOrEmpty()을 사용하여 문자열로 표시되는 비 공백 값이 있는지 확인할 수 있습니다.


편집 :
자세한 내용은 다음을 참조하시기 바랍니다 다음 링크 :

당신이 달성하고 싶은, 다음 쓰기에 대한 생각 그것은 일련의 단계들로 어쩌면 종이에 먼저 코드에서). 그렇게 할 수 없다면, 프로그램 할 수 없습니다 (힌트 : 거의 모든 사람이 프로그램 할 수 있습니다).

+0

@ruchit -이게 당신의 문제를 해결했는지 알려주세요. – JDB

+0

내가 원하는 소스 코드 : 새로운 라인에 - 4F0B52DC0001 이것은 새로운 라인에 - 이것은 새로운 라인입니다 - 이것은 새로운 라인에 - C006411 이것은 새로운 라인입니다 - ....하지만 마지막 테이블 데이터에는 가치가 없습니다 & 나는 다음이 새로운 라인에 있습니다 - ........ 문제는 그 souce 코드에서 내가 가지고있는 : 한 줄 바꿈 ... 나는 가치가없는 마지막 테이블 데이터 속성에서 브레이크 라인을 원하지 않는다. 나는 브레이크 라인을 원해 ..... 그래서 친구 plz 도와주세요 .... –

+0

@ruchitpatel - 내 대답을 업데이 트했습니다. – JDB

관련 문제