Merging in Formatted Text


#1

In some instances, I need to integrate entire documents (which I can only read), preserving all the formatting, to merge into a final document. So what I have tried to do is

a) Read the content of the document I want to take into a memory stream
b) Merge that into the main document.


The code is basically as follows

a)
'load the file
Dim mainDoc As Aspose.Word.Document
mainDoc = word.Open(s_Path)

'create a memory stream
Dim strm As System.IO.MemoryStream = New System.IO.MemoryStream(0)

'write the document text to that stream
mainDoc.save(strm, Aspose.Word.SaveFormat.FormatDocument)


b)
doc = doc.MailMerge.Execute(New String() {“OutOfState”}, New Object() {strm})


I saw that MailMerge.execute takes an object, but clearly it doesn’t take streams (as it prints out as “System.IO.MemoryStream” - i.e. the toString of the object). Obviously it works if I save the stream as Apose.Word.SaveFromat.FormatText and build a string out of the stream, but we need to keep the correct formatting, as these are official documents.

Any ideas?

Jat


#2

Hi Jat,

It is not possible in the current version of Aspose.Word, but it is certainly along the lines of what we want Aspose.Word to be able to do.

I think this functionality should be implemented not as mail merge but more like Insert/File in Word.

There will be many questions raised when trying to insert one document into another and I will look at how Word handles it and try to mimic it as close as possible. For example, what to do with headers/footers, styles, section marks etc when combining documents? The insert behaviour is likely to be different depending on whether you insert the document into “main” document body or into a table cell for example.

So as of today I cannot promise when inserting one document into another will be available. It could be on 2-3months time scale.

We might come up with some alternative solution quickly, for example copy sections of one document into another. In this case complete section(s) of one document can be copied to form sections in the destination document.

Let me know if you think copying sections will work for you.


#3

Copying of a section would be fine. Or even if there was a method for ‘paste RTF’ or something - that way I can extract what I want in the form of an RTF string and simply merge that in (via they paste method) and the fonts/formatting would be preserved.

Or even if you allowed some form of markup to format the text string that is merged e.g.
“Blah blah” & vbcr & "some more text"


Basically Word.Aspose does almost everything we want except
a) Handle the background image (as per that doc I sent you)
b) Allow insertion of text with various formatting





#4

Hi Jat,

Check out Aspose.Word 1.1.5 where background images like yours are supported.

Insertion of formatted text will take some time. Section copying might be available in 2 weeks or so.


#5

As a quick fix - is there a way to implement something like a PASTE SPECIAL in RTF format… That way I can just merge in an rtf string corresponding to the formatted text.

i.e. \rtf{gsdfsdafaAfs}


#6

Unfortunately this is not possible because Aspose.Word does not understand RTF yet.