Closed TopperDEL closed 6 months ago
Well, how would you do it manually in Word to achieve what you want?
Both of that you can do. But maybe you are thinking on something else?
In Word I would create a TextField:
And then I would place it at a specific location:
(Sorry, my Word is german, but I hope you recognize it).
Could this be added?
I'm not sure if a Table would do it, as I need multiple TextFields in e.g. the top region of a page - think of Sender-Address, Receiver-Address, Communication Info etc.
The basic problem is: those text fields need to be separate from the "normal" text run. They have to be at a specific location and should not interfere with the rest of the text.
Looks like TextBox is drawing with anchor
Relative to a page
It's doable, but we need to add new type and all the properties to change different things. Alternate Content Fallback may be harder to do. But we will see.
Is there anything where I can help? Unfortunately I have no clue what needs to be done - but this feature is critical for my app-idea, so I would be very happy to have this included.
Let me know if/how I may help!
This looks similar to how you manage Images. So I will use WordImage type as a starting point and will have to create new type WordTextbox type or something similar. Hopefully it will be enough.
We will see from there.
Awesome!
The project I'm working on should get to the market next year. As soon as I earn something with it I will give back to the projects I'm stacking on top like yours is!
Cool :-) Lets see how that WordTextBox goes first
I got this thing working
internal static void Example_AddingTextbox2(string folderPath, bool openWord) {
Console.WriteLine("[*] Creating standard document with some textbox");
var filePath = System.IO.Path.Combine(folderPath, "BasicDocumentWithTextBox3.docx");
using (WordDocument document = WordDocument.Create(filePath)) {
var paragraph = document.AddParagraph("Adding paragraph with some text");
var textBox = document.AddTextBox("My textbox on the left");
textBox.HorizontalPositionRelativeFrom = HorizontalRelativePositionValues.Page;
// horizontal alignment overwrites the horizontal position offset so only one will work
textBox.HorizontalAlignment = HorizontalAlignmentValues.Left;
textBox.VerticalPositionOffsetCentimeters = 3;
var textBox2 = document.AddTextBox("My textbox on the right");
textBox2.HorizontalPositionRelativeFrom = HorizontalRelativePositionValues.Page;
textBox2.WordParagraph.ParagraphAlignment = JustificationValues.Right;
// horizontal alignment overwrites the horizontal position offset so only one will work
textBox2.HorizontalAlignment = HorizontalAlignmentValues.Right;
textBox2.VerticalPositionOffsetCentimeters = 3;
Console.WriteLine(textBox.VerticalPositionOffsetCentimeters);
Console.WriteLine(document.TextBoxes[0].VerticalPositionOffsetCentimeters);
Console.WriteLine(document.TextBoxes[1].VerticalPositionOffsetCentimeters);
document.Save(openWord);
}
}
But need to add some tests and probably there will be things that are going to need improvements. Maybe add some styles that are available in Word. Also the object is very complicated so I am not sure if it will survive testing on real world documents created by other people.
Looks awesome! Exactly what I need! Would love to test this out!
There is PR linked to this issue. You can play with it
Oh right! Was on my mobile phone and did not realize it. Will try asap!
As mentioned in the PR: it works and is exactly what I need! Would love to see it merged. :) Thank you!
Well that was an easy part. Now the "tests" needs to be done which is less than exciting ;p
Thank you for this awesome project!
I have a question: can I place Text or a "TextBlock" at a specific location e.g. "2cm from the right border and 3cm from the top border"? I need to place Adress data and such at exact locations.