Table Convert To Text method C# WPF? -
i have richtextbox
in rtf format. user can paste in tables. want take functionality away i.e strip tables rtf on paste.
i need keep richtextbox
in rtf need keep bullets, numbered lists etc. can't paste in plain text.
i'm locking down formatting of pasted text works can't find methods remove tables...
private void _btnformat_click(object sender, routedeventargs e) { textrange rangeoftext = new textrange(richtextboxarticlebody.document.contentstart, richtextboxarticlebody.document.contentend); rangeoftext.applypropertyvalue(textelement.foregroundproperty, brushes.black); rangeoftext.applypropertyvalue(textelement.fontsizeproperty, "12"); rangeoftext.applypropertyvalue(textelement.fontfamilyproperty, "arial"); rangeoftext.applypropertyvalue(textelement.fontstyleproperty, "normal"); rangeoftext.applypropertyvalue(inline.textdecorationsproperty, null); }
iterating on rtf & removing tags looks complex each paste different. noticed in word there's table converttotext
functionality need.
does know if there's method in .net can achieve this? thanks
ok, if trying achieve don't think it's possible. maybe can iterate on simple table in rtf string , remove tags if can't determine user input rtf far complex. therefore here's solution (of sorts...)
private void _btnformat_click(object sender, routedeventargs e) { textrange rangeoftext = new textrange(richtextboxarticlebody.document.contentstart, richtextboxarticlebody.document.contentend); rangeoftext.applypropertyvalue(table.borderthicknessproperty, "3"); rangeoftext.applypropertyvalue(table.borderbrushproperty, brushes.red); }
in 'format' button click event i've set table borders red. on save database method i've used simple if
statement:
private void savetodbcommandaction() { if(pastedtext.contains("trowd")) { xceed.wpf.toolkit.messagebox.show("cannot save article. please remove pasted tables"); } else { savetodb(rtbtext); } }
therefore when user pastes in table warned via red cell borders. particularly useful if paste table invisible borders , can't see table. if statement determines whether rtf string contains 'trowd' tag therefore preventing save.
Comments
Post a Comment