Using Tables in RTF
Asked Answered
C

2

20

I need to create a table in an RTF file. However I am not familiar with RΤF. Here is an example of a text file that these RTF files are supposed to replace:

                               GENERAL JOURNAL
                                                                        Page 1

Date     Description                              Post Ref   Debit      Credit  
------------------------------------------------------------------------------
2011
Dec 1    Utilities Expense                          512      250.00
            Cash                                    111                 250.00
               Paid electric bill for November,
               Check No. 1234

    2    Cash                                       111       35.00
            Accounts Receivable / Customer Name     115/√                30.00
            Interest Income                         412                   5.00
               Receipt of payment on account
               from Customer, Check No. 5678

         . . .

The table is supposed to have borders, but I don't know how to do this either. Some cells have to have special borders on the bottom as in this file:

                                 Company Name
                        Schedule of Accounts Receivable
                               December 31, 2011

Name                                                                   Balance
------------------------------------------------------------------------------
Adams, John                                                             354.24
Jefferson, Thomas                                                        58.35
Washington, George                                                      754.58
                                                                      --------
                                                                       1167.17
                                                                      ========

I am aware of the \cell, \row etc., but I cannot figure out how to use them properly as the documentation that I have found is not very good. Please help.

Churrigueresque answered 1/12, 2011 at 23:25 Comment(4)
I am writing the files (TXT and RTF) programmatically in C++Churrigueresque
Here you can find some links to several versions of the RTF specification.Dulcimer
This is useful: RTF Table Definitions. It is more descriptive than what I've been using.Churrigueresque
How to work with tables in RTF well described here: pindari.com/rtf3.htmlTerceira
G
34

This site is useful: http://www.pindari.com/rtf3.html

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

This will give:

---------------------------
|cell 1 | cell 2 | cell 3 |  
---------------------------

A row is delimted with \trowd ... \row

Each cell ends with \cell

\cellx determines the right side of the corresponding cell in twips

Godliman answered 10/11, 2012 at 11:46 Comment(4)
Funny thing... Find and download the Microsoft RTF 1.9.1 specifications document. Then, save it as RTF. Notice that their table rows do NOT start and end like this. Instead, they all start with \ltrrow ...Jocundity
RTF table definitions are a real nightmare. I thought I had it figured out and then I came across nested tables :-(Incite
Fun fact: nested tables were not in the original RTF spec. They were added later in a backwards comptaible way. That is partly why they are a complete mess.Abbreviate
How do you remove the borders in printout receipt printer?Gromyko
S
4

Editing directly in RTF becomes quickly unreadable. Pehaps this practical approach works better: - Create an example mock-up ( in Excel or Word ) using unique identifiers as placeholders ( example "(P1)" ) - Then save as RTF - Open the RTF in notepad - copy the RTF codes "as is" and replace the placeholders with actual values in your program

Semiporcelain answered 5/3, 2015 at 9:11 Comment(1)
The other answer is more general. This is what I actually do in cases like this. As long as you can create table, save as rtf, you can learn how it is done. Warning: liberally insert line breaks after brackets!Baleful

© 2022 - 2024 — McMap. All rights reserved.