Free Support Forum - aspose.com

How to select text from a doc

Hi,

I have about 20 lines of text that for weird security reason, can’t be saved into a DB.

So I saved it into a text file.

In my programming, I move to bookmark, open my text file, read it, and write it in my word document. Easy enough eh?

As you can tell by reading me, it was a bit too easy Smile

It won’t preserve formatting. So what I would like to do, is to put that text into a word document which I would open, select all its content and write it at the bookmark location. That way, it should preserve its formatting right?

So my questions are:
1- how do I select text from my word document?
2- Will it preserve formatting (like ordered list) ?

Hi,

The content from one Word document could be copied into another one by moving a section, this is the only way at the moment. But the problem is that we have not yet implemented the method to put a section at a particular bookmark, merge field etc. It could be only inserted into a section collection or its content could be prepended or appended to a destination section.

So what about another approach? Are you able to store your text in an HTML file, read it to a string, then move to a bookmark and use DocumentBuilder.InsertHtml?

would it retain the formatting?

because in the text file, I had

1. some text here that span over
two lines and were not aligned


and I would need

1. some text here that span over
two lines and are aligned

I also need bold in some case.

I hope it would, but to make sure you should test it yourself or attach a sample of your text to let us see.

Here is what should be inserted at the bookmark

Attached is a pack of documents I used during the testing:

  • test.doc is a source document that contains nothing but a single bookmark;
  • example.doc is your document intended for insertion;
  • insert.htm is the converted HTML document (btw I used Aspose.Word for the conversion Wink, avoid using MS Word for this because it inserts lots of spesific elements into resulting HTML);
  • result.doc is the resulting document.

As you can see, the only obvious problem is the strange spacing in the title before représentant. This seems to be caused by the preceding tab in the original document. Deleting this tab makes the output in the resulting document look properly.