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

Ability to preserve formatting for CustomProperty value. #357

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

EduardBlees
Copy link

Issue:
Formatting in CustomProperty.Value wasn't preserved, because it's added as string value to xElement.

PR:
Parameter withFormatting to Xceed.Document.NET.Document.UpdateCustomPropertyValue method. When true, CustomProperty.Value is formatted using HelperFunctions.FormatInput.

@XceedBoucherS
Copy link
Collaborator

Hi EduardBlees,
I can understand your point to format custom properties, but based on the sample you provided, it doesn't seems necessary to do the formatting.
From v1.6, I was able to add the same custom property as you without formatting:

document.AddCustomProperty( new CustomProperty( "Formatted", $"First Line{Environment.NewLine}Second Line{Environment.NewLine}Third Line" ) );

Then displaying all the custom properties of the document with:
// Display each propertie's name and value. foreach( var prop in document.CustomProperties ) { document.InsertParagraph( prop.Value.Name ).Append( " = " ).Append( prop.Value.Value.ToString() ).AppendLine(); }

showed the "Formatted" property value with the "\n" displayed in 3 lines.
I'm I missing something ?

Thank you

@EduardBlees
Copy link
Author

My bad, missed important detail in issue description - I already have a document that has some custom property, which value is inserted in a lot of places throughout the document. So, by calling AddCustomProperty with the same CustomProperty Name, I'm just updating its value, and Xceed.Document.NET.Document.UpdateCustomPropertyValue updating all insertions.

In this scenario, it's very handy to have ability to preserve formatting in Xceed.Document.NET.Document.UpdateCustomPropertyValue.

@XceedBoucherS
Copy link
Collaborator

Hi,
Yes, the existing custom properties will be updated with a call to AddCustomPoperty() with the same Custom PropertyName, but what kind of formatting are you expecting. Can you provide an example of formatted value to pass to the AddCustomProperty() ?
Currently you suggested some {Environment.NewLine} which doesn't seem to need a Formatting.
Could you provide a complete sample please ?
Thank you.

@EduardBlees
Copy link
Author

Hi,
I provided an example: https://github.com/EduardBlees/DocX/tree/formatting_example
Problem is, {Environment.NewLine} needs formatting, when updating property value throughout the document.

In example branch you can find DocumentSample.FormattedCustomProperties example.
Run it, you should be able to reproduce this.
In /Samples/Document/Output you will find two documents - formatting_test.docx and formatting_test2.docx. It's just copies of the same document.
Each document has CustomProperty named FormatProperty, with value "Initial value", inserted in document 5 times.
DocumentSample.FormattedCustomProperties runs AddCustomProperty without flag on first document, and runs AddCustomProperty with flag on second document.
You can see my results here: https://github.com/EduardBlees/DocX/tree/formatting_example/Xceed.Words.NET.Examples/Samples/Document/screenshots

@XceedBoucherS
Copy link
Collaborator

Hi,

Thank you for you clear explanation.

I will use your idea, but modify it to make all CustomProperties formattable.
In v1.8, your issue will be fixed by default (without any bool parameter) and you will have the possibility to format (with a Formatting object) any CustomProperty value.

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

Successfully merging this pull request may close these issues.

2 participants