OfficeIMO
OfficeIMO copied to clipboard
Supports modify RunStyle
It would be nice to add modifiing RunStyle from RunProperties. This issue is on par with https://github.com/EvotecIT/OfficeIMO/issues/73
@PrzemyslawKlys maybe you have a vision where/within what it is better to add it?
I am not sure I understand the question. From what I see I use it exactly 2 times as part of WordHyperLink.
I assume you want to add ability to create custom style and RunStyle is part of making sure that happens.
When I look at Word there are multiple, but limited styles built in + the styles that are part of TOC, again quite limited. I've defined only styles as part of TOC I believe.
My idea would be to recreate all the styles that come built-in in Word with their respective name and so on so the user can find out by checking what style it is, but if it doesn't match defined styles it would refer to custom style. ANd custom style would be separate class with it's own definitions? This class would mainly limit inputs to what the GUI proposes?
I don't have super experience with this so I'm open to suggestions.
From what I see in Aspose:
- https://forum.aspose.com/t/how-to-create-custom-style-using-c/208115/2
Document doc = new Document();
// Create a paragraph style and specify some formatting for it
Style style = doc.Styles.Add(StyleType.Paragraph, "MyStyle1");
style.Font.Size = 24;
style.Font.Name = "Verdana";
style.ParagraphFormat.SpaceAfter = 12;
- https://learn.microsoft.com/en-us/office/open-xml/how-to-create-and-add-a-character-style-to-a-word-processing-document
- https://learn.microsoft.com/en-us/office/open-xml/how-to-create-and-add-a-paragraph-style-to-a-word-processing-document
- Devexpress - https://docs.devexpress.com/OfficeFileAPI/400460/word-processing-document-api/text-formatting
//Open the document for editing
document.BeginUpdate();
//Create a new paragraph style instance
//and specify the required properties
ParagraphStyle chapterStyle = document.ParagraphStyles.CreateNew();
chapterStyle.Name = "MyTitleStyle";
chapterStyle.ForeColor = Color.SteelBlue;
chapterStyle.FontSize = 16;
chapterStyle.FontName = "Segoe UI Semilight";
chapterStyle.Alignment = ParagraphAlignment.Left;
chapterStyle.SpacingBefore = Units.InchesToDocumentsF(0.2f);
chapterStyle.SpacingAfter = Units.InchesToDocumentsF(0.2f);
chapterStyle.OutlineLevel = 2;
//Add the object to the document collection
document.ParagraphStyles.Add(chapterStyle);
//Finalize the editing
document.EndUpdate();
//Apply the created style to every chapter in the document
for (int i = 0; i < document.Paragraphs.Count; i++)
{
string var = document.GetText(document.Paragraphs[i].Range);
if (var.Contains("Chapter "))
{
document.Paragraphs[i].Style = chapterStyle;
}
}
return;
🤷♂️
Here's one from Syncfusion
- https://help.syncfusion.com/file-formats/docio/working-with-word-document
//Creates a Word document
using (WordDocument document = new WordDocument())
{
//This method adds a section and a paragraph in the document
document.EnsureMinimal();
//Adds a new paragraph style named "ParagraphStyle"
WParagraphStyle paraStyle = document.AddParagraphStyle("ParagraphStyle") as WParagraphStyle;
//Sets the formatting of the style
paraStyle.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
//Adds a new character style named "CharacterStyle"
IWCharacterStyle charStyle = document.AddCharacterStyle("CharacterStyle");
//Sets the formatting of the style
charStyle.CharacterFormat.Bold = true;
charStyle.CharacterFormat.Italic = true;
//Link both paragraph and character style
paraStyle.LinkedStyleName = "CharacterStyle";
//Appends the contents into the paragraph
document.LastParagraph.AppendText("AdventureWorks Cycles");
//Applies the style to paragraph
document.LastParagraph.ApplyStyle("ParagraphStyle");
//Appends new paragraph in section
document.LastSection.AddParagraph();
//Appends the contents into the paragraph
document.LastParagraph.AppendText("AdventureWorks Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company.");
//Applies paragraph style to the text range
(document.LastParagraph.ChildEntities[0] as WTextRange).ApplyStyle("ParagraphStyle");
//Saves the document
document.Save("Result.docx", FormatType.Docx);
}
So I guess separate class that you "define" and later on you build it up and apply to paragraphs. Hope that is what you are asking
This is necessary to support the inline style. For example, as you rightly noted Hyperlink. Or another example — inlined code
So I guess separate class that you "define" and later on you build it up and apply to paragraphs. Hope that is what you are asking
Not exactly, it's not for paragraphs, it's for the Run. Ran part of a paragraph and it can have its own style
Right, but I treat 1 run = 1 WordParagraph in OfficeIMO. And then 1 Paragraph can have multiple runs and be attached to multiple WordParagraphs. So in the end you want a class named like WordParagraphStyle which would have Public property _RunStyle which would allow deep diving if someone doesn't like the "easy" get/set and there would be bunch of defined properties that control things? Or do I misunderstand? Feel free to ignore me tho.