Skip to content

Commit ef33af1

Browse files
Updated table styles examples
1 parent 658a727 commit ef33af1

File tree

2 files changed

+17
-79
lines changed
  • content/english/python-net/tables-and-formatting

2 files changed

+17
-79
lines changed

content/english/python-net/tables-and-formatting/document-table-styles-formatting/_index.md

Lines changed: 16 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Before we dive into the specifics of document table styles and formatting, let's
2323
2. Import the Library: Import the Aspose.Words library into your Python script using the following import statement:
2424

2525
```python
26-
import aspose.words
26+
import aspose.words as aw
2727
```
2828

2929
3. Load a Document: Load an existing document or create a new one using the Aspose.Words API.
@@ -35,7 +35,7 @@ To create and insert tables into documents using Aspose.Words for Python, follow
3535
1. Create a Table: Use the `DocumentBuilder` class to create a new table and specify the number of rows and columns.
3636

3737
```python
38-
builder = aspose.words.DocumentBuilder(doc)
38+
builder = aw.DocumentBuilder(doc)
3939
table = builder.start_table()
4040
```
4141

@@ -65,7 +65,7 @@ Basic table formatting can be achieved using methods provided by the `Table` and
6565

6666
```python
6767
for cell in table.first_row.cells:
68-
cell.cell_format.preferred_width = aspose.words.PreferredWidth.from_points(100)
68+
cell.cell_format.preferred_width = aw.PreferredWidth.from_points(100)
6969
```
7070
7171
2. Cell Padding: Add padding to cells for improved spacing.
@@ -80,32 +80,8 @@ Basic table formatting can be achieved using methods provided by the `Table` and
8080
8181
```python
8282
for row in table.rows:
83-
row.row_format.height_rule = aspose.words.HeightRule.AT_LEAST
84-
row.row_format.height = aspose.words.ConvertUtil.inch_to_points(1)
85-
```
86-
87-
## Styling Tables with Aspose.Words
88-
89-
Aspose.Words for Python provides a range of styling options to make your tables visually appealing:
90-
91-
1. Table Styles: Apply predefined table styles to achieve a professional look.
92-
93-
```python
94-
table.style = aspose.words.StyleIdentifier.LIGHT_LIST_ACCENT_5
95-
```
96-
97-
2. Cell Background Color: Change cell background color to highlight specific data.
98-
99-
```python
100-
cell.cell_format.shading.background_pattern_color = aspose.words.Color.from_rgb(240, 240, 240)
101-
```
102-
103-
3. Font Formatting: Customize font style, size, and color for better readability.
104-
105-
```python
106-
run = cell.paragraphs[0].runs[0]
107-
run.font.size = aspose.words.Size(12, aspose.words.SizeUnit.POINTS)
108-
run.font.color = aspose.words.Color.from_rgb(0, 0, 0)
83+
row.row_format.height_rule = aw.HeightRule.AT_LEAST
84+
row.row_format.height = aw.ConvertUtil.inch_to_points(1)
10985
```
11086
11187
## Merging and Splitting Cells for Complex Layouts
@@ -115,30 +91,14 @@ Creating complex table layouts often requires merging and splitting cells:
11591
1. Merge Cells: Merge multiple cells to create a single larger cell.
11692
11793
```python
118-
table.rows[0].cells[0].cell_format.horizontal_merge = aspose.words.CellMerge.FIRST
119-
table.rows[0].cells[1].cell_format.horizontal_merge = aspose.words.CellMerge.PREVIOUS
94+
table.rows[0].cells[0].cell_format.horizontal_merge = aw.CellMerge.FIRST
95+
table.rows[0].cells[1].cell_format.horizontal_merge = aw.CellMerge.PREVIOUS
12096
```
12197
12298
2. Split Cells: Split cells back into their individual components.
12399
124100
```python
125-
cell.cell_format.horizontal_merge = aspose.words.CellMerge.NONE
126-
```
127-
128-
## Adjusting Row and Column Heights and Widths
129-
130-
Fine-tune row and column dimensions for a balanced table layout:
131-
132-
1. Adjust Row Height: Modify row height based on content.
133-
134-
```python
135-
row.row_format.height_rule = aspose.words.HeightRule.AUTO
136-
```
137-
138-
2. Adjust Column Width: Automatically adjust column width to fit content.
139-
140-
```python
141-
table.auto_fit(auto_fit_behaviour=aspose.words.AutoFitBehaviour.AUTO_FIT_TO_CONTENTS)
101+
cell.cell_format.horizontal_merge = aw.CellMerge.NONE
142102
```
143103
144104
## Adding Borders and Shading to Tables
@@ -148,13 +108,13 @@ Enhance table appearance by adding borders and shading:
148108
1. Borders: Customize borders for tables and cells.
149109
150110
```python
151-
table.set_borders(0.5, aspose.words.LineStyle.SINGLE, aspose.words.Color.from_rgb(0, 0, 0))
111+
table.set_borders(0.5, aw.LineStyle.SINGLE, aw.Color.from_rgb(0, 0, 0))
152112
```
153113
154114
2. Shading: Apply shading to cells for a visually appealing effect.
155115
156116
```python
157-
cell.cell_format.shading.background_pattern_color = aspose.words.Color.from_rgb(230, 230, 230)
117+
cell.cell_format.shading.background_pattern_color = aw.Color.from_rgb(230, 230, 230)
158118
```
159119
160120
## Working with Cell Content and Alignment
@@ -171,7 +131,7 @@ Efficiently manage cell content and alignment for better readability:
171131
2. Text Alignment: Align cell text as needed.
172132
173133
```python
174-
cell.paragraphs[0].paragraph_format.alignment = aspose.words.ParagraphAlignment.CENTER
134+
cell.paragraphs[0].paragraph_format.alignment = aw.ParagraphAlignment.CENTER
175135
```
176136
177137
## Handling Table Headers and Footers
@@ -188,53 +148,31 @@ Incorporate headers and footers into your tables for better context:
188148
189149
```python
190150
footer_row = table.append_row()
191-
footer_row.cells[0].cell_format.horizontal_merge = aspose.words.CellMerge.NONE
151+
footer_row.cells[0].cell_format.horizontal_merge = aw.CellMerge.NONE
192152
footer_row.cells[0].paragraphs[0].runs[0].text = "Total"
193153
```
194154
195-
## Automatically Adjusting Table Layout
196-
197-
Ensure that your table layout adjusts automatically based on content:
198-
199-
1. Auto Fit to Window: Allow the table to fit within the page width.
200-
201-
```python
202-
table.allow_auto_fit = True
203-
```
204-
205-
2. Auto Resize Cells: Enable automatic cell resizing to accommodate content.
206-
207-
```python
208-
table.auto_fit(auto_fit_behaviour=aspose.words.AutoFitBehaviour.AUTO_FIT_TO_WINDOW)
209-
```
210-
211155
## Exporting Tables to Different Formats
212156
213157
Once your table is ready, you can export it to various formats, such as PDF or DOCX:
214158
215159
1. Save as PDF: Save the document with the table as a PDF file.
216160
217161
```python
218-
doc.save("table_document.pdf", aspose.words.SaveFormat.PDF)
162+
doc.save("table_document.pdf", aw.SaveFormat.PDF)
219163
```
220164
221165
2. Save as DOCX: Save the document as a DOCX file.
222166
223167
```python
224-
doc.save("table_document.docx", aspose.words.SaveFormat.DOCX)
168+
doc.save("table_document.docx", aw.SaveFormat.DOCX)
225169
```
226-
227-
## Troubleshooting and Tips for Effective Table Management
228-
229-
- If tables appear distorted, check for incorrect column widths or row heights.
230-
- Test table rendering in different formats to ensure consistency.
231-
- For complex layouts, plan cell merging and splitting carefully.
232-
170+
233171
## Conclusion
234172
235173
Aspose.Words for Python offers a comprehensive toolkit for creating, styling, and formatting document tables. By following the steps outlined in this article, you can effectively manage tables in your documents, customize their appearance, and export them to various formats. Harness the power of Aspose.Words to enhance your document presentations and provide clear, visually appealing information to your readers.
236174
237-
## FAQs
175+
## FAQ's
238176
239177
### How do I install Aspose.Words for Python?
240178

content/english/python-net/tables-and-formatting/document-tables/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Tables are constructed using the Table class in Aspose.Words. To create a table,
5050

5151
```python
5252
# Create a table with 3 rows and 4 columns
53-
table = doc.tables.add(3, 4)
53+
table = doc.get_child(aw.NodeType.TABLE, 0, True).as_table()
5454

5555
# Set preferred width for the table
5656
table.preferred_width = doc.page_width

0 commit comments

Comments
 (0)