Solved

How do I insert and remove bullet points using C# with Word

Posted on 2009-04-05
3
9,014 Views
Last Modified: 2012-05-06
Hi,
I am using C# to automatically populate text in a Word Document. I need a certain paragraph to have bullet points but the next paragraph revert to normal text. I can insert the bullet points but cannot remove them. I am using the following code:


 Object oTrue = true;
 Object oFalse = false;
 Object oTemplatePath = @"C:\SampleTemplate.dotx";
Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document oDoc = new Microsoft.Office.Interop.Word.Document();
Microsoft.Office.Interop.Word.Paragraph oPara1;

oWord.Visible = true;
oDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);
oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing);

oPara1.Range.ParagraphFormat.LeftIndent = -1;
oPara1.Range.ListFormat.ApplyBulletDefault(ref oMissing);
oPara1.Range.Text = "Sample Text that has a preceding bullet point";

oPara1.Range.InsertParagraphAfter();

//Here I need to remove the bullet point on the next paragraph


Any help would be greatly appreciated.

Thanks
David
0
Comment
Question by:dvscie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 7

Accepted Solution

by:
DanSo1 earned 250 total points
ID: 24076895
Hi
You can use RemoveNumbers method:

oPara1.Range.ListFormat.RemoveNumbers(ref oNumberType);

oNumberType is wdNumberParagraph

Regards
  Danso

0
 
LVL 23

Expert Comment

by:irudyk
ID: 24076957
Try the following:
oPara1.Range.InsertParagraphAfter();

//Here I need to remove the bullet point on the next paragraph

oPara1.Range.ListFormat.RemoveNumbers();
0
 

Author Closing Comment

by:dvscie
ID: 31566854
Thank you for your solution - it was very much appreciated and resolved my problem!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question