Reputation:
I have an OLEContainer object, in which I create Word.Document, to allow to edit formulas and other.
How do I set OLEContainer height to height of actual data?
Upvotes: 1
Views: 248
Reputation:
OleContainer has SizeMode property than can be set to smAutoSize. Too easy.
Upvotes: 2
Reputation: 30735
If you are using a TOleContainer, once you activate MS Word in it you can easily obtain an reference to the MS Word Automation object like this:
MSWord := OleContainer1.OleObject;
So far, so simple.
The next step is to try to get a number which represents the height of the Word document open in the MSWord object. The problem with that is that the structure of the document is potentially so complex, and there are so many variables to take into account (font size, inter-paragraph spacing etc) that I can't think of a simple way to obtain an exact number.
However, a simple-minded way to approach the problem is to get a number for the number of lines in the document and then scale the OleContainer's height by a multiplier of that value; The method below will obtain the count of the number of lines in the document (or its main text, at any rate) and you could then adjust the container's height based on that;
procedure TForm1.GetLinesInDocument;
var
Lines : Integer;
MSWord,
vDialog : OleVariant;
begin
MSWord := OleContainer.OleObject;
vDialog := MSword.Dialogs.Item(wdDialogToolsWordCount); // this Dialog returns the number of
// lines in the document
vDialog.Execute; // This executes the Dialog function without causing
// it to display
Lines := vDialog.Lines;
Caption := 'Lines: ' + IntToStr(Lines);
end;
Obviously some experiment would be necessary to determine the scale factor.
Good luck!
Upvotes: 0