表格
透過 Facade API 插入、調整大小、設定樣式並編輯結構化 PDF 表格。
FPdfTable 維護結構化格線,其中包含穩定的儲存格包裝器,並為每個儲存格保存一個可編輯文字 story。
插入與編輯表格
TypeScript
const table = page.insertTable({ rowCount: 2, columnCount: 2, cellTexts: ['Owner', 'Status', 'Docs', 'Ready'], left: 36, top: 36, width: 360, height: 108,})table.resize(3, 2)table.getCell(2, 0).setText('Legal')table.getCell(2, 1).setText('Review')列數和欄數必須是正安全整數,且表格不得超過 10,000 個儲存格。調整大小時會按位置保留重疊的儲存格。
套用表格主題
TypeScript
const [preset] = univerAPI.getPdfTableThemePresets()if (preset) { table.setTheme({ styleId: preset.id, options: { firstRow: true }, })}getPdfTableThemePresets() 傳回分離的 { id, group } 描述元。請將預設的 id 用作 styleId,不要把描述元直接傳給 setTheme()。
儲存格樣式
TypeScript
table.getCell(0, 0).setStyle({ fill: { color: '#eef3ff' }, fontColor: '#1d4ed8', horizontalAlignment: univerAPI.Enum.HorizontalAlign.CENTER, verticalAlign: univerAPI.Enum.PdfTableCellVerticalAlign.MIDDLE,})FPdfTableCell.setStyle() 接受容器欄位,以及作用於整個儲存格的 fontColor 和 horizontalAlignment。透過 univerAPI.Enum 使用 PdfTableCellVerticalAlign。
表格方法包括 getRowCount()、getColumnCount()、getCell()、resize()、getTheme() 和 setTheme()。儲存格方法包括 getText()、setText()、getStyle() 和 setStyle()。
你覺得這篇文檔如何?