Fórum Delphi e Word #180334

06/09/2003

0

Caro Colegas:

Peço ajuda a todos nesta questão:

Estou pasando os dados de uma tabela para o word, e tenho um problema nesta linha...

MSWord.FontSize(14);//muda o tamanho da fonte
MSWord.bold;//coloca negrito
{aqui eu não sei como centralizar o titulo como veem estou usando outro recurso como #13+9...}
MSWord.insert(13+9+9+9+9+dm.TbReTITULO.Value);

Gostaria de saber se existe algo tipo MSword.text.center ou algo assim.

Outro coisa minha tabela tem figuras (campo blob interbase) e não estou conseguindo importar para o word, já procurei e não encontrei algo sobre o assunto, por isso peço ajuda a todos. obrigado. [color=blue:ddb5b1c67f][/color:ddb5b1c67f] :roll:


Rocsadan

Rocsadan

Responder

Posts

06/09/2003

Aroldo Zanela

Colega,

Encontrei algo que poderá lhe ajudar:

[quote:555717fab8=´Deborah Pate (TeamB)´]
I don´t know what example that was, but I think you should
throw it away and start again. In brief, the main causes of
your problems are that you set the font of the last
sentence before you have entered one; you use several
different ranges to change the format, but sometimes the
WordDocument.Range property, which always applies to the
whole document. And I am not sure what you´re trying to do
with the ranges you yourself set up (rather peculiarly).

Let me explain a bit about ranges - sorry for the bits you
already know. A range is a bit of a document. Lots of
objects in Word - documents, sections, paragraphs, etc -
have range properties, and you can use these to change
standard properties, like the font, of all of these
objects. So
Document.Range.Font.Underline := wdUnderlineDouble;
will make the whole document double underlined, whereas
Doc.Paragraphs.Item(1).Range.Font.Underline
:= wdUnderlineDouble;
will make only the first paragraph of the document double
underlined.

As well as using these predefined ranges, you can create
your own ranges, covering just the bits of the document you
want to affect. For example, to make the first 3 paragraphs
underlined, you could do:

var
R: Range;
...
R := Doc.Paragraphs.Item(1).Range;
R.End_ := Doc.Paragraphs.Item(3).Range.End_;
R.Font.Underline := wdUnderlineDouble;

You can also use ranges to enter text.
R := Doc.Range;
R.Text := ´I have deleted everything you just wrote´;
will replace any text in the range with the text you
specify. But you can use the InsertAfter and InsertBefore
methods to avoid that:
R := Doc.Range;
R.InsertAfter(´This will appear at the end of the
document´);
R.InsertParagraphAfter;

After using these methods, your Range variable has expanded
to include the added text. So if you then do
R.Font.Underline := wdUnderlineDouble;
the whole document, including the text you added, will be
underlined. That means that the formatting in this code is
useless:
R.InsertAfter(´This will be underlined´);
R.InsertParagraphAfter;
R.Font.Underline := wdUnderlineDouble;
R.InsertAfter(´Oh no it won´´t´);
R.InsertParagraphAfter;
R.Font.Underline := wdUnderlineNone;
The second call to underline simply undoes the first one.
To change font settings as you type, you need to use the
Collapse method, so that the range doesn´t refer to the
whole document any more:

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

{ R now refers to a range of zero length,
at the end of the document }
R.InsertAfter(´This will be underlined´);
R.InsertParagraphAfter;
{ R now refers just to the paragraph we just inserted }
R.Font.Underline := wdUnderlineDouble;

R.Collapse(Direction);
{ R now refers to a range of zero length,
at the end of the document }
R.InsertAfter(´Yes, but this line won´´t be´);
R.InsertParagraphAfter;
{ R now refers just to the paragraph we just inserted }
R.Font.Underline := wdUnderlineNone;

Miscellaneous tips:
1) The ´law of Demeter´ (basically, use as few dots in your
code as possible) is especially important in automation,
where each dot represents a time-consuming cross-process
call. Use local variables, such as R in the examples above,
to avoid them.

2) Don´t use the TWordFont component, it´s pointless
overhead, since there are no events for it. Just use a
_Font variable:
WordFont: _Font;
...
WordFont := Doc.Range.Font;

Finally: your code obviously won´t compile on my machine,
since I don´t have the data or the checkboxes set up. But
here an adaptation of it that might help you:

const
Heading = ´This is a heading´;
BodyText = ´This is body text´;
var
Direction: OleVariant;
R: Range;
i: integer;

procedure SetHeaderFont(const R: Range);
var
WordFont: _Font;
begin
WordFont := R.Font;
WordFont.Bold := 1;
WordFont.Italic := 1;
WordFont.Size := 17;
WordFont.Name := ´Arial´;
end;

procedure SetTextFont(const R: Range);
var
WordFont: _Font;
begin
WordFont := R.Font;
WordFont.Bold := 0;
WordFont.Italic := 0;
WordFont.Size := 10;
WordFont.Name := ´Georgia´;
end;

begin
Word.Visible := True;
Word.ScreenUpdating := False;
Word.Options.CheckSpellingAsYouType := False;
Word.Options.CheckGrammarAsYouType := False;
Word.Caption := ´Nouveau bulletin de documentation´;
Word.Documents.Add(EmptyParam, EmptyParam);
Doc.ConnectTo(Word.ActiveDocument);

R := Doc.Range;
Direction := wdCollapseEnd;
R.Collapse(Direction);
R.ParagraphFormat.Alignment := wdAlignParagraphCenter;
R.InsertAfter(´SUJET : ´ + Heading);
R.InsertParagraphAfter;
R.InsertAfter(´SUJET : ´ + Heading);
R.InsertParagraphAfter;
SetHeaderFont(R);

R.Collapse(Direction);
R.Paragraphs.Alignment := wdAlignParagraphJustify;
R.InsertAfter(BodyText);
R.InsertParagraphAfter;
R.InsertParagraphAfter;
SetTextFont(R);

R.Collapse(Direction);
R.InsertAfter(BodyText);
R.Font.Italic := 1;

R.InsertParagraphAfter;
R.InsertParagraphAfter;
R.Collapse(Direction);
R.ParagraphFormat.Alignment := wdAlignParagraphCenter;
R.InsertAfter(´ ---oooOooo--- ´);
R.InsertParagraphAfter;
Word.ScreenUpdating := True;

--
Deborah Pate (TeamB) http://delphi-jedi.org
[/quote:555717fab8]


Responder

Gostei + 0

06/09/2003

Rocsadan

Valeu, Obrigado. :lol:


Responder

Gostei + 0

06/09/2003

Rocsadan

A parte do alinhamento, centralização eoutros eu resolvi com:

LeftPara. JustifyPara etc...

Só me resta inserir do delphi as figuras para word.

De um image ou dbimage, ou ainda de um campo blob imagem do interbase oriundo da tabela.

Grato. :?:


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar