Solved

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

Posted on 2009-04-05
3
8,913 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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

749 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