编辑RichText Document的RTF [英] Editing RichText Document's RTF

查看:167
本文介绍了编辑RichText Document的RTF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



和你们所有人非常成功的一年



我正在研究的当前项目是创建格式化报告的阶段打印



我使用RichTextBox构建文本,然后将格式添加到相应的RTF。



可能如下所示:



 rtf.OnCmd(BOLD); rtf.AddText(  *); rtf.OffCmd(BOLD); 





rtf是源自RichTextBox的CRtbx实例。

OnCmd( ..)添加一个rtf on-tag,OffCmd(..)添加一个rtf off-tag,AddText执行Text.Append(..);



在过去的两周里,我已经尝试了很多RTF和

工作原理是:为fonttable添加字体,设置字体,设置字体大小和

设置文本粗体,下划线和斜体。



现在这就是我被困一周的原因:



我无法在Info-Group中添加一些项目({\Info {Itm1} ... {ItmN}}



我这样做:

 rtf.AddText(  * ); 
string strRtf = Rtf;



strRtf看起来像这样(A):



 {\\rtf1\\ansi\\ANSicpg1252 \\deff0 \\deflang1031< br /> 
{ \\\fonttbl {\\f0 \\fnil\\fcharset0 Microsoft Sans Serif;}} \\ n< br />
\\viewkind4 \\uc1 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\



插入信息组后,项目''nofpages1''strRtf看起来像这样(B):



 {\\rtf1\\ansi\\ANSicpg1252 \\deff0 \\deflang1031< br /> 
{\\\\ ttonttbl {\\f0\\fnil\\fcharset0 Microsoft Sans Serif;}} \\ n< br />
{\\ Information {\\\\
ofpages1}} < br />
\\ viewkind4 \\uc1 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ r \ n}} \ n \\ n



但是在

之后

 Rtf = strRtf 



Rtf没有改变,仍然看起来像(A)< br $> b $ b

我在这里做错了什么?

到目前为止谷歌没有任何帮助



提前感谢

解决方案

您正在以非常过时的文本格式进行非常繁琐且容易出错的工作。我不明白为什么这样做。在一开始,您提到您只需要创建一个报告。这更容易,因为您不需要直接深入研究RTF标记,而只需使用API​​通过一个或另一个 RichTextBox 类格式化文本片段。



如果,由于一些奇怪的原因,你真的需要咬紧牙关,请阅读所有语法的参考:

http://msdn.microsoft.com/en-us/library/aa140280%28office.10%29。 aspx [ ^ ],

http:// www。 microsoft.com/en-us/download/details.aspx?id=10725 [ ^ ],

http:// interglacial .com / rtf / [ ^ ]。



但是为什么?



< DD> -SA

hi,
and a very successfull year to all of you

the current project I''m working on is at the stage of creating a formatted report to
be printed.
I use RichTextBox to build the text and then add the formatting to the corresponding RTF.

which might look like this :

rtf.OnCmd(BOLD); rtf.AddText("*"); rtf.OffCmd(BOLD);



rtf is an instance of CRtbx derived from RichTextBox.
OnCmd(..) adds an rtf on-tag, OffCmd(..) adds an rtf off-tag, AddText does Text.Append("..");

for the last two weeks i''ve experimented a lot with RTF and
what is working is : add font to fonttable, set font, set font size and
set text to bold, underline and italics.

Now here is what got me stuck for about a week :

I''m unable to add the Info-Group with some Items ({\Info {Itm1}...{ItmN}}

I do :

rtf.AddText("*");
string strRtf = Rtf;


strRtf looks like this (A):

{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1031<br />
	{\\fonttbl{\\f0\\fnil\\fcharset0 Microsoft Sans Serif;}}\r\n<br />
	\\viewkind4\\uc1\\pard\\f0\\fs17<br />
 	 *\\par\r\n}\r\n"



after inserting the Info-Group with the item ''nofpages1'' strRtf looks like this (B):

{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1031<br />
	{\\fonttbl{\\f0\\fnil\\fcharset0 Microsoft Sans Serif;}}\r\n<br />
	{\\Info{\\nofpages1}}<br />
	\\viewkind4\\uc1\\pard\\f0\\fs17<br />
	 *\\par\r\n}\r\n"


but after

Rtf = strRtf


Rtf hasn''t changed and still looks like (A)

what am I doing wrong here ?
so far google was of no help at all

thanks in advance

解决方案

You are entering very tedious and error-prone work on a pretty much obsolete text format. I don''t understand why doing that. In the very beginning, you mention that you only need to create a report. This is much easier, because you would not need to dig into RTF markup directly, but only format the fragments of text using the API through one or another RichTextBox classes.

If, by some weird reason, you really need to bite the bullet, read the reference on all the syntax:
http://msdn.microsoft.com/en-us/library/aa140280%28office.10%29.aspx[^],
http://www.microsoft.com/en-us/download/details.aspx?id=10725[^],
http://interglacial.com/rtf/[^].

But why?

—SA


这篇关于编辑RichText Document的RTF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆