943,515 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 2473
  • C++ RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Jul 2nd, 2009
0

Re: Copying a microsoft word doc

Hey AD, in your post (#3) you forgot an ending bracket on this line:
while( fin.read( iobuffer, sizeof(iobuffer) )
Last edited by tux4life; Jul 2nd, 2009 at 7:36 am.
Reputation Points: 2125
Solved Threads: 243
Postaholic
tux4life is offline Offline
2,105 posts
since Feb 2009
Jul 2nd, 2009
0

Re: Copying a microsoft word doc

Click to Expand / Collapse  Quote originally posted by tux4life ...
Hey AD, in your post (#3) you forgot a bracket on this line:
while( fin.read( iobuffer, sizeof(iobuffer) )
Nobody is perfect
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is online now Online
21,945 posts
since Aug 2005
Jul 3rd, 2009
0

Re: Copying a microsoft word doc

II have written code that can successfully read and write a microsoft word doc - that is if the word doc contains plain text only. If there are any headings and different fonts used, these are not copied successfully. Which brings me back to my original question - when copying word docs does one need to manipulate the non-ascii chars? And how is this done?





When I actually tried it I had the same problem. I used a command prompt and found out that the two files were just a few bytes different.

well, the code I posted almost works. The problem is that the last few bytes does not get read/written
C++ Syntax (Toggle Plain Text)
  1. int main(int argc, char* argv[])
  2. {
  3. char iobuf[255];
  4. size_t total = 0;
  5. size_t sz = 0;
  6. ifstream fin("file1.doc", ios::binary);
  7. if( !fin.is_open() )
  8. {
  9. cout << "Can't open the file\n";
  10. return 1;
  11. }
  12. ofstream fout( "copy.doc", ios::binary);
  13. while( fin.read(iobuf, sizeof(iobuf) ))
  14. {
  15. sz = fin.gcount();
  16. total += sz;
  17. fout.write(iobuf, sz);
  18. sz = 0;
  19. }
  20. sz = fin.gcount();
  21. if( sz > 0)
  22. {
  23. cout << "sz = " << sz << "\n";
  24. total += sz;
  25. fout.write(iobuf, sz);
  26. }
  27. fin.close();
  28. fout.close();
  29. cout << "Total = " << total << "\n";
  30. return 0;
  31. }
Reputation Points: 6
Solved Threads: 0
Newbie Poster
shealy is offline Offline
14 posts
since Jun 2009
Jul 3rd, 2009
0

Re: Copying a microsoft word doc

Click to Expand / Collapse  Quote originally posted by shealy ...
II have written code that can successfully read and write a microsoft word doc - that is if the word doc contains plain text only
That isn't a microsoft word doc, but a normal text file.

Click to Expand / Collapse  Quote originally posted by shealy ...
. If there are any headings and different fonts used, these are not copied successfully. Which brings me back to my original question - when copying word docs does one need to manipulate the non-ascii chars? And how is this done?
See the code I already posted and which you quoted. If all you want to do is copy the file then the answer to your question is NO.
Last edited by Ancient Dragon; Jul 3rd, 2009 at 11:55 pm.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is online now Online
21,945 posts
since Aug 2005
Jul 6th, 2009
0

Re: Copying a microsoft word doc

The microsoft word doc is copied successfully - byte per byte. Copied file is same size as original. However, when I try and use microsoft word to open the copied file, the copied file contents which have non-ascii text are not readable. The ascii text is readable. So the copied file is worthless to the end user if he/she cannot see the non-ascii parts. So I want to be able to copy the file AND open it and read it successfully using ms-word.


That isn't a microsoft word doc, but a normal text file.



See the code I already posted and which you quoted. If all you want to do is copy the file then the answer to your question is NO.
Reputation Points: 6
Solved Threads: 0
Newbie Poster
shealy is offline Offline
14 posts
since Jun 2009
Jul 6th, 2009
0

Re: Copying a microsoft word doc

Click to Expand / Collapse  Quote originally posted by shealy ...
The microsoft word doc is copied successfully - byte per byte. Copied file is same size as original. However, when I try and use microsoft word to open the copied file, the copied file contents which have non-ascii text are not readable. The ascii text is readable. So the copied file is worthless to the end user if he/she cannot see the non-ascii parts. So I want to be able to copy the file AND open it and read it successfully using ms-word.
Zip up the file you are trying to copy and post it so that I can test it. The doc file I tested is readable by MS-Word as expected, and it contains quite a bit of graphics and charts, so there is no reason that program does not work with any document.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is online now Online
21,945 posts
since Aug 2005
Jul 6th, 2009
0

Re: Copying a microsoft word doc

I can confirm AD's code works correctly.
(Also tested it on a couple of Word files, playing a bit with the formatting)
The file is loading correctly after copying.

To the OP:
Ensure that you're copying a file which isn't corrupted, before copying you should check whether the file you want to copy loads correctly in MS Word, otherwise you've already missed the boat before the copying process starts.
Reputation Points: 2125
Solved Threads: 243
Postaholic
tux4life is offline Offline
2,105 posts
since Feb 2009
Jul 6th, 2009
0

Re: Copying a microsoft word doc

Attached is the input file - Input.doc and the output file that is created - Output.doc. As you can see outfile looks very different to the inputfile. I used the code that you provided to test this.


When I actually tried it I had the same problem. I used a command prompt and found out that the two files were just a few bytes different.

well, the code I posted almost works. The problem is that the last few bytes does not get read/written
C++ Syntax (Toggle Plain Text)
  1. int main(int argc, char* argv[])
  2. {
  3. char iobuf[255];
  4. size_t total = 0;
  5. size_t sz = 0;
  6. ifstream fin("file1.doc", ios::binary);
  7. if( !fin.is_open() )
  8. {
  9. cout << "Can't open the file\n";
  10. return 1;
  11. }
  12. ofstream fout( "copy.doc", ios::binary);
  13. while( fin.read(iobuf, sizeof(iobuf) ))
  14. {
  15. sz = fin.gcount();
  16. total += sz;
  17. fout.write(iobuf, sz);
  18. sz = 0;
  19. }
  20. sz = fin.gcount();
  21. if( sz > 0)
  22. {
  23. cout << "sz = " << sz << "\n";
  24. total += sz;
  25. fout.write(iobuf, sz);
  26. }
  27. fin.close();
  28. fout.close();
  29. cout << "Total = " << total << "\n";
  30. return 0;
  31. }
Attached Files
File Type: doc Input.doc (12.2 KB, 15 views)
File Type: doc Output.doc (12.2 KB, 19 views)
Reputation Points: 6
Solved Threads: 0
Newbie Poster
shealy is offline Offline
14 posts
since Jun 2009
Jul 6th, 2009
0

Re: Copying a microsoft word doc

File is def not corrupted before copying. FYI am using a C++ binary on 2.8 sun solaris operating system. Run the binary and binary creates Output.doc from Input.doc. Output.doc is then ftp'd to desktop where I use miscrosoft word to open it.

Thanks for the help so far.


Click to Expand / Collapse  Quote originally posted by tux4life ...
I can confirm AD's code works correctly.
(Also tested it on a couple of Word files, playing a bit with the formatting)
The file is loading correctly after copying.

To the OP:
Ensure that you're copying a file which isn't corrupted, before copying you should check whether the file you want to copy loads correctly in MS Word, otherwise you've already missed the boat before the copying process starts.
Reputation Points: 6
Solved Threads: 0
Newbie Poster
shealy is offline Offline
14 posts
since Jun 2009
Jul 6th, 2009
0

Re: Copying a microsoft word doc

There might be ftp problem. And I don't know what will happen if you try to copy MS-World doc file on your solaris operating system.
Last edited by Ancient Dragon; Jul 6th, 2009 at 9:23 am.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is online now Online
21,945 posts
since Aug 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: g++ linker error. Please help.
Next Thread in C++ Forum Timeline: [C++] Problem with changing contents of char[]





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC