C# Word OpenXml SDK - Adding text to a run trims spaces - ms-word

I'm trying to add text runs to an existing paragraph in Word using the OpenXml SDK, but every time I do this it ends up "trimming" the text which I add.
For example
Run newRun = newRun();
newRun.AppendChild(new Text("Hello "));
paragraph.AppendChild(newRun);
Run newRun = newRun();
newRun.AppendChild(new Text(" World"));
paragraph.AppendChild(newRun);
// the resulting paragraph contains "HelloWorld" as the text
I've also checked the XML of the resulting Run which gets generated, which clearly includes the "space" character:
<w:t xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\">Hello </w:t>
I've tried injecting '\u0020' unicode values, as well as an "empty" run which just contains a single space, but nothing seems to work.
Does anyone know the trick to this?

Rolling my eyes at how typical that I find the answer 5 minutes after posting (having been trying for hours)
The answer is to add the XML xml:space="preserve" attribute to the Text element, otherwise spaces are trimmed.
newRun.InnerXml = $"<w:t xml:space=\"preserve\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\">{text}</w:t>";

Related

WKInterfaceLabel ignoring \n indicators

I'm getting text from the MediaWiki API, and it includes getting \n text which indicates a new line. When I set the API results as the text of a WKInterfaceLabel, the \n's disappears, but no new line is created.
Any way to fix it?
Example. From this term:
[...] forms.\n\n==Use in writing systems==\n\n===English===\nIn Modern English [[English orthography|spelling]], {{angbr|i}} represents several different sounds, either the diphthong {{IPAc-en|aɪ}} ("long" {{angbr|i}}) as in ''kite'', the short [...]
It's meant to remove the \n's and replace it with new lines. What's added to the label is this text minus the \n's, but no new lines.

Monaco editor: Replace short text with longer text

I want to use the additionalTextEdits of the autocomplete callback to replace some text.
In some cases, I want to replace a short text with a longer text and expect everything after the short text to get pushed further back.
Example:
Original: abde
Text to insert: ABC, startColumn: 1, endColumn: 3
Expected outcome: ABCde
Actual outcome: ABde
My suspicion is that the editor sees that I want to replace two characters and therefore only takes the first two characters of my provided text.
Is there a way to tell it to replace those two characters with the provided three characters and everything afterwards gets pushed one column back?
Here is the link to the documentation of the property that I use:
https://microsoft.github.io/monaco-editor/api/interfaces/monaco.languages.CompletionItem.html#additionalTextEdits

Aspose.Words - Format a single word in a paragraph

I'm new to Aspose.Words for .Net, and working on recreating some documents for a customer. I need to make a single word in a paragraph bold and underlined. I'm trying to achieve this by creating separate paragraph runs for the text before the bold word, the bold word itself, and the text after. Then I'm formatting the bold word's run and appending everything to the paragraph. This seems overly complicated. Is there a simple way to achieve this from within DocumentBuilder.WriteLn("some text")?
I kept working at it, and achieved the desired result by using DocumentBuilder.Write() instead of DocumentBuilder.Writeln():
builder.Write("The start of the paragraph ");
builder.Font.Bold = true;
builder.Font.Underline = Underline.Single;
builder.Write("underlined bolded text");
builder.Font.Bold = false;
builder.Font.Underline = Underline.None;
builder.Write(" the end of the paragraph.");

How to increase visual length of form text field in Word?

When a form text field is inserted in a Word document, the grey shaded length is about 5 characters long. How can this length be increased?
Allthough it is a rather crude measure (and I don't recommend it), you can set "Properties -> Default Text" to as many blanks as you want the size. But this comes for a price: as long as you move into the field by pressing TAB, all blanks are selected and get typed over. When you use the mouse, you click the cursor anywhere into the field and start typing ... so your entry might be pre and post fixed by a number of blanks that you have to trim away in e.g. an exit macro.
I recommend old form fields as the last resort (i.e. there must be a good reason to use them) and would prefer (in that order)
native Word2010/2007 fields (text or Rich text - perhaps not backwords compatible)
legacy ActiveX fields (compatible with W2003)
Legacy (old) form fields

tinymce removes extra spaces

I have a text area tinymce file that removes extra spaces and I don't want that.
For example if in the text area if I put hello, 5 spaces, bye, and when I save the file and view it again, 4 spaces are deleted and I see hello bye. (4 extra spaces are deleted)
Sorry if I sound not too informed about this, but I just wonder if this is a default feature or if there is an easy way to turn off this feature. (I do not want the extra spaces to be deleted.)
Thanks,
The issue here is that modern browsers will not display several spaces - but will show them as one single space. The solution here is to replace every second space with a " " before the content gets into the editor (best is to replace them on serverside). This way the browser will show all the spaces.