Concatenate two Word documents using Delphi
<p>I would like to combine two word documents into one using Delphi.</p>

<p>In my database I have a table that contains a table with a varbinary(max) that containts a Word document and I would like to create a word document from some of the rows of that table based on a condition.</p>

<p>I have tried using streams </p>

<p>See : <a href="https://stackoverflow.com/questions/34894908/concatenate-tstringstream/">Concatenate TStringStream</a></p>

<p>Any ideas how can I achieve this? I've been searching, but did not find a solution. </p>

<pre><code>var
  i: Int32;
  stream: TFileStream;
  Path1: string;
  WordApp: TWordApplication;
begin
  Path1 := IncludeTrailingPathDelimiter(GetEnvironmentVariable('TEMP')) +
    FormatDateTime('yyyymmddhhnnssz', Now) + '.doc';
  WordApp := TWordApplication.Create(nil);
  stream := TFileStream.Create(Path1, fmCreate);
  try
    try
      with dm do
      begin
        DataSet.First;
        CopyBlobFieldToStream(dm.DataSet,
          dm.DataSetBlobField, stream);
        ShowMessage(IntToStr(stream.Size));
        DataSet.Next;
        CopyBlobFieldToStream(dm.DataSet,
          dm.DataSetBlobField, stream);
        ShowMessage(IntToStr(stream.Size));
        CopyBlobFieldToStream(dm.DataSet2,
          dm.DataSet2BlobField, stream);
        ShowMessage(IntToStr(stream.Size));
      end;
    finally
      stream.Free;
    end;
    WordApp.Documents.Open(Path1, EmptyParam, False, EmptyParam, EmptyParam,
      EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam,
      EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam);
    WordApp.Visible := True;
  finally
    WordApp.Free;
  end;
</code></pre>

<p>This is what i've tried.</p>