Recognizing a Word-document

Recognizing a Word-document

Postby driessen » Fri Mar 11, 2022 9:21 am

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.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Recognizing a Word-document

Postby James Bott » Fri Mar 11, 2022 3:17 pm

Hmm, why not use the extension? That seems to be the simplest way.
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Recognizing a Word-document

Postby Otto » Fri Mar 11, 2022 7:35 pm

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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6329
Joined: Fri Oct 07, 2005 7:07 pm

Re: Recognizing a Word-document

Postby nageswaragunupudi » Sun Mar 13, 2022 10:40 pm

Existing FWH function MemoryBufferType is extended for next release.

Code: Select all  Expand view
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
User avatar
nageswaragunupudi
 
Posts: 10627
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 81 guests