Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

reading / writing word files with docfile

39 views
Skip to first unread message

Chris Sadler

unread,
Feb 8, 1999, 3:00:00 AM2/8/99
to
Does anyone have any code that demonstrates how to read and write MS word
files.

Any pointers would be appreciated.

Thanks

Chris

c...@io.org

Howard Rubin - change nospam to nyx

unread,
Feb 8, 1999, 3:00:00 AM2/8/99
to
"Chris Sadler" <c...@io.org> wrote:
>Does anyone have any code that demonstrates how to read and write MS word

Microsoft Developer Network Library Edition
Microsoft Office Development
Office
Microsoft Office 97 Binary File Formats
Microsoft Word 97 Binary File Format
and when you decide that's too ugly, you can use StgOpenStorage,
IStorage::OpenStream, IStream::Seek and IStream::Read to read the data.
HTH, Howard Rubin

#include <windows.h>
#include <stdio.h>
// Extracts text from a simple only-text document.
int ExtractTextFromMSWordDoc(const char *filename,
char *buf,
int maxBufSize,
int *ReturnLength,
int *Status) {
// Translate filename to UNICODE...
WCHAR wcFilename[1024];
int i = mbstowcs(wcFilename, filename, strlen(filename));
wcFilename[i] = 0;

// Open document as an OLE compound document...
IStorage *pStorage;
HRESULT hr = ::StgOpenStorage(wcFilename, NULL, STGM_READ | STGM_SHARE_DENY_WRITE, NULL, 0, &pStorage);

if(FAILED(hr)) {
return -1;
}

// Open the data-stream where Word stores the data...
IStream *pStream;
hr = pStorage->OpenStream(L"WordDocument", NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &pStream);

if(FAILED(hr)) {
pStorage->Release();
return -1;
}

// Seek to the entry in the FIB where the
// offsets for the text is stored...
LARGE_INTEGER offset;
offset.QuadPart = 0x18;
//DWORD count;
pStream->Seek(offset, STREAM_SEEK_SET, NULL);

// Read starting & ending offsets...
long start, end;
pStream->Read(&start, sizeof(long), NULL);
pStream->Read(&end, sizeof(long), NULL);

// Seek to starting offset...
offset.QuadPart = start;
pStream->Seek(offset, STREAM_SEEK_SET, NULL);

// Read text into buffer...
int size = min(end-start, maxBufSize-1);
pStream->Read(buf, size, NULL);

// Let go of our IStreampointer...
pStream->Release();

// Let go of our IStorage pointer...
pStorage->Release();

*ReturnLength = size;

return 0;
}
--
Advertisers using spambots, please don't send to the following addresses:
pres...@whitehouse.gov vice.pr...@whitehouse.gov first...@whitehouse.gov consum...@ftc.gov c...@ftc.gov fr...@uspis.gov u...@ftc.gov rh...@fcc.gov jqu...@fcc.gov sn...@fcc.gov rch...@fcc.gov cust...@usps.gov ad...@HARRIS-MARKETING.COM postm...@HARRIS-MARKETING.COM jmo...@SAVOYNET.COM postm...@agis.net ab...@agis.net ro...@agis.net dns-...@AGIS.NET n...@AGIS.NET hostm...@agis.net pat.co...@state.co.us ph...@agis.net webm...@agis.net postmaster@localhost in...@tsf-industries.com pro...@atg.wa.gov le...@atg.wa.gov mono...@atg.wa.gov uti...@atg.wa.gov c4en...@atg.wa.gov emai...@atg.wa.gov k...@cognigen.com
docu...@agis.net ip-re...@agis.net rou...@agis.net ne...@agis.net accou...@agis.net in...@agis.net aa...@agis.net h...@agis.net ema...@qlink2info.com sim...@answerme.com hostm...@INREACH.COM a...@INREACH.COM postm...@EMAILDIRECT.NET ab...@EMAILDIRECT.NET ro...@EMAILDIRECT.NET postm...@e-bizness.com ab...@e-bizness.com ro...@e-bizness.com com...@IAW.ON.CA maxe...@UNITED-CBE.ORG dom...@EMAILDIRECT.NET dom...@HOSTING.NETCOM.COM bobg...@EARTHLINK.NET sa...@marketingmasters.com biz...@SOFTCOM.NET dom...@HOSTING.NETCOM.COM ar...@ADDITIONALBENEFITS.COM

lee midgley

unread,
Feb 9, 1999, 3:00:00 AM2/9/99
to
do you have an example of reading a exel file (.xls)
Thanks,
Lee.

Howard Rubin - change nospam to nyx wrote in message
<91848009...@iris.nyx.net>...

Howard Rubin - change nospam to nyx

unread,
Feb 9, 1999, 3:00:00 AM2/9/99
to
"lee midgley" <cool...@chorleys.co.uk> wrote:
>do you have an example of reading a exel file (.xls)

ODBC via SQLAllocEnv, SQLAllocConnect, SQLConnect, SQLSetConnectOption,
SQLAllocStmt, SQLSetStmtOption, SQLExecDirect, SQLBindCol, and SQLSetPos
will write an XLS. You should be able to adapt SQLGetData to read one.
HTH, Howard Rubin

0 new messages