Board index » delphi » Save formatted text from RichEdit to rtf-file

Save formatted text from RichEdit to rtf-file

Hello!

I hope you can help me with this. I want to save text that is formatted
froom a RichEdit or DBRichEdit to a rtf-file. RichEdit.Lines.SaveToFile only
saves the text, not the formatting. How can I save the text to a true
rtf-format that can be used in Word.

Thanks in advance,
Klas

--
*******************************************
Klas Westholm
DataKatten
Lingonstigen 3 B
271 38 Ystad
Tel: 0411-732 73, 0411-107 55
Mobil: 070-789 17 53
E-post: Klas.Westh...@datakatten.se
Hemsida: http://www.datakatten.se

 

Re:Save formatted text from RichEdit to rtf-file


Quote
"Klas Westholm" <Klas.Westh...@telia.com> wrote in message

news:3ecb6b2e@newsgroups.borland.com...

Quote
> Hello!

> I hope you can help me with this. I want to save text that is formatted
> froom a RichEdit or DBRichEdit to a rtf-file. RichEdit.Lines.SaveToFile
only
> saves the text, not the formatting. How can I save the text to a true
> rtf-format that can be used in Word.

Try setting the control's PlainText property to False.

HTH,
Ian

Re:Save formatted text from RichEdit to rtf-file


Sorry, but it didn't work. I had this setting before. Do you have any other
suggestions?

Yours,
Klas

--
*******************************************
Klas Westholm
DataKatten
Lingonstigen 3 B
271 38 Ystad
Tel: 0411-732 73, 0411-107 55
Mobil: 070-789 17 53
E-post: Klas.Westh...@datakatten.se
Hemsida: http://www.datakatten.se
"Ian Kirk" <i...@kel.deletethisbit.co.uk> skrev i meddelandet
news:3ecb7fe0@newsgroups.borland.com...

Quote
> "Klas Westholm" <Klas.Westh...@telia.com> wrote in message
> news:3ecb6b2e@newsgroups.borland.com...
> > Hello!

> > I hope you can help me with this. I want to save text that is formatted
> > froom a RichEdit or DBRichEdit to a rtf-file. RichEdit.Lines.SaveToFile
> only
> > saves the text, not the formatting. How can I save the text to a true
> > rtf-format that can be used in Word.

> Try setting the control's PlainText property to False.

> HTH,
> Ian

Re:Save formatted text from RichEdit to rtf-file


Quote
> E-post: Klas.Westh...@datakatten.se
> Hemsida: http://www.datakatten.se
> "Ian Kirk" <i...@kel.deletethisbit.co.uk> skrev i meddelandet
> news:3ecb7fe0@newsgroups.borland.com...
> > "Klas Westholm" <Klas.Westh...@telia.com> wrote in message
> > news:3ecb6b2e@newsgroups.borland.com...
> > > Hello!

> > > I hope you can help me with this. I want to save text that is
formatted
> > > froom a RichEdit or DBRichEdit to a rtf-file.

RichEdit.Lines.SaveToFile

Quote
> > only
> > > saves the text, not the formatting. How can I save the text to a true
> > > rtf-format that can be used in Word.

> > Try setting the control's PlainText property to False.

> Sorry, but it didn't work. I had this setting before. Do you have any
other
> suggestions?

Bottom posting? :-)

Coming back to the problem in hand, I've just created a new default app,
added a TRichEdit to it (which has PlainText = False by default) and put
this code in FormCreate:

procedure TForm1.FormCreate(Sender: TObject);
begin
  RichEdit1.Text := '' ;
  RichEdit1.SelText := 'Some ' ;

  RichEdit1.SelAttributes.Style := [fsBold] ;
  RichEdit1.SelText := 'bold' ;

  RichEdit1.SelAttributes.Style := [] ;
  RichEdit1.SelText := ' text' ;

  RichEdit1.Lines.SaveToFile('C:\Test.rtf');
end;

Run the program, checked the contents of C:\Test.rtf and it held:

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil MS Sans Serif;}}
\viewkind4\uc1\pard\f0\fs16 Some \b bold\b0  text
\par }

Can you try doing the same?  If you get non-RTF in your Test.rtf there's
clearly something significantly different about our systems.  If you do get
RTF there's some subtle code-related issue in your main app you'll need to
pin down.

HTH,
Ian

Re:Save formatted text from RichEdit to rtf-file


Klas

If Ian's suggestion doesn't work on your machine for some reason try this:

Copy the contents of the richedit to a TMemorystream
(Trichedit.lines.savetostream method)
Then save the stream to a file (TMemorystream.savetofile).

As far as I know, both Ian's suggestion and the above should save the RTF
format.

Mike

Quote
"Klas Westholm" <Klas.Westh...@telia.com> wrote in message

news:3ecc8d61$1@newsgroups.borland.com...
Quote
> Sorry, but it didn't work. I had this setting before. Do you have any
other
> suggestions?

> Yours,
> Klas

> --
> *******************************************
> Klas Westholm
> DataKatten
> Lingonstigen 3 B
> 271 38 Ystad
> Tel: 0411-732 73, 0411-107 55
> Mobil: 070-789 17 53
> E-post: Klas.Westh...@datakatten.se
> Hemsida: http://www.datakatten.se
> "Ian Kirk" <i...@kel.deletethisbit.co.uk> skrev i meddelandet
> news:3ecb7fe0@newsgroups.borland.com...
> > "Klas Westholm" <Klas.Westh...@telia.com> wrote in message
> > news:3ecb6b2e@newsgroups.borland.com...
> > > Hello!

> > > I hope you can help me with this. I want to save text that is
formatted
> > > froom a RichEdit or DBRichEdit to a rtf-file.

RichEdit.Lines.SaveToFile

- Show quoted text -

Quote
> > only
> > > saves the text, not the formatting. How can I save the text to a true
> > > rtf-format that can be used in Word.

> > Try setting the control's PlainText property to False.

> > HTH,
> > Ian

Re:Save formatted text from RichEdit to rtf-file


Thank you Mike and Ian!

Both suggestions worked with RichEdit. Now a new question:

I want to do the same with a DBRichEdit. I can change the text alright
(bold, color, size, and so on), but when I save to file (either with
lines.savetofile or streams.savetofile) formatting is lost. (It doesn't
matter if the text is saved to the DB first or if I am in Edit-mode or not).

Yours,
Klas
--
"Mike Manning" <NOMORES...@nowhere.com.au> skrev i meddelandet
news:3eccaf36$1@newsgroups.borland.com...

Quote
> Klas

> If Ian's suggestion doesn't work on your machine for some reason try this:

> Copy the contents of the richedit to a TMemorystream
> (Trichedit.lines.savetostream method)
> Then save the stream to a file (TMemorystream.savetofile).

> As far as I know, both Ian's suggestion and the above should save the RTF
> format.

> Mike

Re:Save formatted text from RichEdit to rtf-file


Thank you Mike and Ian!

Both suggestions worked with RichEdit. Now a new question:

I want to do the same with a DBRichEdit. I can change the text alright
(bold, color, size, and so on), but when I save to file (either with
lines.savetofile or streams.savetofile) formatting is lost. (It doesn't
matter if the text is saved to the DB first or if I am in Edit-mode or not).

Yours,
Klas

Quote
> If Ian's suggestion doesn't work on your machine for some reason try this:

> Copy the contents of the richedit to a TMemorystream
> (Trichedit.lines.savetostream method)
> Then save the stream to a file (TMemorystream.savetofile).

> As far as I know, both Ian's suggestion and the above should save the RTF
> format.

> Mike

 > > I hope you can help me with this. I want to save text that is
formatted
Quote
> > > froom a RichEdit or DBRichEdit to a rtf-file.

RichEdit.Lines.SaveToFile

Quote
> > only
> > > saves the text, not the formatting. How can I save the text to a true
> > > rtf-format that can be used in Word.

> > Try setting the control's PlainText property to False.

> Sorry, but it didn't work. I had this setting before. Do you have any
other
> suggestions?

Bottom posting? :-)

Coming back to the problem in hand, I've just created a new default app,
added a TRichEdit to it (which has PlainText = False by default) and put
this code in FormCreate:

procedure TForm1.FormCreate(Sender: TObject);
begin
  RichEdit1.Text := '' ;
  RichEdit1.SelText := 'Some ' ;

  RichEdit1.SelAttributes.Style := [fsBold] ;
  RichEdit1.SelText := 'bold' ;

  RichEdit1.SelAttributes.Style := [] ;
  RichEdit1.SelText := ' text' ;

  RichEdit1.Lines.SaveToFile('C:\Test.rtf');
end;

Run the program, checked the contents of C:\Test.rtf and it held:

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil MS Sans Serif;}}
\viewkind4\uc1\pard\f0\fs16 Some \b bold\b0  text
\par }

Can you try doing the same?  If you get non-RTF in your Test.rtf there's
clearly something significantly different about our systems.  If you do get
RTF there's some subtle code-related issue in your main app you'll need to
pin down.

HTH,
Ian

--
*******************************************
Klas Westholm
DataKatten
Lingonstigen 3 B
271 38 Ystad
Tel: 0411-732 73, 0411-107 55
Mobil: 070-789 17 53
E-post: Klas.Westh...@datakatten.se
Hemsida: http://www.datakatten.se

Other Threads