Comments (23)
Huh? What do you mean?
from officeimo.
See here a sample in Word:
WeirdTextBox.mp4
from officeimo.
$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.
Maybe defaults couldd be changed.
from officeimo.
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.
You need to change Position of it and to what it's relative to? Maybe the defaults are relative to Paragraph?
from officeimo.
$varValue = $Document.AddTextbox("Text"); $varValue.WordParagraph.Text =" ChangeText" $varvalue.WordParagraph.Color = xxxI 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.
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.
It can be on the page, but $varValue has PositionRelativeTo or similar property which you can change.
from officeimo.
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.
how would you make it stick when doing it manually?
from officeimo.
It seems my understanding of Word is wrong. I thought this should do the trick:
Basically bring the TextBox "In front of the text" so that it is independent of the normal text flow.
from officeimo.
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.
In my code it has wraptopbottom
So this would need additional get/set logic to look for those "Wrap" types and add them or remove them on demand.
from officeimo.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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)
- InvalidProgramException HOT 5
- Open Office Writer can't open document created with OfficeIMO HOT 17
- Add Combo Chart HOT 1
- Upgrading DocumentFormat.OpenXML to version 3 HOT 1
- dotnet 8.0 error HOT 13
- Any way to implement numbered list (a., b., c., ....)? HOT 4
- Setting font size for list symbol HOT 7
- Any way to insert rich text HTML content? HOT 8
- Remove continue numbering & restart numbering for lists
- Add ability to merge & remove lists
- Image layout options HOT 8
- Mislabeled Behavior? HOT 8
- Potential Bug: Does iteration over TableCell's Paragraphs property allow mutation? HOT 21
- Stable and unlikely to change vs unstable and subject to change vs depreciated api HOT 13
- How to add paragraph without pagebreak? HOT 4
- ContentControls.Add() is trimming space from user selection HOT 1
- How to display the specific gravity value in a pie chart HOT 2
- How to add image watermark? HOT 3
- how can I add a table with two rows and each row had diff columns and width? HOT 1
- Issue with Text Replacement in Multi-Line Text Boxes HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from officeimo.