- Home
- Forum
- ASP.NET Core - EJ 2
- FirstLineIndent modify LeftIndent when I set negative values
FirstLineIndent modify LeftIndent when I set negative values
Hello,
I am wokring creating a word document and when I tried use FirstLineIndent with negative values (to set hanging) this also modify the LeftIndent value with the negative value. How I can set hanging in a paragraph and keep the value in Left Ident?
Hi Juan,
We have reproduced the reported problem “LeftIndent
is changed while setting negative value for FirstLineIndent in a Word document”
in our end. We will validate this issue and update you with more details by mid
of this week.
Regards,
Sneha.
Juan,
Upon further analysis, we have found that the hanging indent and left indent
are interrelated at the file level when a hanging indent is set for a paragraph
in a Word document.
As per DocIO behavior, if we set the hanging indent, we write the hanging
indent and left indent as they are in the Word document at the file level.
However, Microsoft Word automatically calculates the left indent value based on
the hanging indent value and shows in UI. This is the hanging indentation
behavior of Microsoft Word.
|
UI level |
File level |
|
|
|
To achieve your requirement of setting a hanging indent for a
paragraph, we suggest setting the hanging indent along with the required left
indent value using the custom method provided below. This custom method sets
the given hanging indent value and converts the left indent value based on the
hanging indent value.
Please refer to the code snippet below for setting the hanging indent along
with the left indent of the paragraph.
|
WordDocument document = new WordDocument(); document.EnsureMinimal(); document.LastParagraph.AppendText("Hello"); WParagraph nextPara = document.LastSection.AddParagraph() as WParagraph; nextPara.AppendText("World"); //Set the hanging and left indent for the paragraph. //If need left indent, set required left indent otherwise set 0f. SetHangingAndLeftindent(nextPara.ParagraphFormat, -10f, 0f); document.Save(@"Output.docx"); document.Close(); /// <summary> /// Set the hanging and left indent for the paragraph. /// </summary> /// <param name="paragraphFormat">The paragraph format.</param> /// <param name="hangingIndent">The hanging indent UI value.</param> /// <param name="leftIndent">The left indent UI value.</param> private static void SetHangingAndLeftindent(WParagraphFormat paragraphFormat, float hangingIndent, float leftIndent) { paragraphFormat.FirstLineIndent = hangingIndent; if (paragraphFormat.FirstLineIndent < 0) { paragraphFormat.LeftIndent = leftIndent + (-1 * paragraphFormat.FirstLineIndent); } else paragraphFormat.LeftIndent = leftIndent; } |
Regards,
Suriya Balamurugan.
Hi Suriya,
Its works very good, Thanks for the support!
I think this method will be included in the documentation for reference in the future.
Juan, we are glad to know that it worked, and we have planned to document your requirement in our user guide.