Free Support Forum - aspose.com

Remove left indent of a List

Hi,

In Microsoft Word, if adding a list in a document, left indent is added automatically. Manually, we can change the margin of the paragraph to fix this problem.

Is there a way or any function I can use in Aspose.Word to change the margin of a particular paragraph or a list?


Thanks

Hi Hong-Yi,

Thanks for your inquiry. Please use ParagraphFormat.LeftIndent property to set the value (in points) that represents the left indent for paragraph.

Document doc = new Document(MyDir + "list.docx");

foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))

{

if (para.IsListItem)

para.ParagraphFormat.LeftIndent = 0.0;

}

doc.Save(MyDir + "out.docx");


Hope this answers your query. If this does not help you, please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate as to how you want your final Word output be generated like. We will then provide you more information on this along with code.


Hi Tahir Manzoor,

Thank you for your reply. Your answer was really helpful. Just an additional question. Do we have control over hanging indent and left tab when creating word document?

I’ve attached 3 files which are the template I used, the document generated by my application and the ideal outcome I want.

Please also have a look the code.

--------------------------------------------------------------------------------------------
Document docTemplate = new Document(‘aspose_test.dot’);
DocumentBuilder db = new DocumentBuilder(docTemplate);

db.MoveToBookmark(“TCyourinformationU1”);
db.InsertHtml(@“

  1. Aspose.Words List Item Indent TestAspose.Words List Item Indent TestAspose.Words List Item Indent TestAspose.Words List Item Indent TestAspose.Words List Item Indent Test

  2. Aspose.Words List Item Indent TestAspose.Words List Item Indent TestAspose.Words List Item Indent TestAspose.Words List Item Indent TestAspose.Words List Item Indent Test

  3. Aspose.Words List Item Indent TestAspose.Words List Item Indent TestAspose.Words List Item Indent TestAspose.Words List Item Indent TestAspose.Words List Item Indent TestAspose.Words List Item Indent Test

  4. Aspose.Words List Item Indent TestAspose.Words List Item Indent TestAspose.Words List Item Indent TestAspose.Words List Item Indent TestAspose.Words List Item Indent Test
”);

foreach (Paragraph para in docTemplate.GetChildNodes(NodeType.Paragraph, true))
{

if (para.IsListItem)
{
para.ParagraphFormat.FirstLineIndent = 0.0;
para.ParagraphFormat.LeftIndent = 0.0;
}
}

docTemplate.Save(open_template.InitialDirectory+"\test.doc", SaveFormat.Doc);

-----------------------------------------------------------------------------------------------------------

Your help is really appreciated.


Hi Hong-Yi,


Thanks for sharing the details. Please note that ParagraphFormat.FirstLineIndent property gets/sets the value (in points) for a first line or hanging indent.

Use a positive value to set a first-line indent, and use a negative value to set a hanging indent. Moreover, you also need to add TabStops to achieve your required output.

Please use the following code snippet to achieve your required output. Hope this helps you. Please let us know if you have any more queries.

<span style=“font-size:
10.0pt;font-family:“Courier New”;color:#2B91AF;mso-no-proof:yes”>Document<span style=“font-size:10.0pt;font-family:“Courier New”;mso-no-proof:yes”> doc = new Document(MyDir

  • “aspose_list_indent_test.dot”);<o:p></o:p>

DocumentBuilder db = new DocumentBuilder(doc);

db.MoveToBookmark("TCyourinformationU1");

db.InsertHtml(@"

  1. Aspose.Words List Item Indent TestAspose.Words List Item Indent TestAspose.Words List Item Indent TestAspose.Words List Item Indent TestAspose.Words List Item Indent Test

  • Aspose.Words List Item Indent TestAspose.Words List Item Indent TestAspose.Words List Item Indent TestAspose.Words List Item Indent TestAspose.Words List Item Indent Test
  • Aspose.Words List Item Indent TestAspose.Words List Item Indent TestAspose.Words List Item Indent TestAspose.Words List Item Indent TestAspose.Words List Item Indent TestAspose.Words List Item Indent Test
  • Aspose.Words List Item Indent TestAspose.Words List Item Indent TestAspose.Words List Item Indent TestAspose.Words List Item Indent TestAspose.Words List Item Indent Test
  • ");

    foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))

    {

    if (para.IsListItem)

    {

    para.ParagraphFormat.FirstLineIndent = 10.0;

    para.ParagraphFormat.FirstLineIndent = -10.0;

    para.ParagraphFormat.LeftIndent = 10.0;

    double tabStop = 10;

    para.ParagraphFormat.TabStops.Add(new TabStop(tabStop, Aspose.Words.TabAlignment.Left, TabLeader.Dots));

    }

    }

    doc.Save(MyDir + "out.doc");