Get Font Properties From Word Document With OpenXML (.NET) - ms-word

How can I get font properties from word document with OpenXML?
var para = wordDocument.MainDocumentPart.RootElement.Descendants<Paragraph>().ToList();
With the code above, I can only get the paragraphs themselves.
Only font insertion shown in forum.
Please help me..

Although i don't really know, what 'font-properties' means in this context, my answer is: it depends.
styles (templates defining paragraph or run format, etc) are set in MainDocumentPart.StyleDefinitionsPart
formatting properties are defined in RunProperties or ParagraphProperties (applied styles can also be found here)
So if you like to retrieve certain formatting properties, you will have to look inside the openxml-package.

Related

Word add-in js getHtml() function not return all fully style

I write word add-in in JS using this API: https://dev.office.com/reference/add-ins/word/word-add-ins-reference-overview
When I use function body.getHtml() I get almost everything , but some style is missing ,for example table of content is not with style, and when I use body.insertHtml() all style of table of content is not exist.
I success to get all style with body.getOoxml() function but it's very very long when I compare it to the html and this is bug problem for me .
What could I do?
Thank you
The issue here is that when you create a TOC what really happens in the doc is that we insert a special type of content control wrapping the TOC and we don't roundtrip it in docx-html conversions. In fact, if you save your TOCed document as HTML you will see that the style is lost in the resulting html. FWIW the links on the resulting HTML are functional.
That said, your only option as of now is to go OOXML.
thx,
Juan.

HTML5 Custom Data Attributes in TYPO3 Backend Content Elements

I am wondering if there is a way to add a HTML5 Custom Data Attribute to any Content Element like Text or Text w/ images.
Anyone tried / did this before or is there a good reason not to do this?
You can either add a new field (own extension) or use any of the existing (e.g. layout to define own values. Then you can change the TypoScript rendering based on the value of this field.
... or in addition to #pgampe's answer, which is fine for programmers you can use ie. DCE extension, which allows you to create any HTML structure with usage pure Fluid syntax
Thank's for the answers. I didn't know DCE, looks very interesting.
As I needed a quick solution for just a few elements on one page I did something really quick and dirty. But as it worked for me, I would like to post it in addition to the two other excellent answers.
I used the field Description field to add the content of my custom field. I know it's not intended for this, but as alreay mentioned: quick & dirty. :-)
tt_content.stdWrap.innerWrap.cObject {
50 =< tt_content.stdWrap.innerWrap.cObject.default
50.20.10.value = csc-default layout-{field:layout}" data-filter="{field:rowDescription}
50.20.10.insertData = 1
}

Merging documents using OpenXml and section breaks causes empty paragraphs

I am stitching a couple of documents together with a requirement that each document should retain its header and footer information in the final document. Using AltChunk instead of raw OpenXml or DocumentBuilder saves a lot of effort with regards to styles, formatting, references, parts, etc.
Unfortunately, after a couple of days I can't seem to get a 100% working version due to a small and frustrating issue and I need some insight.
My code is loosly based on this article
I modify each sub document, prior to appending it (as an AltChunk) to a working document, by moving the last section properties into the last paragraph (in order to retain header and footer references), but Word seems to be adding a blank paragraph to each of these documents as it renders them in the final document. I end up with:
document 1 with correct header and footer
section properties/break
blank paragraph
document 2 with correct header and footer
section properties/break
blank paragraph
etc.
I cant remove the blank paragraphs afterwards, as I ideally don't want to use WAS to render the document first.
It seems as if you cannot have a next-page section break without a following paragraph?
After further investigation, it seems that will not be away around my usage scenario. I would need to place the last section properties in the body element, but due to my way of processing with nested AltChunk, it would not work.
I have changed my approach completely and went back to a more detailed append procedure using OpenXml Power Tools and some LINQ to Xml.
I'm using Document Builder and works perfectly for me!
var sources = new List<OpenXmlPowerTools.Source>();
sources.Add(new OpenXmlPowerTools.Source(new WmlDocument(#tempReportPart1)));
sources.Add(new OpenXmlPowerTools.Source(new WmlDocument(#tempReportPart2)));
var outputPath = #"C:\Users\xpto\Documents\TestFolder\myNewDocument.docx";
DocumentBuilder.BuildDocument(sources, outputPath);
I have the similar empty paragraph issue while importing HTML files.
My solution is,
After inserting HTML AltChunk, I add a GUID place holder. After processing the file, I will open the file again, locate the GUID and check if there is a empty paragraph before it, if so remove the empty paragraph and GUID. it seems work perfectly in my solution.
Hope it helps.

Three lines of code look the same and only one works. Why?

I have some GWT code here. I am trying to change the background color of a widget:
this.getElement().setAttribute("backgroundColor", backgroundColor);
this.getElement().setPropertyString("backgroundColor", backgroundColor);
this.getElement().getStyle().setProperty("backgroundColor", backgroundColor);
Usually in code I can tell by the name of the function what the code does... but in this case all three lines of code looks the same and "read the same"! (Reading the javadoc did not help either.I went to the javadoc because that usually helps me understand what code does. The javadoc did not help.)
My question to you is: Please explain what is the differences between these three lines of code (for instance why do you need to call getStyle())? Why does the last line work?
this.getElement().getStyle().setProperty("backgroundColor", backgroundColor);
is the only line that access the actual style information, properties and attributes manipulate the element directly and don't have anything to do with the Style that is associated with an element.
And just as an addition, you should really be using a style sheet and changing the style instead of setting inline this way.
It is the difference between
<tag backgroundColor="#f0f0f0">
and
<tag style="background-color:#f0f0f0">
This is somewhat of an educated guess...
Line 1 you are accessing the element's attributes not the styling attributes.
Line 2 would access properties on the element not the styling.
Line 3 actually gets the styling properties and then changes them accordingly.

Write a Word 2007 document in OpenXML

My problem is in two parts:
How can I, in Word 2007, put an id on a section so I can easy access this section from my code? For example, if I have Name : Here I want to set the name from my C# code.
How can I, from my C# code, fill this section id ?
The best way is to use Content Controls in Word (and the Content Control Toolkit). There are tons of examples out there, like:
http://coolthingoftheday.blogspot.com/2006/11/open-xmlword-2007-content-control.html
http://www.vsj.co.uk/articles/display.asp?id=657
http://www.craigmurphy.com/blog/?p=913