FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Problem with the "height" of a table cell in MS Word
Posts: 193
Joined: Wed Apr 04, 2007 06:54 AM
Problem with the "height" of a table cell in MS Word
Posted: Thu Jul 31, 2025 08:25 PM

Hi at all.

I can't get the height of a table cell in MS Word.

I can only get the width; the height always returns 9999999.00.

Is this a Word bug? (Version 2016 and 2019 give the same result.)

oWord := CreateObject("Word.Application")

oFile := oWord:Documents:Open( cFilePath(GetModuleFileName(GetInstance())) + "doc1.docx" )

? oFile:Tables[1]:Rows[2]:Height // result: 9999999.00

? oFile:Tables[1]:Cell(2, 2):Height // result: 9999999.00

? oFile:Tables[1]:Cell(2, 2):width // result: 96.25

Only if I enter a height value does it return the measurement:

? oFile:Tables[1]:Cell(2, 2):Height := 24 // result: 24

? oFile:Tables[1]:Cell(2, 2):Height // result 24.00

oWord:Quit()

can someone help me?

thanks, Marzio

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Problem with the "height" of a table cell in MS Word
Posted: Fri Aug 01, 2025 04:58 AM

Dear Marzio,

> Only if I enter a height value does it return the measurement:

Then, why don't you do it that way ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 193
Joined: Wed Apr 04, 2007 06:54 AM
Re: Problem with the "height" of a table cell in MS Word
Posted: Fri Aug 01, 2025 06:11 AM

thanks Antonio per your help.

I need to know the height of a row in an existing table to estimate how many lines of text there are.

If I give it a measurement, it returns the same measurement, but it doesn't match reality:

If I assign it a measurement of 12, the function returns 12, but in reality, if it contains 3 lines of text, it is 36 high.

Posts: 99
Joined: Thu Jul 12, 2007 02:02 PM
Re: Problem with the "height" of a table cell in MS Word
Posted: Fri Aug 01, 2025 08:15 AM
Hi Marzio,

this can help you ?
Pos := oFile:Tables[1]:Cell( 2, 2 ):Range:End - 1
CellHeight := oFile:Range( Pos, Pos ):Information( 8 )      // wdVerticalPositionRelativeToTextBoundary
MsgStop( CellHeight )
Posts: 193
Joined: Wed Apr 04, 2007 06:54 AM
Re: Problem with the "height" of a table cell in MS Word
Posted: Fri Aug 01, 2025 09:54 AM

Thanks MaxP for your interest.

Unfortunately, MsgStop() returns 0.00.

Do you have any other ideas?

Posts: 99
Joined: Thu Jul 12, 2007 02:02 PM
Re: Problem with the "height" of a table cell in MS Word
Posted: Fri Aug 01, 2025 09:59 AM

Hi Marzio,

yes, it returns 0 if the cell is empty,

but if there is text it should return the height

Massimo

Posts: 193
Joined: Wed Apr 04, 2007 06:54 AM
Re: Problem with the "height" of a table cell in MS Word
Posted: Fri Aug 01, 2025 10:14 AM

Hi Massimo.

There is text in the cells but it still returns 0.00

Posts: 99
Joined: Thu Jul 12, 2007 02:02 PM
Re: Problem with the "height" of a table cell in MS Word
Posted: Fri Aug 01, 2025 10:17 AM

Hi Marzio,

should return 0 if there is only one line,

you could try entering a longer text ?

Posts: 99
Joined: Thu Jul 12, 2007 02:02 PM
Re: Problem with the "height" of a table cell in MS Word
Posted: Fri Aug 01, 2025 11:51 AM
Hi Marzio,

try this
...
nRows := WdGetNRows( oFile, 1, 2, 2 )
...

FUNCTION WdGetNRows( oDoc, nTable, nRow, nCol )
        LOCAL   Pos, CellHeight, CellHeight1, nRows, cBuf, nSizeRow
        
        Pos := oDoc:Tables[nTable]:Cell( nRow, nCol ):Range:End - 1
        CellHeight := oDoc:Range( Pos, Pos ):Information( 8 )      // wdVerticalPositionRelativeToTextBoundary 8
                        
        cBuf := LEFT( oDoc:Tables[nTable]:Cell( nRow, nCol ):Range:Text, LEN( oDoc:Tables[1]:Cell( nRow, nCol ):Range:Text ) - 2 )

        oDoc:Tables[nTable]:Cell( nRow, nCol ):Range:Text := cBuf + CRLF
                        
        Pos := oDoc:Tables[nTable]:Cell( nRow, nCol ):Range:End - 1
        CellHeight1 := oDoc:Range( Pos, Pos ):Information( 8 )      // wdVerticalPositionRelativeToTextBoundary 8
                        
        nSizeRow := CellHeight1 - CellHeight

        oDoc:Tables[nTable]:Cell( nRow, nCol ):Range:Text := cBuf

        IF CellHeight == 0
                nRows := IIF( EMPTY( cBuf ), 0, 1 )
        ELSE
                nRows := INT( CellHeight / nSizeRow ) + 1
        ENDIF
RETURN nRows
Posts: 193
Joined: Wed Apr 04, 2007 06:54 AM
Re: Problem with the "height" of a table cell in MS Word
Posted: Fri Aug 01, 2025 01:17 PM

Yes, Massimo,

now works fine.

beyond the first line, the measurement returns higher than the first line. This is what fooled me. Thank you so much. Now I can proceed!

I'll also check the function you sent me!

Thank you so much.

Marzio

Continue the discussion