【问题标题】:want to print value in first row of fifth column in HTML想要在 HTML 的第五列的第一行打印值
【发布时间】:2021-08-08 14:33:00
【问题描述】:

我正在从 XML 创建一个表。 XML 文件针对表的不同部分具有不同的数据。 例如:

创建表格时,值会正确打印在第 3 列和第 4 列,但当循环转到第 5 列时,它不会移动到第 5 列的第一个单元格/第一行。 在这里,它打印从第 6 行开始的值。

HTML 代码是在 PowerShell ISE 上编写的:

$htmlTable
$html2 = 1..$testConditionCount;

for ($j = 0; $j -le $testConditionCount-1; $j++) 
{

    $html2[$j]=$header+'<table id="data" align="Left" style="width:100%">'+
                        '<tr>
                            <th colspan="10">Test Condition Name:'+$TestConditionName[$j]+'</th>
                            <th>Result:</th>
                            <th>'+$FinalResult[$j]+'</th>
                        </tr>'+
                       '<tr>
                            <th>TIA Installation</th>
                            <th>'+$TIA_Installation[$j]+'</th>
                            <th>SDR Installation</th>
                            <th>'+$SDR_Installation[$j]+'</th>
                            <th>SDR Modify</th>
                            <th>'+$SDR_Modify[$j]+'</th>
                            <th>SDR Repair</th>
                            <th>'+$SDR_Repair[$j]+'</th>
                            <th>SDR Uninstalltion</th>
                            <th>'+$SDR_Uninstallation[$j]+'</th>
                        </tr>'


 for ($i_C = 0; $i_C -le ($I_SmokeTestCount[$j] )-1; $i_C++) 
    {
     
         $html2[$j]+="<tr>
       
                    <td>"+""+"</td>
                    <td>"+""+"</td>
                    <td>"+$I_SmokeTest[$j].get($i_C)+"</td>
                    <td>"+$I_SmokeTestResult[$j].get($i_C)+"</td>
                </tr>" 
              #  "</table>"
    }
If ($M_SmokeTestCount[$j] -gt 0)
{    
    for ($i_M = 0; $i_M -le ($M_SmokeTestCount[$j] )-1; $i_M++) 
        {
             $html2[$j]+="<tr>
                        <td>"+""+"</td>
                        <td>"+""+"</td>
                        <td>"+""+"</td>
                        <td>"+""+"</td>
                        <td>"+$M_SmokeTest[$j].get($i_M)+"</td>
                        <td>"+$M_SmokeTestResult[$j].get($i_M)+"</td> 
                        </tr>" 
        }
    }

If ($R_SmokeTestCount[$j] -gt 0)
{
    for ($i_R = 0; $i_R -le ($R_SmokeTestCount[$j] )-1; $i_R++) 
        {
             $html2[$j]+="<tr>
                        <td>"+""+"</td>
                        <td>"+""+"</td>
                        <td>"+""+"</td>
                        <td>"+""+"</td>
                        <td>"+""+"</td>
                        <td>"+""+"</td>
                        <td>"+$R_SmokeTest[$j].get($i_R)+"</td>
                        <td>"+$R_SmokeTestResult[$j].get($i_R)+"</td>                    
                    </tr>" 
                  
        }
    }
$html2[$j]+=$header+'</table>'

【问题讨论】:

    标签: html powershell html-table multiple-columns rows


    【解决方案1】:

    嗯,基本上这就是您生成表格的方式:

    在伪代码中:

    对 $testcondition 次执行以下操作:

    1. 写一个表头
    2. 在第 3 列和第 4 列写入 ($I_SmokeTestCount[$j]) 行,其中包含一些值
    3. 在第 5 列和第 6 列写入 ($M_SmokeTestCount[$j]) 行,其中包含一些值
    4. 在第 7 列和第 8 列写入 ($R_SmokeTestcount[$j]) 行,其中包含一些值

    要点是:您总是添加行,而不是列!

    也许可以试试:

    $htmlTable
    $html2 = 1..$testConditionCount;
    
    for ($j = 0; $j -le $testConditionCount-1; $j++) 
    {
    
        $html2[$j]=$header+'<table id="data" align="Left" style="width:100%">'+
                            '<tr>
                                <th colspan="10">Test Condition Name:'+$TestConditionName[$j]+'</th>
                                <th>Result:</th>
                                <th>'+$FinalResult[$j]+'</th>
                            </tr>'+
                           '<tr>
                                <th>TIA Installation</th>
                                <th>'+$TIA_Installation[$j]+'</th>
                                <th>SDR Installation</th>
                                <th>'+$SDR_Installation[$j]+'</th>
                                <th>SDR Modify</th>
                                <th>'+$SDR_Modify[$j]+'</th>
                                <th>SDR Repair</th>
                                <th>'+$SDR_Repair[$j]+'</th>
                                <th>SDR Uninstalltion</th>
                                <th>'+$SDR_Uninstallation[$j]+'</th>
                            </tr>'
    
     $maxIndex = @($I_SmokeTestCount[$j], $M_SmokeTestCount[$j], $R_SmokeTestCount[$j]) | Sort-Object -Descending | Select-Object -First 1;
    
     for ($i = 0; $i -lt $maxIndex; $i++) 
        {
         
             $html2[$j]+="<tr>
           
                        <td>"+""+"</td>
                        <td>"+""+"</td>
                        <td>"+if ($i -lt $I_SmokeTestResult[$j]) { $I_SmokeTest[$j].get($i) } else { "" }+"</td>
                        <td>"+if ($i -lt $I_SmokeTestResult[$j]) { $I_SmokeTestResult[$j].get($i) } else { "" }+"</td>
                        <td>"+if ($i -lt $M_SmokeTestResult[$j]) { $M_SmokeTest[$j].get($i) } else { "" }+"</td>
                        <td>"+if ($i -lt $M_SmokeTestResult[$j]) { $M_SmokeTestResult[$j].get($i) } else { "" }+"</td> 
                        <td>"+if ($i -lt $R_SmokeTestResult[$j]) { $R_SmokeTest[$j].get($i) } else { "" }+"</td>
                        <td>"+if ($i -lt $R_SmokeTestResult[$j]) { $R_SmokeTestResult[$j].get($i) } else { "" }+"</td>                    
                        </tr>" 
                      
            }
        }
    $html2[$j]+=$header+'</table>'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-04
      • 1970-01-01
      • 1970-01-01
      • 2019-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多