Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supports modify RunStyle #74

Open
rstm-sf opened this issue Nov 14, 2022 · 6 comments
Open

Supports modify RunStyle #74

rstm-sf opened this issue Nov 14, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@rstm-sf
Copy link
Contributor

rstm-sf commented Nov 14, 2022

It would be nice to add modifiing RunStyle from RunProperties. This issue is on par with #73

@rstm-sf
Copy link
Contributor Author

rstm-sf commented Nov 14, 2022

@PrzemyslawKlys maybe you have a vision where/within what it is better to add it?

@PrzemyslawKlys
Copy link
Member

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.

image

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?

image

I don't have super experience with this so I'm open to suggestions.

From what I see in Aspose:

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;
//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;

🤷‍♂️

@PrzemyslawKlys
Copy link
Member

Here's one from Syncfusion

//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

@PrzemyslawKlys PrzemyslawKlys added the enhancement New feature or request label Nov 14, 2022
@rstm-sf
Copy link
Contributor Author

rstm-sf commented Nov 14, 2022

This is necessary to support the inline style. For example, as you rightly noted Hyperlink. Or another example — inlined code

@rstm-sf
Copy link
Contributor Author

rstm-sf commented Nov 14, 2022

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

@PrzemyslawKlys
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants