|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "strconv" |
| 5 | + |
| 6 | + asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" |
| 7 | +) |
| 8 | + |
| 9 | +func InitializeTable() *asposepdfcloud.Table { |
| 10 | + // Initialize new table |
| 11 | + num_of_cols := 5 |
| 12 | + num_of_rows := 5 |
| 13 | + |
| 14 | + header_text_state := asposepdfcloud.TextState{ |
| 15 | + Font: "Arial Bold", |
| 16 | + FontSize: 11, |
| 17 | + ForegroundColor: &asposepdfcloud.Color{A: 255, R: 255, G: 255, B: 255}, |
| 18 | + FontStyle: asposepdfcloud.FontStylesBold, |
| 19 | + } |
| 20 | + |
| 21 | + common_text_state := asposepdfcloud.TextState{ |
| 22 | + Font: "Arial Bold", |
| 23 | + FontSize: 11, |
| 24 | + ForegroundColor: &asposepdfcloud.Color{A: 255, R: 112, G: 112, B: 112}, |
| 25 | + FontStyle: asposepdfcloud.FontStylesRegular, |
| 26 | + } |
| 27 | + |
| 28 | + col_widths := "" |
| 29 | + for col_index := 0; col_index < num_of_cols; col_index++ { |
| 30 | + col_widths += " 70" |
| 31 | + } |
| 32 | + |
| 33 | + var table_rows = []asposepdfcloud.Row{} |
| 34 | + |
| 35 | + border_table_border := asposepdfcloud.GraphInfo{ |
| 36 | + Color: &asposepdfcloud.Color{A: 255, R: 0, G: 255, B: 0}, |
| 37 | + LineWidth: 0.5, |
| 38 | + } |
| 39 | + |
| 40 | + for row_index := 0; row_index < num_of_rows; row_index++ { |
| 41 | + var row_cells = []asposepdfcloud.Cell{} |
| 42 | + |
| 43 | + for col_index := 0; col_index < num_of_cols; col_index++ { |
| 44 | + cell := asposepdfcloud.Cell{DefaultCellTextState: &common_text_state} |
| 45 | + |
| 46 | + if row_index == 0 { |
| 47 | + // header cells |
| 48 | + cell.BackgroundColor = &asposepdfcloud.Color{A: 255, R: 128, G: 128, B: 128} |
| 49 | + cell.DefaultCellTextState = &header_text_state |
| 50 | + } else { |
| 51 | + cell.BackgroundColor = &asposepdfcloud.Color{A: 255, R: 255, G: 255, B: 255} |
| 52 | + } |
| 53 | + |
| 54 | + text_rect := asposepdfcloud.TextRect{} |
| 55 | + if row_index == 0 { |
| 56 | + text_rect.Text = "header #" + strconv.Itoa(col_index) |
| 57 | + } else { |
| 58 | + text_rect.Text = "value '" + strconv.Itoa(row_index) + "','" + strconv.Itoa(col_index) + "'" |
| 59 | + } |
| 60 | + |
| 61 | + cell.Paragraphs = append(cell.Paragraphs, text_rect) |
| 62 | + |
| 63 | + row_cells = append(row_cells, cell) |
| 64 | + } |
| 65 | + |
| 66 | + row := asposepdfcloud.Row{Cells: row_cells} |
| 67 | + |
| 68 | + table_rows = append(table_rows, row) |
| 69 | + } |
| 70 | + |
| 71 | + table := asposepdfcloud.Table{Left: 150, Top: 250, ColumnWidths: col_widths, Rows: table_rows} |
| 72 | + |
| 73 | + table.DefaultCellBorder = &asposepdfcloud.BorderInfo{ |
| 74 | + Top: &border_table_border, |
| 75 | + Right: &border_table_border, |
| 76 | + Bottom: &border_table_border, |
| 77 | + Left: &border_table_border, |
| 78 | + RoundedBorderRadius: 2, |
| 79 | + } |
| 80 | + |
| 81 | + return &table |
| 82 | +} |
0 commit comments