@@ -181,12 +181,83 @@ p_children = p_element.xpath("//child::*") # selects all children
181181p_child = p_element.at_xpath(" //child::*" ) # selects first child
182182```
183183
184+ ### Writing and Manipulating Styles
185+ ``` ruby
186+ require ' docx'
187+
188+ d = Docx ::Document .open (' example.docx' )
189+ existing_style = d.styles_configuration.style_of(" Heading 1" )
190+ existing_style.font_color = " 000000"
191+
192+ # see attributes below
193+ new_style = d.styles_configuration.add_style(" Red" , name: " Red" , font_color: " FF0000" , font_size: 20 )
194+ new_style.bold = true
195+
196+ d.paragraphs.each do |p |
197+ p .style = " Red"
198+ end
199+
200+ d.paragraphs.each do |p |
201+ p .style = " Heading 1"
202+ end
203+
204+ d.styles_configuration.remove_style(" Red" )
205+ ```
206+
207+ #### Style Attributes
208+
209+ The following is a list of attributes and what they control within the style.
210+
211+ - ** id** : The unique identifier of the style. (required)
212+ - ** name** : The human-readable name of the style. (required)
213+ - ** type** : Indicates the type of the style (e.g., paragraph, character).
214+ - ** keep_next** : Boolean value controlling whether to keep a paragraph and the next one on the same page. Valid values: ` true ` /` false ` .
215+ - ** keep_lines** : Boolean value specifying whether to keep all lines of a paragraph together on one page. Valid values: ` true ` /` false ` .
216+ - ** page_break_before** : Boolean value indicating whether to insert a page break before the paragraph. Valid values: ` true ` /` false ` .
217+ - ** widow_control** : Boolean value controlling widow and orphan lines in a paragraph. Valid values: ` true ` /` false ` .
218+ - ** shading_style** : Defines the shading pattern style.
219+ - ** shading_color** : Specifies the color of the shading pattern. Valid values: Hex color codes.
220+ - ** shading_fill** : Indicates the background fill color of shading.
221+ - ** suppress_auto_hyphens** : Boolean value controlling automatic hyphenation. Valid values: ` true ` /` false ` .
222+ - ** bidirectional_text** : Boolean value indicating if the paragraph contains bidirectional text. Valid values: ` true ` /` false ` .
223+ - ** spacing_before** : Defines the spacing before a paragraph.
224+ - ** spacing_after** : Specifies the spacing after a paragraph.
225+ - ** line_spacing** : Indicates the line spacing of a paragraph.
226+ - ** line_rule** : Defines how line spacing is calculated.
227+ - ** indent_left** : Sets the left indentation of a paragraph.
228+ - ** indent_right** : Specifies the right indentation of a paragraph.
229+ - ** indent_first_line** : Indicates the first line indentation of a paragraph.
230+ - ** align** : Controls the text alignment within a paragraph.
231+ - ** font** : Sets the font for different scripts (ASCII, complex script, East Asian, etc.).
232+ - ** font_ascii** : Specifies the font for ASCII characters.
233+ - ** font_cs** : Indicates the font for complex script characters.
234+ - ** font_hAnsi** : Sets the font for high ANSI characters.
235+ - ** font_eastAsia** : Specifies the font for East Asian characters.
236+ - ** bold** : Boolean value controlling bold formatting. Valid values: ` true ` /` false ` .
237+ - ** italic** : Boolean value indicating italic formatting. Valid values: ` true ` /` false ` .
238+ - ** caps** : Boolean value controlling capitalization. Valid values: ` true ` /` false ` .
239+ - ** small_caps** : Boolean value specifying small capital letters. Valid values: ` true ` /` false ` .
240+ - ** strike** : Boolean value indicating strikethrough formatting. Valid values: ` true ` /` false ` .
241+ - ** double_strike** : Boolean value defining double strikethrough formatting. Valid values: ` true ` /` false ` .
242+ - ** outline** : Boolean value specifying outline effects. Valid values: ` true ` /` false ` .
243+ - ** outline_level** : Indicates the outline level in a document's hierarchy.
244+ - ** font_color** : Sets the text color. Valid values: Hex color codes.
245+ - ** font_size** : Controls the font size.
246+ - ** font_size_cs** : Specifies the font size for complex script characters.
247+ - ** underline_style** : Indicates the style of underlining.
248+ - ** underline_color** : Specifies the color of the underline. Valid values: Hex color codes.
249+ - ** spacing** : Controls character spacing.
250+ - ** kerning** : Sets the space between characters.
251+ - ** position** : Controls the position of characters (superscript/subscript).
252+ - ** text_fill_color** : Sets the fill color of text. Valid values: Hex color codes.
253+ - ** vertical_alignment** : Controls the vertical alignment of text within a line.
254+ - ** lang** : Specifies the language tag for the text.
255+
184256## Development
185257
186258### todo
187259
188260* Calculate element formatting based on values present in element properties as well as properties inherited from parents
189261* Default formatting of inserted elements to inherited values
190262* Implement formattable elements.
191- * Implement styles.
192263* Easier multi-line text insertion at a single bookmark (inserting paragraph nodes after the one containing the bookmark)
0 commit comments