-
Notifications
You must be signed in to change notification settings - Fork 473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HeadingType is not applied when using Load() #245
Comments
Hi, We cannot reproduce this in v1.2.
Are we missing anything ? |
Yes. I use $Paragraph.StyleName = $HeadingType instead of the way you do. I guess I'll switch to your approach if it works. So in C# it would be
More or less. And what I actually do in code is
|
And maybe I'm using it wrong but I don't see... Heading property for Paragraph But I do see it in examples
So I'll verify why I don't see it. Anyways I use it via StyleName instead of Heading property. |
If you want to use it your way, you should use it this way : `var doc = DocX.Load( "WordTemplate.docx" );
Paragraph only contains a StyleName property, which is a string. It doesn't contain a Heading property. |
In c#
Notice how it's not set And Create
Diffence is just Create vs Load. |
And your code doesn't give better results either:
Headings are not set. |
Hello, When creating a document, the style used will be the the default styles (including Heading1, Heading2...), but when loading a document, its defined styles will be used. We will investigate on this. |
Hello |
I worked around it by creating empty doc, saving and then adding my flavors making it my template. Works |
Hi @PrzemyslawKlys , i'm experiencing the same issue and would be very helpful if you can be more detailed on your solution proposal. Thanks in advance |
Just create an empty doc with DocX and work from there. It will have proper format that is required. |
@PrzemyslawKlys I tried, but if i make some change on it using Office like edit the header it keep doing the same. I have to put a logo just like u show on your screenshots, but i cant find a way to put an image as a header using DocX |
What I did is exactly as I said:
|
Thanks for your replay, i followed your suggestion but i changed the editor for the Doc Drive downloading as a .docx and it worked perfectly. I found that if you save in latest version of Word it changes the schemas from 2006 to 2015 or later in the "document.xml" and i think that's the problem, because trying with other editors they use http://schemas.openxmlformats.org/markup-compatibility/2006 |
Hello everybody, |
After some investigations, the property "Stylename" is a little bit confusing. It should be "Styleid", the element name in the schema is not the same thing for a style. In my point of view, the easiest way could be to retrieve styles by alias and to apply the retrieved style id on a property named "Styleid" |
Hi mastertnt, |
Hi, Thanks for the answer. If you use StyleId, the Load function has no trouble. The difficulty is to know the correct StyleId (the aliases displayed in Word seems more natural) or i don't the way to retrieve it from the API. Regards, |
Hi, |
Hi, Thanks for the precision, i have already seen this. I use a french template and also all the special characters present in Latin1 character set are removed for example, "Référence" will have styleId "Rfrence". For other languages (like chinese), i don't know if it is possible to infer the styleId. Regards, |
Hi, For Heading types, you can always use the Paragraph.Heading() method, which take in parameter a HeadingType. Therefor, you don't have to use the styleId, at least for the heading types. In v1.8, you will also have access to a static method in Document called "GetParagraphStyleIdFromStyleName" which will take in argument a styleName and return the corresponding styleId. |
While below code is powershell it uses your .NET. Essentially when you use .Load(Path) and apply HeaderStyle it's not saved in final document making TOC useless. It behaves as expected on .Create(Path)
To reproduce it in pseudo code
When checking:
Document.Paragraphs.StyleName
So comparison is almost identical but still save doesn't cover this. Replacing Load with Create - everything works again. I'm using https://github.com/EvotecIT/PSWriteWord/blob/master/Examples/Templates/WordTemplate.docx as a template but shouldn't really matter I guess.
The text was updated successfully, but these errors were encountered: