Skip to content

Commit 3df98a3

Browse files
committed
Adding more documentation
1 parent 1775fee commit 3df98a3

1 file changed

Lines changed: 55 additions & 1 deletion

File tree

README.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,18 +186,72 @@ p_child = p_element.at_xpath("//child::*") # selects first child
186186
require 'docx'
187187

188188
d = Docx::Document.open('example.docx')
189+
existing_style = d.styles_config.style_of("Heading 1")
190+
existing_style.font_color = "000000"
189191

190-
# see lib/docx/elements/style.rb for more attributes you can set!
192+
# see attributes below
191193
new_style = d.styles_config.add_style("Red", name: "Red", font_color: "FF0000", font_size: 20)
192194
new_style.bold = true
193195

194196
d.paragraphs.each do |p|
195197
p.style = "Red"
196198
end
197199

200+
d.paragraphs.each do |p|
201+
p.style = "Heading 1"
202+
end
203+
198204
d.styles_config.remove_style("Red")
199205
```
200206

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.
201255

202256
## Development
203257

0 commit comments

Comments
 (0)