Code Monkey home page Code Monkey logo

Comments (23)

PrzemyslawKlys avatar PrzemyslawKlys commented on May 25, 2024

Huh? What do you mean?

from officeimo.

TopperDEL avatar TopperDEL commented on May 25, 2024

See here a sample in Word:

WeirdTextBox.mp4

from officeimo.

PrzemyslawKlys avatar PrzemyslawKlys commented on May 25, 2024
$varValue = $Document.AddTextbox("Text");
$varValue.WordParagraph.Text =" ChangeText"
$varvalue.WordParagraph.Color = xxx

I am not sure I understand, but Textbox has WordParagraph linked to it and it's responsisble how those colors/data looks like.

from officeimo.

PrzemyslawKlys avatar PrzemyslawKlys commented on May 25, 2024

Maybe defaults couldd be changed.

from officeimo.

TopperDEL avatar TopperDEL commented on May 25, 2024

See here how the TextBox "gets pushed" to the end of the document if the flowting text before it gets larger.

WeirdTextBox2.mp4

from officeimo.

PrzemyslawKlys avatar PrzemyslawKlys commented on May 25, 2024

You need to change Position of it and to what it's relative to? Maybe the defaults are relative to Paragraph?

from officeimo.

TopperDEL avatar TopperDEL commented on May 25, 2024
$varValue = $Document.AddTextbox("Text");
$varValue.WordParagraph.Text =" ChangeText"
$varvalue.WordParagraph.Color = xxx

I am not sure I understand, but Textbox has WordParagraph linked to it and it's responsisble how those colors/data looks like.

Maybe word recognizes somethin special within? On right click on the blue text it lets me "Remove content control" ("Inhaltssteuerelement entfernen" in german).

from officeimo.

TopperDEL avatar TopperDEL commented on May 25, 2024

You need to change Position of it and to what it's relative to? Maybe the defaults are relative to Paragraph?

So maybe I should add the TextBox on a "Section" or the page itself instead?

from officeimo.

PrzemyslawKlys avatar PrzemyslawKlys commented on May 25, 2024

It can be on the page, but $varValue has PositionRelativeTo or similar property which you can change.

from officeimo.

TopperDEL avatar TopperDEL commented on May 25, 2024

Hm, this is my code:

var textBox = document.AddTextBox(partText);
textBox.RelativeWidthPercentage = 0;
textBox.RelativeHeightPercentage = 0;
textBox.HeightCentimeters = part.Height / 10;
textBox.WidthCentimeters = part.Width / 10;
textBox.HorizontalPositionRelativeFrom = DocumentFormat.OpenXml.Drawing.Wordprocessing.HorizontalRelativePositionValues.Page;
textBox.VerticalPositionRelativeFrom = DocumentFormat.OpenXml.Drawing.Wordprocessing.VerticalRelativePositionValues.Page;
textBox.HorizonalPositionOffsetCentimeters = part.Left / 10;
textBox.VerticalPositionOffsetCentimeters = part.Top / 10;

The TextBox still is being moved when the floating text gets larger.

from officeimo.

PrzemyslawKlys avatar PrzemyslawKlys commented on May 25, 2024

how would you make it stick when doing it manually?

from officeimo.

TopperDEL avatar TopperDEL commented on May 25, 2024

It seems my understanding of Word is wrong. I thought this should do the trick:

image

Basically bring the TextBox "In front of the text" so that it is independent of the normal text flow.

from officeimo.

PrzemyslawKlys avatar PrzemyslawKlys commented on May 25, 2024

ye, so this WordTextBox needs extension for that. I believe it's hardcoded to single value. Unfortunetly I won't have time for a week to take a look at it.

From what I see when you change it to vor den text it actually adds WrapNone to anchor.

image

In my code it has wraptopbottom

image

So this would need additional get/set logic to look for those "Wrap" types and add them or remove them on demand.

from officeimo.

TopperDEL avatar TopperDEL commented on May 25, 2024

I'm still trying to accomplish what I need with word itself. It is not that trivial as it seems. Basically I want to place some text in the first page only and at specific locations. Maybe I first need to add the floating text and afterwards add my fixed textboxes to the first page?
I'm confused.

Don't worry about your timeframe! There is not immediate need to adjust anything. Thank you, though!

from officeimo.

PrzemyslawKlys avatar PrzemyslawKlys commented on May 25, 2024

Maybe Relative to margin, rather than to page? Dunno, try in Word itself and once you have that ready you can see how the code looks like in Open XML SDK 2.5 Productivity Tool and see what's missing.

from officeimo.

TopperDEL avatar TopperDEL commented on May 25, 2024

Ok, I've sorted a bit. Where I was wrong: I have to anchor or add the textboxes within the header/footer. Then they are at a specific location on a page.
I still have the issue with the TextBox-Text being some kind of "variable" within word (rendered as blue text). But I will tackle this later. And come back to here.

from officeimo.

TopperDEL avatar TopperDEL commented on May 25, 2024

Back at work. :)
So, I need to add a TextBox to the Header and Footer. But those do not have corresponding AddTextBox()-Methods. Would ypu be able to add them without much effort? I still do not quite understand how your library works internally - I hope that I can help you out adding features like this.

from officeimo.

PrzemyslawKlys avatar PrzemyslawKlys commented on May 25, 2024

It should be fairly easy to add, mostly copy paste. As the textbox attaches between paragraphs so mostly similar to other Add commands. I will be back at work next week. If you figure it out..., if not i'll fix it

from officeimo.

TopperDEL avatar TopperDEL commented on May 25, 2024

Just tried a bit but was unsuccessfull. I am confused with the types you have (like WordParagraph) and the types from the OpenXml-library (like Paragraph). I can create a TextBox and a TextBoxContent and add it to your WordDocument - but it does not Show up. I think I need to add my "self created" paragraph to an internal list of your paragraphs?
Will check again tomorrow.

from officeimo.

PrzemyslawKlys avatar PrzemyslawKlys commented on May 25, 2024

I've made a simple PR showing this functionality. I don't have proper internet/my workstation to work on this, but it does add it to header/footer and you should be able to play with it there (linked to this issue)

from officeimo.

TopperDEL avatar TopperDEL commented on May 25, 2024

You're awesom! That PR helped alot and I now have a much better understanding of how everything works. I've added some features I needed along the way.

What still confuses me a bit is how you wrap the underlying OpenXML-classes. E.g. if you look at my PR #188 - I've added a feature to add multiple runs and breaks from the text provided. But this is just a quick workaround. You have a similar logic in WordParagraph.PrivateMethos.cs on a WordParagraph. But I cannot use it here because the WordParagraph on a WordTextBox is just a "on-the-fly"-wrapper around the first run of the textbox. Maybe I'm still missing something - but it is not always clear when you have an own class for something and when you use the OpenXML-types.
E.g. my new TextBodyProperties-Property on WordTextBox feels wrong as it gives access to the underlying OpenXML-Type. Should I add dedicated properties for that? But wouldn't that make it just more complex to add every single propertie of every part of all elements?

from officeimo.

PrzemyslawKlys avatar PrzemyslawKlys commented on May 25, 2024

To be honest I do it on my best guess. I use openxml types if it's pretty clear conversion, but when for example wrap/nowrap/and few other options means you need to add internally few other things I would go create something internal.

For your specific use case I guess it would make sense to create multiple properties as long as those make sense in exposing them. I usually expose those that I use, but when you use multiple others ...

Also I believe expanding AddTextbox method with other properties makes sense like position, and other settings that usually means you need to change them anyways.

I'm experimenting as I go ;)

from officeimo.

PrzemyslawKlys avatar PrzemyslawKlys commented on May 25, 2024

Keep in mind that NoWrap or Wrap are just one of X number of options available (as per your screenshot). So this can't be a bool, but more likely an enum that causes different code changes. Take a look at WordImage. I believe it has similar code in this regards.

from officeimo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.