На страницу разработчика                                            Есть ещё вопросы? Задавайте их экспертам. Регистрация На RFPro.ru   

Вставка графических объектов в документ MSWord средствами Delphi.

Пример добавления графических объектов в документ MSWord приведу в  следующем фрагменте кода:

 

...

const

msoShapeRectangle = 1;

 

begin

...

Word:= CreateOleObject('Word.Application');
Word.Visible:= True;
Doc:= Word.Documents.Open('C:\My_Doc\1.doc');
Doc.Shapes.AddShape(msoShapeRectangle, 5, 5, 20, 30, EmptyParam );

...

Рассмотрим метод AddShape. Метод AddShape коллекции Shapes используется для создания геометрических фигур.

Общее описание метода: AddShape(Type_: integer, Left, Top, Width, Height: Extended, Anchor: OleVariant)

Первый аргумент представляет собой целое число и определяет тип создаваемого объекта, например Туре_ = 1 соответствует прямоугольнику. Возможные типы фигур, поддерживаемых методом AddShape в версии Delphi7 описаны в модуле OfficeXP.pas. Аргументы Left, Top, Width, Height - числа, имеющие тип Extended и определяют соответственно отступ справа, отступ сверху, ширину и высоту создаваемого объекта. Аргумент Anchor, объект типа OleVariant, определяющий область, где будет создан объект.

Ниже приведу код модуля, рисующего все объекты по очереди в документе.

...

uses ... ComObj;

...

procedure TForm1.Button1Click(Sender: TObject);
var
Word, Doc: variant;
count: OleVariant;
i: integer;

const
wdCharacter = 1;
wdLine = 5;
wdMove = 0;

begin
Word:= CreateOleObject('Word.Application');
Word.Visible:= True;
Doc:= Word.Documents.Open('C:\My_Doc\1.doc');
Doc.Shapes.AddShape(137, 0, 0, 30, 30, EmptyParam );
Word.Selection.Collapse(EmptyParam);
count:= 4;
  for i:= 136 downto 1 do
  begin
  Word.Selection.TypeParagraph;
  Word.Selection.TypeParagraph;
  Word.Selection.TypeParagraph;
  Word.Selection.MoveUp(wdLine, count, wdMove);
    try
    Doc.Shapes.AddShape(i, 0, 0, 30, 30, EmptyParam );
    except
    Showmessage(IntToStr(i));
    end;


  end;
Doc.Save;
Doc.Close;
Word.Quit; Word:= UnAssigned;
Word:= null;
end;
...

 

Основные значения переменной Type_ и соответствующие рисунки приведены в таблице:

 

Переменная модуля OfficeXP.pas

 Значение

Рисунок

msoShapeRectangle

 $00000001;

msoShapeParallelogram

 $00000002;

 

msoShapeTrapezoid

 $00000003;

 

msoShapeDiamond

 $00000004;

 

msoShapeRoundedRectangle

 $00000005;

 

msoShapeOctagon

 $00000006;

 

msoShapeIsoscelesTriangle

 $00000007;

 

msoShapeRightTriangle

 $00000008;

 

msoShapeOval

 $00000009;

 

msoShapeHexagon

 $0000000A;

 

msoShapeCross

 $0000000B;

 

msoShapeRegularPentagon

 $0000000C;

 

msoShapeCan

 $0000000D;

 

msoShapeCube

 $0000000E;

 

msoShapeBevel

 $0000000F;

 

msoShapeFoldedCorner

 $00000010;

 

msoShapeSmileyFace

 $00000011;

 

msoShapeDonut

 $00000012;

 

msoShapeNoSymbol

 $00000013;

 

msoShapeBlockArc

 $00000014;

 

msoShapeHeart

 $00000015;

 

msoShapeLightningBolt

 $00000016;

 

msoShapeSun

 $00000017;

 

msoShapeMoon

 $00000018;

 

msoShapeArc

 $00000019;

 

msoShapeDoubleBracket

 $0000001A;

 

msoShapeDoubleBrace

 $0000001B;

 

msoShapePlaque

 $0000001C;

 

msoShapeLeftBracket

 $0000001D;

 

msoShapeRightBracket

 $0000001E;

 

msoShapeLeftBrace

 $0000001F;

 

msoShapeRightBrace

 $00000020;

 

msoShapeRightArrow

 $00000021;

 

msoShapeLeftArrow

 $00000022;

 

msoShapeUpArrow

 $00000023;

 

msoShapeDownArrow

 $00000024;

 

msoShapeLeftRightArrow

 $00000025;

 

msoShapeUpDownArrow

 $00000026;

 

msoShapeQuadArrow

 $00000027;

 

msoShapeLeftRightUpArrow

 $00000028;

 

msoShapeBentArrow

 $00000029;

 

msoShapeUTurnArrow

 $0000002A;

 

msoShapeLeftUpArrow

 $0000002B;

 

msoShapeBentUpArrow

 $0000002C;

 

msoShapeCurvedRightArrow

 $0000002D;

 

msoShapeCurvedLeftArrow

 $0000002E;

 

msoShapeCurvedUpArrow

 $0000002F;

 

msoShapeCurvedDownArrow

 $00000030;

 

msoShapeStripedRightArrow

 $00000031;

 

msoShapeNotchedRightArrow

 $00000032;

 

msoShapePentagon

 $00000033;

 

msoShapeChevron

 $00000034;

 

msoShapeRightArrowCallout

 $00000035;

 

msoShapeLeftArrowCallout

 $00000036;

 

msoShapeUpArrowCallout

 $00000037;

 

msoShapeDownArrowCallout

 $00000038;

 

msoShapeLeftRightArrowCallout

 $00000039;

 

msoShapeUpDownArrowCallout

 $0000003A;

 

msoShapeQuadArrowCallout

 $0000003B;

 

msoShapeCircularArrow

 $0000003C;

 

msoShapeFlowchartProcess

 $0000003D;

 

msoShapeFlowchartAlternateProcess

 $0000003E;

 

msoShapeFlowchartDecision

 $0000003F;

 

msoShapeFlowchartData

 $00000040;

 

msoShapeFlowchartPredefinedProcess

 $00000041;

 

msoShapeFlowchartInternalStorage

 $00000042;

 

msoShapeFlowchartDocument

 $00000043;

 

msoShapeFlowchartMultidocument

 $00000044;

 

msoShapeFlowchartTerminator

 $00000045;

 

msoShapeFlowchartPreparation

 $00000046;

 

msoShapeFlowchartManualInput

 $00000047;

 

msoShapeFlowchartManualOperation

 $00000048;

 

msoShapeFlowchartConnector

 $00000049;

 

msoShapeFlowchartOffpageConnector

 $0000004A;

 

msoShapeFlowchartCard

 $0000004B;

 

msoShapeFlowchartPunchedTape

 $0000004C;

 

msoShapeFlowchartSummingJunction

 $0000004D;

 

msoShapeFlowchartOr

 $0000004E;

 

msoShapeFlowchartCollate

 $0000004F;

 

msoShapeFlowchartSort

 $00000050;

 

msoShapeFlowchartExtract

 $00000051;

 

msoShapeFlowchartMerge

 $00000052;

 

msoShapeFlowchartStoredData

 $00000053;

 

msoShapeFlowchartDelay

 $00000054;

 

msoShapeFlowchartSequentialAccessStorage

 $00000055;

 

msoShapeFlowchartMagneticDisk

 $00000056;

 

msoShapeFlowchartDirectAccessStorage

 $00000057;

 

msoShapeFlowchartDisplay

 $00000058;

 

msoShapeExplosion1

 $00000059;

 

msoShapeExplosion2

 $0000005A;

 

msoShape4pointStar

 $0000005B;

 

msoShape5pointStar

 $0000005C;

 

msoShape8pointStar

 $0000005D;

 

msoShape16pointStar

 $0000005E;

 

msoShape24pointStar

 $0000005F;

 

msoShape32pointStar

 $00000060;

 

msoShapeUpRibbon

 $00000061;

 

msoShapeDownRibbon

 $00000062;

 

msoShapeCurvedUpRibbon

 $00000063;

 

msoShapeCurvedDownRibbon

 $00000064;

 

msoShapeVerticalScroll

 $00000065;

 

msoShapeHorizontalScroll

 $00000066;

 

msoShapeWave

 $00000067;

 

msoShapeDoubleWave

 $00000068;

 

msoShapeRectangularCallout

 $00000069;

 

msoShapeRoundedRectangularCallout

 $0000006A;

 

msoShapeOvalCallout

 $0000006B;

 

msoShapeCloudCallout

 $0000006C;

 

msoShapeLineCallout1

 $0000006D;

 

msoShapeLineCallout2

 $0000006E;

 

msoShapeLineCallout3

 $0000006F;

 

msoShapeLineCallout4

 $00000070;

 

msoShapeLineCallout1AccentBar

 $00000071;

 

msoShapeLineCallout2AccentBar

 $00000072;

 

msoShapeLineCallout3AccentBar

 $00000073;

 

msoShapeLineCallout4AccentBar

 $00000074;

 

msoShapeLineCallout1NoBorder

 $00000075;

 

msoShapeLineCallout2NoBorder

 $00000076;

 

msoShapeLineCallout3NoBorder

 $00000077;

 

msoShapeLineCallout4NoBorder

 $00000078;

 

msoShapeLineCallout1BorderandAccentBar

 $00000079;

 

msoShapeLineCallout2BorderandAccentBar

 $0000007A;

 

msoShapeLineCallout3BorderandAccentBar

 $0000007B;

 

msoShapeLineCallout4BorderandAccentBar

 $0000007C;

 

msoShapeActionButtonCustom

 $0000007D;

 

msoShapeActionButtonHome

 $0000007E;

 

msoShapeActionButtonHelp

 $0000007F;

 

msoShapeActionButtonInformation

 $00000080;

 

msoShapeActionButtonBackorPrevious

 $00000081;

 

msoShapeActionButtonForwardorNext

 $00000082;

 

msoShapeActionButtonBeginning

 $00000083;

 

msoShapeActionButtonEnd

 $00000084;

 

msoShapeActionButtonReturn

 $00000085;

 

msoShapeActionButtonDocument

 $00000086;

 

msoShapeActionButtonSound

 $00000087;

 

msoShapeActionButtonMovie

 $00000088;

 

msoShapeBalloon

 $00000089;

 

msoShapeNotPrimitive

 $0000008A;

 

Удачи в разработке приложений.



Hosted by uCoz