Apply bundled Office StyleSets or load them from .dotx files.
1. What Are StyleSets
StyleSets are collections of professionally designed style definitions. They work alongside themes to create beautifully formatted documents with consistent styling.
A StyleSet (.dotx file) contains:
-
Style definitions for headings, body text, quotes, etc.
-
Paragraph formatting (spacing, indentation, alignment)
-
Character formatting (fonts, colors, sizes)
-
Table styles
2. Using Bundled StyleSets
Uniword includes 12 Office StyleSets as bundled YAML files:
# Load bundled StyleSet by name
styleset = Uniword::StyleSet.load('distinctive')
# Apply to document
doc = Uniword::Document.new
styleset.apply_to(doc)
# Or use shorthand method
doc.apply_styleset('distinctive')
# List available bundled StyleSets
available = Uniword::StyleSet.available_stylesets
# => ["distinctive", "elegant", "fancy", "formal", ...]
|
StyleSets use Uniword names (e.g., |
3. Loading StyleSets from .dotx Files
Load a StyleSet directly from a Microsoft Office .dotx file:
# Load StyleSet from .dotx file
styleset = Uniword::StyleSet.from_dotx('path/to/Distinctive.dotx')
puts styleset.name
# => "Distinctive"
puts styleset.styles.count
# => 42
# Apply to document
doc = Uniword::Document.new
styleset.apply_to(doc)
doc.add_paragraph("Heading", heading: :heading_1)
doc.save('output.docx')
4. Conflict Resolution Strategies
When applying a StyleSet, you can control how conflicts with existing styles are handled:
# Keep existing styles, add only new ones (default)
styleset.apply_to(doc, strategy: :keep_existing)
# Replace existing styles with StyleSet styles
styleset.apply_to(doc, strategy: :replace)
# Keep both, rename imported styles
styleset.apply_to(doc, strategy: :rename)
5. Combining Themes and StyleSets
Themes define colors and fonts. StyleSets define style formatting:
doc = Uniword::Document.new
# Apply theme (colors and fonts)
doc.apply_theme('celestial')
# Apply StyleSet (style definitions)
doc.apply_styleset('distinctive')
# Use the styled content
doc.add_paragraph('Document Title', heading: :heading_1)
doc.add_paragraph('Introduction paragraph with consistent styling.')
doc.save('professional_document.docx')
6. Available StyleSets
| Uniword Name | Description |
|---|---|
|
Bold headings with color accents |
|
Refined, professional appearance |
|
Decorative, attention-grabbing |
|
Traditional business document styling |
|
Book-style formatting |
|
Contemporary, minimalist design |
|
Newspaper-style columns and headers |
|
Dynamic, angled headings |
|
Minimal, unobtrusive formatting |
|
Textured, organic appearance |
|
Classic document styling |
|
Basic Word 2010 formatting |