Code Monkey home page Code Monkey logo

Comments (6)

PrzemyslawKlys avatar PrzemyslawKlys commented on May 12, 2024 1

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.

from officeimo.

rstm-sf avatar rstm-sf commented on May 12, 2024

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

from officeimo.

PrzemyslawKlys avatar PrzemyslawKlys commented on May 12, 2024

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;

🤷‍♂️

from officeimo.

PrzemyslawKlys avatar PrzemyslawKlys commented on May 12, 2024

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

from officeimo.

rstm-sf avatar rstm-sf commented on May 12, 2024

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

from officeimo.

rstm-sf avatar rstm-sf commented on May 12, 2024

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

from officeimo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.