|
| 1 | +using Aspose.Pdf.Cloud.Sdk.Model; |
| 2 | + |
| 3 | +namespace Tables |
| 4 | +{ |
| 5 | + public class TableCreate |
| 6 | + { |
| 7 | + public static Table New() |
| 8 | + { |
| 9 | + int num_of_cols = 5; |
| 10 | + int num_of_rows = 5; |
| 11 | + |
| 12 | + TextState header_text_state = new TextState( |
| 13 | + Font: "Arial Bold", |
| 14 | + FontSize: 11, |
| 15 | + ForegroundColor: new Color(A: 255, R: 255, G: 255, B: 255), |
| 16 | + FontStyle: FontStyles.Bold); |
| 17 | + |
| 18 | + TextState common_text_state = new TextState( |
| 19 | + Font: "Arial Bold", |
| 20 | + FontSize: 11, |
| 21 | + ForegroundColor: new Color(A: 255, R: 112, G: 112, B: 112), |
| 22 | + FontStyle: FontStyles.Regular); |
| 23 | + |
| 24 | + string col_widths = string.Empty; |
| 25 | + for (int col_index = 0; col_index < num_of_cols; col_index++) |
| 26 | + { |
| 27 | + col_widths += " 70"; |
| 28 | + } |
| 29 | + |
| 30 | + List<Row> table_rows = new List<Row>(); |
| 31 | + GraphInfo border_table_border = new GraphInfo( |
| 32 | + Color: new Color(A: 255, R: 0, G: 255, B: 0), |
| 33 | + LineWidth: 0.5); |
| 34 | + |
| 35 | + for (int row_index = 0; row_index < num_of_rows; row_index++) |
| 36 | + { |
| 37 | + List<Cell> row_cells = new List<Cell>(); |
| 38 | + |
| 39 | + for (int col_index = 0; col_index < num_of_cols; col_index++) |
| 40 | + { |
| 41 | + Cell cell = new Cell(DefaultCellTextState: common_text_state, Paragraphs: new List<TextRect>()); |
| 42 | + if (row_index == 0) |
| 43 | + { // header cells |
| 44 | + cell.BackgroundColor = new Color(A: 255, R: 128, G: 128, B: 128); |
| 45 | + cell.DefaultCellTextState = header_text_state; |
| 46 | + } |
| 47 | + else |
| 48 | + { |
| 49 | + cell.BackgroundColor = new Color(A: 255, R: 255, G: 255, B: 255); |
| 50 | + cell.DefaultCellTextState = common_text_state; |
| 51 | + }; |
| 52 | + |
| 53 | + TextRect text_rect = new TextRect(); |
| 54 | + if (row_index == 0) |
| 55 | + { |
| 56 | + text_rect.Text = "header #" + col_index.ToString(); |
| 57 | + } |
| 58 | + else |
| 59 | + text_rect.Text = string.Format("value '{0}', '{1}'", row_index, col_index); |
| 60 | + |
| 61 | + cell.Paragraphs.Add(text_rect); |
| 62 | + |
| 63 | + row_cells.Add(cell); |
| 64 | + } |
| 65 | + |
| 66 | + Row row = new Row(Cells: row_cells); |
| 67 | + table_rows.Add(row); |
| 68 | + } |
| 69 | + Table table = new Table(Left: 150, Top: 250, ColumnWidths: col_widths, Rows: table_rows); |
| 70 | + table.DefaultCellBorder = new BorderInfo( |
| 71 | + Top: border_table_border, |
| 72 | + Right: border_table_border, |
| 73 | + Bottom: border_table_border, |
| 74 | + Left: border_table_border, |
| 75 | + RoundedBorderRadius: 2); |
| 76 | + |
| 77 | + return table; |
| 78 | + } |
| 79 | + } |
| 80 | +} |
0 commit comments