Setting column width in RTF

让人想犯罪 __ 提交于 2019-12-03 15:34:22

The problem is in that you have set very small width for column:

\cellx1 
\cellx2 
\cellx3

To set width for column in RTF there is a keyword '\cellxN', where N - is column width in twips. 15 twips is 1px.

So if you want to create a simple RTF table with 1 row and 3 columns, 100px each, use this syntax:

\trowd\cellx1500\cellx3000\cellx4500
\intbl A\cell B\cell C\cell\row

You will get a simple table by 300px, 3 columns - 100px each, with invisible borders.

Cheers, Max

The control words you are looking for are \clwWidthN and \clftsWidthN

Microsoft RTF Specification v1.9.1:

- \clwWidthN
Preferred cell width. Overrides \trautofitN.
- \clftsWidthN 
Units for \clwWidthN:    
  - 0 : Null. Ignore \clwWidthN in favor of \cellxN (Word 97 style of determining cell and row width).
  - 1 : Auto, no preferred cell width, ignores \clwWidthN if present; \clwWidthN will generally not be written, giving precedence to row defaults.
  - 2 : Percentage (in 50ths of a percent).
  - 3 : Twips.

So, in your case, you could just use \clftsWidth1 (automatically set width) or set the preferred percentages yourself e.g. \clwWidth2\clwWidth2500 (2500 = 50%)

Auto width

\trowd \trautofit1  
\intbl  
\clftsWidth1\cellx1  
\clftsWidth1\cellx2  
\clftsWidth1\cellx3  
{a\cell b\cell c\cell }

40% - 30% - 30%

\trowd \trautofit1  
\intbl  
\clftsWidth2\clwWidth2000\cellx1  
\clftsWidth2\clwWidth1500\cellx2  
\clftsWidth2\clwWidth1500\cellx3  
{a\cell b\cell c\cell }

You need to either use cellx0, so that autofit tag applies, or explicity set the number to the number of twips from the left border. In your example, you use 1 2 and 3 which is explicity setting the column widths to be very skinny. For example, something like:

\cellx5125 \Cellx6000 \Cellx8000

Note that these numbers are offsets from the left margin.

If you are going to do any RTF, I highly recomend the RTF Pocket Guide from O'Rielly

Check this link

http://joseluisbz.wordpress.com/2014/04/26/working-rtf-html-css-and-script-files-with-my-own-packages-java-and-php/

you can to make your own file.

      TblData = new RTFTable(4,4);  //4 Columns, 4 Rows

      TblData.setWideCols(1000);  //Width of 2000 to put all columns
      TblData.setWideCol(0,3000);  //Width of 3000 to Column 0
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!