Implement table styles
All checks were successful
CI Pipeline / build (pull_request) Successful in 14s
All checks were successful
CI Pipeline / build (pull_request) Successful in 14s
This commit is contained in:
74
README.md
74
README.md
@@ -261,6 +261,77 @@ Notare::Document.create("output.docx") do |doc|
|
||||
end
|
||||
```
|
||||
|
||||
#### Table Styles
|
||||
|
||||
Define reusable table styles with borders, shading, cell margins, and alignment:
|
||||
|
||||
```ruby
|
||||
Notare::Document.create("output.docx") do |doc|
|
||||
# Define a custom table style
|
||||
doc.define_table_style :fancy,
|
||||
borders: { style: "double", color: "0066CC", size: 6 },
|
||||
shading: "E6F2FF",
|
||||
cell_margins: 100,
|
||||
align: :center
|
||||
|
||||
# Apply the style to a table
|
||||
doc.table(style: :fancy) do
|
||||
doc.tr do
|
||||
doc.td "Product"
|
||||
doc.td "Price"
|
||||
end
|
||||
doc.tr do
|
||||
doc.td "Widget"
|
||||
doc.td "$10.00"
|
||||
end
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
#### Table Style Properties
|
||||
|
||||
| Property | Description | Example |
|
||||
|----------|-------------|---------|
|
||||
| `borders` | Border configuration | `{ style: "single", color: "000000", size: 4 }` |
|
||||
| `shading` | Background color (hex) | `"EEEEEE"` |
|
||||
| `cell_margins` | Cell padding (twips) | `100` or `{ top: 50, bottom: 50, left: 100, right: 100 }` |
|
||||
| `align` | Table alignment | `:left`, `:center`, `:right` |
|
||||
|
||||
**Border styles:** `single`, `double`, `dotted`, `dashed`, `triple`, `none`
|
||||
|
||||
**Border configuration options:**
|
||||
|
||||
```ruby
|
||||
# All borders the same
|
||||
borders: { style: "single", color: "000000", size: 4 }
|
||||
|
||||
# Per-edge borders
|
||||
borders: {
|
||||
top: { style: "double", color: "FF0000", size: 8 },
|
||||
bottom: { style: "single", color: "000000", size: 4 },
|
||||
left: { style: "none" },
|
||||
right: { style: "none" },
|
||||
insideH: { style: "dotted", color: "CCCCCC", size: 2 },
|
||||
insideV: { style: "dotted", color: "CCCCCC", size: 2 }
|
||||
}
|
||||
|
||||
# No borders
|
||||
borders: :none
|
||||
```
|
||||
|
||||
#### Built-in Table Styles
|
||||
|
||||
| Style | Description |
|
||||
|-------|-------------|
|
||||
| `:grid` | Standard black single-line borders |
|
||||
| `:borderless` | No borders |
|
||||
|
||||
```ruby
|
||||
doc.table(style: :borderless) do
|
||||
doc.tr { doc.td "No borders here" }
|
||||
end
|
||||
```
|
||||
|
||||
### Images
|
||||
|
||||
Images can be added to paragraphs, table cells, and list items. Supports PNG and JPEG formats.
|
||||
@@ -449,12 +520,13 @@ end
|
||||
| `link(url, text)` | Hyperlink with custom text |
|
||||
| `link(url) { }` | Hyperlink with block content |
|
||||
| `define_style(name, **props)` | Define a custom style |
|
||||
| `define_table_style(name, **props)` | Define a custom table style |
|
||||
| `ul { }` | Bullet list (can be nested) |
|
||||
| `ol { }` | Numbered list (can be nested) |
|
||||
| `li(text)` | List item with text |
|
||||
| `li { }` | List item with block content |
|
||||
| `li(text) { }` | List item with text and nested content |
|
||||
| `table { }` | Table |
|
||||
| `table(style:) { }` | Table with optional style |
|
||||
| `tr { }` | Table row |
|
||||
| `td(text)` | Table cell with text |
|
||||
| `td { }` | Table cell with block content |
|
||||
|
||||
Reference in New Issue
Block a user