Hello,
Is there a way to find out what format a document it is made in, which i need to open in Word from my FWH-application.
Is it an RTF-document, is it DOC, is it DOCX?
I want to know it, without taking the filename extension into considuration.
Thank you very much.
Recognizing a Word-document
Recognizing a Word-document
Regards,
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.09 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.09 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
- James Bott
- Posts: 4840
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Re: Recognizing a Word-document
Hmm, why not use the extension? That seems to be the simplest way.
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
- Otto
- Posts: 6414
- Joined: Fri Oct 07, 2005 7:07 pm
- Has thanked: 30 times
- Been thanked: 2 times
- Contact:
Re: Recognizing a Word-document
Michel, what about opening with memoread?
In a DOC file, you will find {\rtf1\ were as a docx is a zip file.
Best regards,
Otto
In a DOC file, you will find {\rtf1\ were as a docx is a zip file.
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
- nageswaragunupudi
- Posts: 10729
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 10 times
- Contact:
Re: Recognizing a Word-document
Existing FWH function MemoryBufferType is extended for next release.
This function can recognize if the given text is an image type or a doc type ( RTF, GTF, PDF, DOC, DCX (for DOCX), etc
Code: Select all | Expand
function MemoryBufferType( cBuf )
local cType, n, a
local cPunct := Chr( 9 ) + Chr( 10 ) + Chr( 12 ) + Chr( 13 ) + Chr( 26 ) + Chr( 141 )
local lExact := Set( _SET_EXACT, .f. )
local lBinary := .f.
local aTypes := { ;
{ "IMG.BMP", "BM", .t. }, ;
{ "IMG.PNG", Chr( 0x89 ) + "PNG", .f. }, ;
{ "IMG.ICO", Chr( 0 ) + Chr( 0 ) + Chr( 1 ), .f. }, ;
{ "IMG.JPG", Chr( 255 ) + Chr( 216 ) + Chr( 255 ), .f. }, ;
{ "IMG.GIF", "GIF8", .t. }, ;
{ "IMG.TIF", Chr(73) + Chr(73) + Chr(42), .t. }, ;
{ "IMG.TIF", Chr(77) + Chr(77) + Chr(42), .t. }, ;
{ "IMG.EMF", Chr( 1 ) + Chr( 0 ) + Chr( 0 ) + Chr( 0 ), .f., }, ;
{ "IMG.WMF", HEXTOSTR( "D7CDC69A00" ), .f. }, ;
{ "DOC.XML", "<?xml ", .f. }, ;
{ "DOC.RTF", "{\rtf", .f. }, ;
{ "DOC.GTF", "GTF" + Chr( 5 ), .f. }, ;
{ "DOC.PDF", "%PDF-", .f. }, ;
{ "DOC.DOC", HEXTOSTR( "D0CF11E0A1B11AE1" ), .f. }, ;
{ "DOC.DCX", HEXTOSTR( "504B030414" ), .f. } }
for each a in aTypes
if cBuf = a[ 2 ]
if a[ 3 ]
if IsBinaryData( SubStr( cBuf, 3, 15 ) )
cType := a[ 1 ]
endif
else
cType := a[ 1 ]
endif
EXIT
endif
next
Set( _SET_EXACT, lExact )
if ! Empty( cType )
return cType
endif
lBinary := IsBinaryData( cBuf )
if lBinary
if FreeImageIsLoaded() .and. ( n := IfNil( FITypeFromMemory( cBuf ), -1 ) ) >= 0
return "IMG." + cValToChar( n )
endif
cType := "BIN.HEX"
else
if IsUTF8( cBuf )
return "TXT.UTF8"
else
cType := "TXT.ANSI"
endif
endif
return cType
This function can recognize if the given text is an image type or a doc type ( RTF, GTF, PDF, DOC, DCX (for DOCX), etc
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India