2015-12-04 54 views
0

我想用row-span屬性打印使用流文檔的表。表Rowspan問題flowdocument C#

我想打印以下輸出,

enter image description here

,但它給了我這個

enter image description here

我不明白這有什麼錯我的代碼,也許我錯過了一些東西。 任何幫助appreciated.Please看到下面的代碼,

Table tbl = new Table(); 
      for (int i = 0; i < 2; i++) 
      { 
       TableColumn tableCol = new TableColumn(); 
       tableCol.Width = new GridLength(150); 
       tbl.Columns.Add(tableCol); 
      } 

      TableRow row = new TableRow(); 
      row.Background = Brushes.White; 
      row.FontSize = PointsToPixels(TITLETEXTSIZE); 
      row.FontFamily = new FontFamily(FONTFAMILY); 


      row.Cells.Add(new TableCell(new Paragraph(new Run("cell1")))); 
      row.Cells[0].BorderBrush = Brushes.Black; 
      row.Cells[0].BorderThickness = new Thickness(0.0, 1.0, 1, 0.0); 
      row.Cells[0].RowSpan = 2; 

      row.Cells.Add(new TableCell(new Paragraph(new Run("cell2")))); 
      row.Cells[1].BorderBrush = Brushes.Black; 
      row.Cells[1].BorderThickness = new Thickness(0.0, 0.0, 0, 1.0); 
      row.Cells[1].RowSpan = 1; 

      var rowgroup = new TableRowGroup(); 
      rowgroup.Rows.Add(row); 
      tbl.RowGroups.Add(rowgroup); 


      row = new TableRow(); 
      row.Background = Brushes.White; 
      row.FontSize = PointsToPixels(TITLETEXTSIZE); 
      row.FontFamily = new FontFamily(FONTFAMILY); 

      row.Cells.Add(new TableCell(new Paragraph(new Run("cell1")))); 
      row.Cells[0].BorderBrush = Brushes.Black; 
      row.Cells[0].BorderThickness = new Thickness(0.0, 1.0, 1, 1.0); 
      row.Cells[0].RowSpan = 1; 

      rowgroup = new TableRowGroup(); 
      rowgroup.Rows.Add(row); 
      tbl.RowGroups.Add(rowgroup); 

      tbl.BorderThickness = new Thickness(1, 1, 1, 0); 
      tbl.BorderBrush = Brushes.Black; 

回答

1

這是一個快速的嘗試在XAML中,同樣需要遵循在C#中,同時構建流程文檔。

嘗試添加表格行組並添加表格行。

<FlowDocument> 
      <Table> 
       <TableRowGroup> 
        <TableRow> 
         <TableCell Background="Green" RowSpan="2"> 
          <Paragraph>Cell 1</Paragraph> 
         </TableCell> 
         <TableCell> 
          <Paragraph Background="Yellow">Cell 2</Paragraph> 
         </TableCell> 
        </TableRow> 
        <TableRow> 
         <TableCell Background="Red"> 
          <Paragraph>Cell 1</Paragraph> 
         </TableCell> 

        </TableRow> 
       </TableRowGroup> 
      </Table> 
    </FlowDocument> 

enter image description here

+0

得到了答案的想法。而不是創建新的TableRowGroup,** rowgroup = new TableRowGroup(); **我向現有的行組添加了新行。 – sharad