Remove element in Interop

Asked

Viewed 44 times

1

I am developing a tool that will generate a file in format . DOC, the form fields will be filled in anyway but would like to put a formatting that removes any symbol from the text.

Ex: "• ", "¹²³£"

var atividades = wordDoc.Content.Paragraphs.Add(); 
atividade.Range.Text = "ATIVIDADES: \t" + txtAtividades.Text.Trim(); 
atividade.Range.Font.Name = "Arial"; 
atividade.Range.Bold = 0; 
atividade.Range.Font.Size = 11; // Centralizando o texto 
atividade.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignPa‌​ragraphLeft; 
atividade.Range.InsertParagraphAfter();
  • You already have some code ready so I can write a response based on it?

1 answer

0


Instead, I would apply a regular expression to remove strange characters from the text:

using System.Text.RegularExpressions;

atividade.Range.Text = Regex.Replace(atividade.Range.Text, "[^0-9a-zA-Z\.,]+", "");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.