View Full Version : Merging of files
imported_Pat
12-17-2002, 06:25 AM
How can I use C programming language to merge 2 or more files with the extension doc (microsoft word).
I have tried to copy the files and append it to a destination file but only the first stated file is copied but the file size keeps on increasing. Binary mode have been used
Strike
12-17-2002, 08:45 AM
Well, the .doc file format would probably be a good thing to know. Unfortunately, I don't think that that specification is open to the public (hooray closed formats). There's a lot more than just the words that you type in .doc files. There's formatting info, general document info, and a bunch of other data, and it's not all stuck in along with the text either, so simply concatenating the files together won't work because there will be chunks of data where they don't belong.
So, in short, you need to find either: a) the Word doc format specification (if it exists somewhere to be had freely), or b) a library of some sort that allows you to read specific parts of Word docs
bwkaz
12-17-2002, 10:09 AM
I'm not entirely sure on how you can do it in C, but Word itself is macro-izeable (hooray for macro viruses...) and supports COM/OLE Automation, which means you can control an instance of Word from another program, as long as you're running on Windows, and you have a compiler that understands COM (I know M$'s compilers do, but I don't know about other ones).
You create a COM object of type Word.Application, name it app for example, then do a doc2 = app.Documents.Open("drive:\path\to\file2.doc");, then do the equivalent of a select all (not sure how to do that though...), then copy, then doc1 = app.Documents.Open("drive:\path\to\file1.doc");, go to the end of it somehow, and do a paste somehow.
I'm not sure if this exact syntax will work in e.g. an MSVC++ program, as all I've ever done this kind of thing with is VB (uggh, I know, it still hurts). But there should be something similar that you can do -- I'd suggest reading up on OLE Automation and/or COM in general.
In short, the idea is to get the version of Word that's already installed on the computer to do the concatenation for you -- that way, you don't need the (unpublished... yay. :rolleyes: ) .doc format.
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.