2015-12-04 2 views
0

Я пытаюсь распечатать таблицу, используя flow-document, со свойством row-span.Таблица Rowspan issue 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

Смежные вопросы