APPLICATION INTERCHANGE FILE FORMATS
Simple tutorial for programmers



RTF - Rich Text Format (.rtf extension) - working with tables

This builds upon the basics in the first example. The desired database output required three columns, the first of which had the question, the second column had the current period comments and the third column had last period comments. Both comments were free form text. The rows represented different questions to which the comments applied.

As you will have observed from the prior examples RTF used a measurement system called twips which are defined in 1/20 of a point, where 72 points are an inch; therefore 1440 twips are one inch (72 times 20). In the following examples I build a table by defining sequential rows. Each row begins with \trowd and ends with \row. Within a row are cells which end with \cell.

The following will generate a table of one row and three columns. The right side of first cell is at 1,000 twips; the second cell at 2,000 twips and the third at 3,000 twips.

{\rtf1\ansi\deff0
\trowd
\cellx1000
\cellx2000
\cellx3000
cell 1\intbl\cell
cell 2\intbl\cell
cell 3\intbl\cell
\row
}


Of course, this could also be done with tabs. Unlike a tab, the application will increase the row height to accomodate the text.

{\rtf1\ansi\deff0
\trowd
\cellx1000
\cellx2000
\cellx3000
cell 1\intbl\cell
lots of text in cell two\intbl\cell
cell 3\intbl\cell
\row
}


and you can add boarders to the top, bottom, left and right of the cells

{\rtf1\ansi\deff0
\trowd
\clbrdrt\brdrs\clbrdrl\brdrs\clbrdrb\brdrs\clbrdrr\brdrs
\cellx1000
\clbrdrt\brdrs\clbrdrl\brdrs\clbrdrb\brdrs\clbrdrr\brdrs
\cellx2000
\clbrdrt\brdrs\clbrdrl\brdrs\clbrdrb\brdrs\clbrdrr\brdrs
\cellx3000
cell 1\intbl\cell
lots of text in cell two\intbl\cell
cell 3\intbl\cell
\row
}


Since I don't want the text right next to the border I move it in 144 twips (1/10")

{\rtf1\ansi\deff0
\trowd\trgaph144
\clbrdrt\brdrs\clbrdrl\brdrs\clbrdrb\brdrs\clbrdrr\brdrs
\cellx1000
\clbrdrt\brdrs\clbrdrl\brdrs\clbrdrb\brdrs\clbrdrr\brdrs
\cellx2000
\clbrdrt\brdrs\clbrdrl\brdrs\clbrdrb\brdrs\clbrdrr\brdrs
\cellx3000
cell 1\intbl\cell
lots of text in cell two\intbl\cell
cell 3\intbl\cell
\row
}


adding a second row is straight forward

{\rtf1\ansi\deff0
\trowd\trgaph144
\clbrdrt\brdrs\clbrdrl\brdrs\clbrdrb\brdrs\clbrdrr\brdrs
\cellx1000
\clbrdrt\brdrs\clbrdrl\brdrs\clbrdrb\brdrs\clbrdrr\brdrs
\cellx2000
\clbrdrt\brdrs\clbrdrl\brdrs\clbrdrb\brdrs\clbrdrr\brdrs
\cellx3000
cell 1\intbl\cell
lots of text in cell two\intbl\cell
cell 3\intbl\cell
\row
\trowd\trgaph144
\clbrdrt\brdrs\clbrdrl\brdrs\clbrdrb\brdrs\clbrdrr\brdrs
\cellx1000
\clbrdrt\brdrs\clbrdrl\brdrs\clbrdrb\brdrs\clbrdrr\brdrs
\cellx2000
\clbrdrt\brdrs\clbrdrl\brdrs\clbrdrb\brdrs\clbrdrr\brdrs
\cellx3000
row 2 cell 1\intbl\cell
lots of text in row 2 cell two\intbl\cell
row 2 cell 3\intbl\cell
\row
}


Instead of \brdrs for a single line border you can use the following border types (note that I used \par and \pard to break the rows):

{\rtf1\ansi\deff0
Below are the border types\line\par

\trowd\trgaph144
\clbrdrt\brdrs\clbrdrl\brdrs\clbrdrb\brdrs\clbrdrr\brdrs
\cellx5000
Single border\intbl\cell
\row\pard\par

\trowd\trgaph144
\clbrdrt\brdrdot\clbrdrl\brdrdot\clbrdrb\brdrdot\clbrdrr\brdrdot
\cellx5000
Dotted border\intbl\cell
\row\pard\par

\trowd\trgaph144
\clbrdrt\brdrdb\clbrdrl\brdrdb\clbrdrb\brdrdb\clbrdrr\brdrdb
\cellx5000
Double thickness border\intbl\cell
\row\pard\par

\trowd\trgaph144
\clbrdrt\brdrdash\clbrdrl\brdrdash\clbrdrb\brdrdash\clbrdrr\brdrdash
\cellx5000
Dashed border\intbl\cell
\row\pard\par

\trowd\trgaph144
\clbrdrt\brdrdashsm\clbrdrl\brdrdashsm\clbrdrb\brdrdashsm\clbrdrr\brdrdashsm
\cellx5000
Small dashed border\intbl\cell
\row\pard\par

\trowd\trgaph144
\clbrdrt\brdrdashd\clbrdrl\brdrdashd\clbrdrb\brdrdashd\clbrdrr\brdrdashd
\cellx5000
Dot dash border\intbl\cell
\row\pard\par

\trowd\trgaph144
\clbrdrt\brdrdashdd\clbrdrl\brdrdashdd\clbrdrb\brdrdashdd\clbrdrr\brdrdashdd
\cellx5000
Dot dot dash border\intbl\cell
\row\pard\par

\trowd\trgaph144
\clbrdrt\brdrtriple\clbrdrl\brdrtriple\clbrdrb\brdrtriple\clbrdrr\brdrtriple
\cellx5000
Triple border\intbl\cell
\row\pard\par

\trowd\trgaph144
\clbrdrt\brdrtnthlg\clbrdrl\brdrtnthlg\clbrdrb\brdrthtnlg\clbrdrr\brdrthtnlg
\cellx5000
Thick thin border (large)\intbl\cell
\row\pard\par

\trowd\trgaph144
\clbrdrt\brdrtnthlg\clbrdrl\brdrtnthlg\clbrdrb\brdrthtnlg\clbrdrr\brdrthtnlg
\cellx5000
Thin thick border (large)\intbl\cell
\row\pard\par

\trowd\trgaph144
\clbrdrt\brdrtnthtnlg\clbrdrl\brdrtnthtnlg\clbrdrb\brdrtnthtnlg\clbrdrr\brdrtnthtnlg
\cellx5000
Thin thick thin border (large)\intbl\cell
\row\pard\par

\trowd\trgaph144
\clbrdrt\brdrwavy\clbrdrl\brdrwavy\clbrdrb\brdrwavy\clbrdrr\brdrwavy
\cellx5000
Wavy border\intbl\cell
\row\pard\par

\trowd\trgaph144
\clbrdrt\brdrdashdotstr\clbrdrl\brdrdashdotstr\clbrdrb\brdrdashdotstr\clbrdrr\brdrdashdotstr
\cellx5000
Striped border\intbl\cell
\row\pard\par

\trowd\trgaph144
\clbrdrt\brdremboss\clbrdrl\brdremboss\clbrdrb\brdrengrave\clbrdrr\brdrengrave
\cellx5000
Emboss border\intbl\cell
\row\pard\par

\trowd\trgaph144
\clbrdrt\brdrengrave\clbrdrl\brdrengrave\clbrdrb\brdremboss\clbrdrr\brdremboss
\cellx5000
Engrave border\intbl\cell
\row\pard\par

End of border types.
}


Click here to open a file with the above code.



Reference sites:

Home Page