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
280 stars 50 forks source link

Extending field type list #71

Closed byteSamurai closed 1 year ago

byteSamurai commented 1 year ago

Hey, At the moment, I have struggles to add custom field codes because the enum does not contain the whole list of field codes, but only a subset: https://github.com/EvotecIT/OfficeIMO/blob/master/OfficeIMO.Word/WordField.cs#L10

E.g., could we add BIBLIOGRAPHY to it? See: https://support.microsoft.com/en-us/office/field-codes-bibliography-field-cbb17838-05d7-4533-8066-4791aeddb9de

Some field codes require switches, so how about passing a dictionary to AddField(...) as an optional argument?

Do you think that is doable? Do you prefer a PR or to do it yourself?

PrzemyslawKlys commented 1 year ago

Hi,

I've implemented what I actually tested works and that I mostly understood. I am not sure how all other fields behave and whether or not those can be easily defined the same way. If you know how all those are handled I would be more than happy to get a PR. I would love people to join in - as I have no clue what I am doping most of the time.

Please make sure to add couple of examples/tests.

Przemek

byteSamurai commented 1 year ago

as I have no clue what I am doping most of the time

Yeah yeah... the humble MS MVPs 😏

I will try to send a PR asap.

PrzemyslawKlys commented 1 year ago

as I have no clue what I am doping most of the time

Yeah yeah... the humble MS MVPs 😏

My MVP title is for Cloud & Datacenter, aka Sysadmin/PowerShell stuff. Playing with C# is my hobby, and I just tend to use my skill of bashing my head against the wall long enough for patterns to emerge and I somehow get it to work. Then copilot, resharper and VS enterprise comes in with some advice and things seems to work out better or worse. But I am far from knowing what I am actually doing with openxmlπŸ€£πŸ˜‚

byteSamurai commented 1 year ago

Let me put it this way: It's refreshing to see a maintainer who is open to contributions. I saw exciting projects on Github, but the maintainers were very biased about their code quality. If you see a larger project w/o testing and the maintainer don't wants to change anything because it's so "well-crafted", ... don't use it! However, I saw some magic strings/numbers in the parsing of the field codes. I am about to refactor this part at the moment. Looking forwarding hearing your opinion about it once I have done it. πŸ’ͺ🏻

byteSamurai commented 1 year ago

Hey @PrzemyslawKlys would you mind if I also clean up stuff like this? https://github.com/EvotecIT/OfficeIMO/blob/master/OfficeIMO.Word/WordSection.cs#L168

The first return statement looks like a left-over.. WDYT? πŸ€”

PrzemyslawKlys commented 1 year ago

No, go ahead. The very first version I created had a lot of stuff that was calculated by me and I was doing all the tracking what changes and how. Once I had a working model with tests I decided to go back and rewrite all the properties/methods to get stuff dynamically with the exception of sections. There are a lot of left-overs like this in code. Some are commented out, some are not. I just wasn't sure if the new code is stable enough. Maybe it should be done as part of separate PR (as in Cleanup having it's own, and this topic having it's own, unless it directly influences what you're doing with this topic then it can be in one PR - at least I think

For example all those empty if/else is left-over as well: https://github.com/EvotecIT/OfficeIMO/blob/fca5b6474c45492d3b09cb171c13fd2220db78a1/OfficeIMO.Word/WordSection.cs#L240C46-L253

I am just not sure if I am ready to start cleaning up, as I am just not 100% sure I understand WTH is going on with the code.

byteSamurai commented 1 year ago

Okay, I will not review the whole codebase, but if I spot a warning, which can be resolved with ease, I will do it then.

I admit, that I struggle at the moment to get a proper debugging session on my new Mac (debugger is not attaching itself to the session) C#-Coding seems to be more fun with VS or VScode on Windows πŸ˜…

byteSamurai commented 1 year ago

As commented in the comments, I faced some weird behavior while setting up this project locally. I hope you allow me to ask a few questions here:

PrzemyslawKlys commented 1 year ago

Hi,

image

It's actually very useful for PowerShell where with one LIB you are able to support both PS 5.1 and PS 7 which is the main reason I created this project.

As you can see in the project there are 3 systems tested on Azure Devops - linux, windows, macos. As long as we retain tests for all supported frameworks on all supported systems we can adjust the settings to be runnable on all systems as required. Maybe it just needs some IF/ELSE in the configuration settings depending on OS version.