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.

slugonamission
  • 9,562
  • 1
  • 34
  • 41
ctype.h
  • 1,470
  • 4
  • 20
  • 34
  • I am writing the files (TXT and RTF) programmatically in C++ – ctype.h Dec 01 '11 at 23:29
  • 1
    [Here](http://en.wikipedia.org/wiki/Rich_Text_Format#External_links) you can find some links to several versions of the RTF specification. – Matteo Italia Dec 01 '11 at 23:42
  • 1
    This is useful: [RTF Table Definitions](http://msdn.microsoft.com/en-us/library/aa140283(v=office.10).aspx#rtfspec_tabledef). It is more descriptive than what I've been using. – ctype.h Dec 02 '11 at 06:24
  • How to work with tables in RTF well described here: http://www.pindari.com/rtf3.html – Igor Borisenko Mar 28 '14 at 01:57

2 Answers2

33

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

Jerry
  • 4,258
  • 3
  • 31
  • 58
  • 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 ... – MaxOvrdrv Dec 22 '14 at 20:15
  • 6
    RTF table definitions are a real nightmare. I thought I had it figured out and then I came across nested tables :-( – Santosh Jun 05 '17 at 09:23
  • 1
    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. – user2847643 Aug 04 '17 at 12:11
  • How do you remove the borders in printout receipt printer? – Demodave Jan 24 '19 at 21:37
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

Maarten
  • 41
  • 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! – pauljohn32 Jun 14 '17 at 04:17