Board index » delphi » Help with headers/footers Please ?

Help with headers/footers Please ?

My problem is that I need to insert the contents of a richtextbox in Delphi into an open Word document (.rtf), which works fine except that when using "rtfbox.Lines.savetoFile();"
overwrites the comlete content of my document destroying all previously existing graphics headers and footers in the document. Strangely the same thing seems to happen when I open
the document in Word and paste the content of the richtextbox into the open document.
Can anyone show me a way to keep my headers/footers or to create new ones
after pasting?

Thanks
Maxx

P.S.:
Thanks Debbie for showing me the way inside,
I am behind a firewall, already wondered why
no one answered.

 

Re:Help with headers/footers Please ?


Quote
Marcus Reisinger <marcus.reisin...@noevers.at> wrote in message

news:3b5beccc$1_1@dnews...
Quote

> My problem is that I need to insert the contents of a richtextbox in

Delphi into an open Word document (.rtf), which works fine except that when
using "rtfbox.Lines.savetoFile();"
Quote
> overwrites the comlete content of my document destroying all previously

existing graphics headers and footers in the document. Strangely the same
thing seems to happen when I open

Quote
> the document in Word and paste the content of the richtextbox into the
open document.
> Can anyone show me a way to keep my headers/footers or to create new ones
> after pasting?

> Thanks
> Maxx

> P.S.:
> Thanks Debbie for showing me the way inside,
> I am behind a firewall, already wondered why
> no one answered.

In MS-Word there is an option for inserting files, I think you'd be better
off using that so the current page format should not change.  The only thing
you need to do is placing the cursor in the right location and insert the
object (in your case file).

regards,

Re:Help with headers/footers Please ?


<<Marcus Reisinger:
"rtfbox.Lines.savetoFile();"
overwrites the comlete content of my document

Quote

Um, well, it would, wouldn't it? I don't really understand
why you're doing that - perhaps if you post more code I'll
see the light. :)

Here are a couple of ways to access a header or footer),
just in case it's useful:
  Doc.Sections.Item(1).Headers.Item(
       wdHeaderFooterPrimary).PageNumbers.Add(
                               Alignment, EmptyParam);
  Doc.StoryRanges.Item(wdPrimaryFooterStory).Text :=
          'Here is a footer';

<<Marcus:
Strangely the same thing seems to happen when I open
the document in Word and paste

Quote

Pasting will always overwrite the content of the range or
selection pasted to. So to stop your work being
overwritten, you have to make sure it isn't included in the
range, by using the Range.Collapse method first.

  Direction := wdCollapseEnd;
  R := Doc.Range;
  R.Collapse(Direction);
  R.Paste;

<<Marcus:
Thanks Debbie for showing me the way inside,

Quote

Glad you got through. Even though you called me Debbie
(ack!). :)

--
Deborah Pate (TeamB) http://delphi-jedi.org

  Use Borland servers; TeamB don't see posts via ISPs
  http://www.borland.com/newsgroups/genl_faqs.html

Re:Help with headers/footers Please ?


"Deborah Pate (TeamB)" <d.p...@cableinet.co.not-this-bit.uk> wrote:

Quote
><<Marcus Reisinger:
>"rtfbox.Lines.savetoFile();"
>overwrites the comlete content of my document

>Um, well, it would, wouldn't it? I don't really understand
>why you're doing that - perhaps if you post more code I'll
>see the light. :)

Well, first thanks very much for the help to both of my
responders!
Second, I did this for reasons of speed, cause it's always
very much faster to replace variables or parts of the text
inside the Delphi program instead of passing each change
over to Word. Besides, my users wish to have an extremely
fast preview of the document without starting Word.
Here's the code:
//Replaces text inside a richtextbox
function FFreplaceVars(varname,vartext,ctrltype: String): Boolean;
Var selstart,sellen: Integer;
    FindTxt: String;
begin
//Spezialit?t fr Inkassobriefe
If (varname = 'i.V. Reitermayer e.h./') Then Findtxt := varname
                                        Else Findtxt := '?' + varname + '?';
vartext := replaceNewlines(vartext);
sellen := Length(brieffrm.fastviewmemo.Text);
selstart := brieffrm.fastviewmemo.FindText(Findtxt,0,sellen,[]);
While (selstart <> - 1) do begin
   brieffrm.fastviewmemo.SelStart := selstart;
   If (ctrltype = 'CHECK') and (vartext = '') Then
      brieffrm.fastviewmemo.SelLength := Length(Findtxt) + 1
                                              Else
      brieffrm.fastviewmemo.SelLength := Length(Findtxt);
   brieffrm.fastviewmemo.SelText := vartext;
   FFReplacevars := True;
   sellen := Length(brieffrm.fastviewmemo.Text);
   //wenn i.V. ersetzt wurde mu? selstart -1 gesetzt werden, sonst Endlosschleife
   If (Findtxt <> 'i.V. Reitermayer e.h./') Then
      selstart := brieffrm.fastviewmemo.FindText(Findtxt,0,sellen,[])
                                            else selstart := - 1;
                           end;
end;
Quote
>Here are a couple of ways to access a header or footer),
>just in case it's useful:
>  Doc.Sections.Item(1).Headers.Item(
>       wdHeaderFooterPrimary).PageNumbers.Add(
>                               Alignment, EmptyParam);
>  Doc.StoryRanges.Item(wdPrimaryFooterStory).Text :=
>          'Here is a footer';

><<Marcus:
>Strangely the same thing seems to happen when I open
>the document in Word and paste

>Pasting will always overwrite the content of the range or
>selection pasted to. So to stop your work being
>overwritten, you have to make sure it isn't included in the
>range, by using the Range.Collapse method first.

>  Direction := wdCollapseEnd;
>  R := Doc.Range;
>  R.Collapse(Direction);
>  R.Paste;

><<Marcus:
>Thanks Debbie for showing me the way inside,

>Glad you got through. Even though you called me Debbie
>(ack!). :)

>--
>Deborah Pate (TeamB) http://delphi-jedi.org

>  Use Borland servers; TeamB don't see posts via ISPs
>  http://www.borland.com/newsgroups/genl_faqs.html

Other Threads