Automatización de palabras para agregar / eliminar texto

I am working on a word automation project in c# and am using the interop word library to read/write to word. I am currently using bookmarks in a word template doc to find where to write info to in the word doc from c#. One of my bookmarks consists of two highlighted lines in the doc. Based on a boolean value, i have to decide whether to leave that text there and add a new line of text right after it, or delete those existing two lines from the doc.

So here is my pseudo for it:

if (writeToDoc)
// leave selected bookmark text intact and press enter to write another line right after
//delete the selected bookmark text

Can anyone please show me how to delete existing text as well as do the equivalent of pressing enter and writing another line from c#?

Muchas Gracias

EDIT: Here is the code i have (roughly)

    foreach (var bookmark in wordDoc.Bookmarks)
        var bookMarkNameExistsInCode = listOfBookmarks.Contains(wordDoc.Bookmarks[bookmark].Name);
        if (bookMarkNameExistsInCode )
            object oBookMarkName = wordDoc.Bookmarks[bookmark].Name;
            rng = wordDoc.Bookmarks.get_Item(ref oBookMarkName).Range;
            // at this point i am pointing to the two selected lines labelled as a bookmark in word. How can i deselect and add a new line?

preguntado el 09 de marzo de 12 a las 14:03

It might help to post some of the code you have so far: such as loading the part that locates the text block you want to work with.. This way people can expand on your thoughts a bit instead of starting from scratch -

ive added an edit above. hope it helps! -

1 Respuestas

If the word manipulation is done on DocX files you could use DocX library and use some very simple commands like text.ReplaceText(); and other very easy/intuitive commands. Replacing Interop con DocX if possible should get you up and running in no time :)

respondido 09 mar '12, 17:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.