c# - How To Select The First line or (first 20 Characters) of a pragraph using Microsoft Office Interop word.? -
i have been trying following code first line or first 20 characters of paragraph using microsoft office interop word 12
microsoft.office.interop.word.application w = new microsoft.office.interop.word.application(); microsoft.office.interop.word.document doc; int iparastart = para.range.start; para.range.text = "a big paragraph comes here ……."; para = doc.paragraphs.add(); int iparaend = para.range.end; // select first sentance code tried doc.range(irangestart,irangeend).sentences.first.select(); doc.range(irangestart,irangeend).sentences.first.shading.backgroundpatterncolor=wdcolor.wdcolororange; // characters code tried doc.range(irangestart,irangestart+20).select();
it seems not working how can . need select either first sentence or first 20 characters
try using (i assumed have open application , word document):
// paragraph range paragraphs = doc.paragraphs; word.paragraph paragraph = paragraphs.first; word.range paragraphrange = paragraph.range;
selecting first sentence:
word.sentences sentences = paragraphrange.sentences; word.range firstsentence = sentences.first; firstsentence.select();
selecting first 20 characters:
if (paragraphrange.text.length > 20) { word.range range = paragraph.range.duplicate; range.setrange(range.start, range.start + 20); range.select(); }
Comments
Post a Comment