EvotecIT / OfficeIMO

Fast and easy to use cross-platform .NET library that creates or modifies Microsoft Word (DocX) and later also Excel (XLSX) files without installing any software. Library is based on Open XML SDK
MIT License
263 stars 47 forks source link

[Potential Bug] Paragraph AddText Method sets given text to the current run before adding the paragraph. #177

Closed tmheath closed 7 months ago

tmheath commented 7 months ago

I am not sure whether or not this is a bug. par.AddText(text) will add text to the end of par and then return a new paragraph object. Proceeding from this applying settings such as bold to the returned paragraph apply below. Working on this I had assumed the behavior would be to add a new paragraph containing text and then apply settings but I found the reverse. Currently I have implemented reliance on the behavior as it stands but if this is actually a bug and not intended then it might need to be fixed.

Thanks

tmheath commented 7 months ago

As a side note I've started a hand typed manual using refman latex class for your library, it won't be updated so frequently but when complete it should be much more filled in as useful documentation for the word-processing than what you have being generated. It is however the lowest priority thing that I'm working on but I figured I'd mention it somewhere, if you have any advice I'd appreciate it (Not trying to cause offense but as a stranger coming into this library I ended up finding it easier to read your source code to figure things out then your documentation for a lot of things).

PrzemyslawKlys commented 7 months ago

This is what I expect

using (WordDocument document = WordDocument.Create(filePath)) {
    var paragraph = document.AddParagraph("Adding paragraph with some text");
    var newParagraph = paragraph.AddText(" and some more text");
    newParagraph.Bold = true;

    document.Save(true);
}

image

And with this code:

using (WordDocument document = WordDocument.Create(filePath)) {
    var paragraph = document.AddParagraph("Adding paragraph with some text");
    var newParagraph = paragraph.AddText(" and some more text");
    newParagraph.Bold = true;
    paragraph.Color = Color.Aquamarine;

    document.Save(true);
}

image

I am not sure if i understood your problem correctly - but for me paragraph until it's overwritten refers to first run.

PrzemyslawKlys commented 7 months ago

As a side note I've started a hand typed manual using refman latex class for your library, it won't be updated so frequently but when complete it should be much more filled in as useful documentation for the word-processing than what you have being generated. It is however the lowest priority thing that I'm working on but I figured I'd mention it somewhere, if you have any advice I'd appreciate it (Not trying to cause offense but as a stranger coming into this library I ended up finding it easier to read your source code to figure things out then your documentation for a lot of things).

I don't take offense in documentation based topic. The documentation doesn't exists and is mostly based on examples. I have no time to document fully both the source code or methods. It's not on my priority list, but maybe some day someone will sit down and write proper docs inside code, which then can be auto-generated properly. Maybe i'll even create Hugo website. For now the project is quite small and doesn't get much publicity.

tmheath commented 7 months ago

This is what I expect

using (WordDocument document = WordDocument.Create(filePath)) {
    var paragraph = document.AddParagraph("Adding paragraph with some text");
    var newParagraph = paragraph.AddText(" and some more text");
    newParagraph.Bold = true;

    document.Save(true);
}

image

And with this code:

using (WordDocument document = WordDocument.Create(filePath)) {
    var paragraph = document.AddParagraph("Adding paragraph with some text");
    var newParagraph = paragraph.AddText(" and some more text");
    newParagraph.Bold = true;
    paragraph.Color = Color.Aquamarine;

    document.Save(true);
}

image

I am not sure if i understood your problem correctly - but for me paragraph until it's overwritten refers to first run.

I see, I had a conceptual misunderstanding. My code used a Table cell to create a new paragraph which I then called add text onto in order to insert a run into the text. That is what I expected from the XML but is makes sense now how this works to me. Thank you for your fast response clearing that up.

The manual I've designed has a front section focusing on the consumer facing interface while the back section will actually document all the code, as it currently stands. Painful to update and initially get working, it should be nice enough to work updated every so often without having to be kept exactly up to date. But as I mentioned, I'm working on that under everything else so it's chugging along slowly. When/if I get it finished in time, I'll point you at it.