To insert bullets and numbering in the word document use below code :
Numbering :
using DocumentFormat.OpenXml.Wordprocessing;
using DocumentFormat.OpenXml;
namespace GeneratedCode
{
public class GeneratedClass
{
public static Paragraph GenerateParagraph()
{
var element =
new Paragraph(
new ParagraphProperties(
new ParagraphStyleId(){ Val = "ListParagraph" },
new NumberingProperties(
new NumberingLevelReference(){ Val = 0 },
Type of bullet style-> new NumberingId(){ Val = 1 })),
new Run(
new Text("List 1"))//Text you want to insert with number
){ RsidParagraphAddition = "005F3962", RsidParagraphProperties = "00330DA9", RsidRunAdditionDefault = "00330DA9" };
return element;
}
}
}
Bullets:
using DocumentFormat.OpenXml.Wordprocessing;
using DocumentFormat.OpenXml;
namespace GeneratedCode
{
public class GeneratedClass
{
public static Paragraph GenerateParagraph()
{
var element =
new Paragraph(
new ParagraphProperties(
new ParagraphStyleId(){ Val = "ListParagraph" },
new NumberingProperties(
new NumberingLevelReference(){ Val = 0 },
Type of bullet style-> new NumberingId(){ Val = 2 })),
new Run(
new Text("P 2"))//Text tou want to insert with bullet
){ RsidParagraphAddition = "00031711", RsidParagraphProperties = "00031711", RsidRunAdditionDefault = "00031711" };
return element;
}
}
}
Also remember the styles.xml file to attached with document. How to it given in previous post.
I am trying to create a paragrapgh list with bullets but it always gets created as numbered list.I tried with both NumberingId(){ Val = 2 })) and NumberingId { Val = 1 }.
ReplyDeleteI also attached styles.xml.Any ideas?
Great example. I'm stuck trying to reset numbering in a list paragraph level. I imagine its using the LevelRestart class but I can't figure out how to apply it. Thanks for any help.
ReplyDelete