简体   繁体   中英

How to remove the extra spaces before the cell text?

I am working with WinForms. In my application, I need to use RTF for formatting cell text. However, when I set the RTF style, there are extra spaces shown before the text in the first cell. Here is the sample code I used:

string rtf3 =
    @"{\rtf1\ansi" +
    // font table
    @"{\fonttbl" +
    @"\f0 Axel;} " +
    @"\deff0 " +
    // color table
    @"{\colortbl" +
    @"\red186\green0\blue0; " +
    @"\red240\green224\blue255;} " +
    // first line
    @"\ql\f0\fs18 " + "David" +
    @"\plain\par" +
    // closing bracket
    @"}";

In this, I can't understand the style settings. Please anyone suggest me how to resolve the extra spaces as per the below image?

表格截图

You should remove the spaces that are not part of an RTF control word that you do not want to appear in the output. So spaces after ; and } , and before { . So your code will look like this:

string rtf3 =
    @"{\rtf1\ansi" +
    // font table
    @"{\fonttbl" +
    @"\f0 Axel;}" +
    @"\deff0" +
    // color table
    @"{\colortbl" +
    @"\red186\green0\blue0;" +
    @"\red240\green224\blue255;}" +
    // first line
    @"\ql\f0\fs18 " + "David" +
    @"\plain\par" +
    // closing bracket
    @"}";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM