Crear un documento.
Hacer visible un documento.
Añadir un documento.
Insertar texto en...
Graba un documento.
Cierra un documento.
Abre un documento.
Cursor al principio de ...
Encuentra texto.
Pega texto.
Encuentra y Pega texto.
Abre el diálogo de la impresora.
Crea una tabla.
Dimensiona una tabla.
Tamaño de la tabla.
Pon texto en la tabla.
Mezcla celdas.
Selecciona celdas de una tabla.
Ir a la siguiente o anterior tabla.
Obtiene las columnas de una tabla.
Añade una fila a una tabla.
Crea una caja de texto.
Obtiene el índice de la forma gráfica.
Pone el nombre a un shape.
Crea una línea.
Crea una imagen.
Borra un shape.
Crea un documento Word:
uses ComObj;
procedure TForm1.Button1Click(Sender: TObject);
var
MSWord: Variant;
begin
try
MsWord := GetActiveOleObject('Word.Application');
except
try
MsWord := CreateOleObject('Word.Application');
MsWord.Visible := True;
except
Exception.Create('Error');
end;
end;
MSWord.Documents.Add;
MSWord.Selection.Font.Size := 12;
MSWord.Selection.TypeText('Arial');
MSWord.Selection.Font.Bold := true;
MSWord.Selection.TypeText(#13#10'new');
MSWord.ActiveDocument.SaveAs('C:\doc1.doc');
end;
Hacer visible un documento
Function VisibleWord (visible:boolean):boolean;
begin
VisibleWord:=true;
try
W.visible:= visible;
except
VisibleWord:=false;
end;
End;
Añadir un documento
Function AddDoc:boolean;
Var Doc_:variant;
begin
AddDoc:=true;
try
Doc_:=W.Documents;
Doc_.Add;
except
AddDoc:=false;
end;
End;
Function SetTextToDoc(text_: string;InsertAfter_: boolean): boolean;
var Rng_:variant;
begin
SetTextToDoc:=true;
try
Rng_:=W.ActiveDocument.Range;
if InsertAfter_
then Rng_.InsertAfter(text_)
else Rng_.InsertBefore(text_);
except
SetTextToDoc:=false;
end;
End;
En esta función, se usa el objeto Range y sus métodos InsertBefore InsertAfter para insertar texto en el documento en la posición del cursor.
if InsertAfter_
then W.ActiveDocument.Range. InsertAfter(text_)
else W.ActiveDocument.Range. InsertBefore(text_);
Graba un documento:
Function SaveDocAs(file_:string):boolean;
begin
SaveDocAs:=true;
try
W.ActiveDocument.SaveAs(file_);
except
SaveDocAs:=false;
end;
End;
Cierra un documento:
Function CloseDoc:boolean;
begin
CloseDoc:=true;
try
W.ActiveDocument.Close;
except
CloseDoc:=false;
end;
End;
Abre un documento:
var
Doc_:=W.Documents;
Doc_.Open(file_);
Function OpenDoc (file_:string):boolean;
Var
Doc_:variant;
begin
OpenDoc:=true;
try
Doc_:=W.Documents;
Doc_.Open(file_);
except
OpenDoc:=false;
end;
End;
Cursor al principio de ...
Function StartOfDoc:boolean;
begin
StartOfDoc:=true;
try
W.Selection.End:=0;
W.Selection.Start:=0;
except
StartOfDoc:=false;
end;
End;
Encuentra texto:
Function FindTextDoc (text_:string):boolean;
begin
FindTextDoc:=true;
Try
W.Selection.Find.Forward:=true;
W.Selection.Find.Text:=text_;
FindTextDoc := W.Selection.Find.Execute;
except
FindTextDoc:=false;
end;
End;
Pega texto:
Function PasteTextDoc (text_:string):boolean;
begin
PasteTextDoc:=true;
Try
W.Selection.Delete;
W.Selection.InsertAfter (text_);
except
PasteTextDoc:=false;
end;
End;
Encuentra y Pega texto:
Function FindAndPasteTextDoc
(findtext_,pastetext_:string): boolean;
begin
FindAndPasteTextDoc:=true;
try
W.Selection.Find.Forward:=true;
W.Selection.Find.Text:= findtext_;
if
W.Selection.Find.Execute then
begin
W.Selection.Delete;
W.Selection.InsertAfter (pastetext_);
end
else
FindAndPasteTextDoc:=false;
except
FindAndPasteTextDoc:=false;
end;
End;
Abre el diálogo de la impresora:
Function PrintDialogWord:boolean;
Const wdDialogFilePrint=88;
begin
PrintDialogWord:=true;
try
W.Dialogs.Item(wdDialogFilePrint).Show;
except
PrintDialogWord:=false;
end;
End;
Crea una tabla:
Function CreateTable(NumRows, NumColumns:integer;
var
index:integer):boolean;
var
sel_:variant;
begin
CreateTable:=true;
try
sel_:=W.selection;
W.ActiveDocument.Tables.Add (Range:=sel_.Range,NumRows:
=NumRows,
NumColumns:=NumColumns);
index:=W.ActiveDocument. Tables.Count;
except
CreateTable:=false;
end;
End;
Dimensiona una tabla:
Function SetSizeTable(Table:integer; RowsHeight,
ColumnsWidth:real):boolean;
begin
SetSizeTable:=true;
try
W.ActiveDocument.Tables.Item
(Table).Columns.Width:=ColumnsWidth;
W.ActiveDocument.Tables.Item(Table).
Rows.Height:=RowsHeight;
except
SetSizeTable:=false;
end;
End;
De manera similar, se puede definir la altura de cualquier línea o el ancho de cualquier columna que queramos.
Function SetHeightRowTable(Table,Row:integer;
RowHeight:real):boolean;
begin
SetHeightRowTable:=true;
try
W.ActiveDocument.Tables.Item(Table).Rows.item(Row).Height:=RowHeight;
except
SetHeightRowTable:=false;
end;
End;
Function SetWidthColumnTable(Table,Column: integer;
ColumnWidth:real):boolean;
begin
SetWidthColumnTable:=true;
try
W.ActiveDocument.Tables.Item(Table).Columns.
Item(Column).Width:=ColumnWidth;
except
SetWidthColumnTable:=false;
end;
End;
Tamaño de la tabla:
Function GetSizeTable(Table:integer;var RowsHeight,
ColumnsWidth: real):boolean;
begin
GetSizeTable:=true;
try
ColumnsWidth:=W.ActiveDocument.
Tables.Item(Table).Columns.Width;
RowsHeight:=W.ActiveDocument.
Tables.Item(Table).Rows.Height;
except
GetSizeTable:=false;
end;
End;
Pon texto en la tabla:
Function SetTextToTable(Table:integer;Row,
Column:integer;
text:string):boolean;
begin
SetTextToTable:=true;
try
W.ActiveDocument.Tables.Item(Table).Columns.Item(Column).
Cells.Item(Row).Range.Text:=text;
except
SetTextToTable:=false;
end;
End;
Mezcla celdas:
Function SetMergeCellsTable(Table:integer;Row1,
Column1,Row2,Column2:integer):boolean;
var
Cel:variant;
begin
SetMergeCellsTable:=true;
try
Cel:=W.ActiveDocument.Tables.I
tem(Table).Cell(Row2,Column2);
W.ActiveDocument.Tables.Item(Table).
Cell(Row1,Column1).Merge(Cel);
except
SetMergeCellsTable:=false;
end;
End;
Selecciona celdas de una tabla:
Function GetSelectionTable:boolean;
const wdWithInTable=12;
begin
GetSelectionTable:=true;
try
GetSelectionTable:=W.Selection.Information(wdWithInTable);
except
GetSelectionTable:=false;
end;
End;
Ir a la siguiente o anterior tabla:
Function GoToNextTable (table_:integer):boolean;
const wdGoToTable=2;
begin
GoToNextTable:=true;
try
W.Selection.GoToNext (wdGoToTable);
except
GoToNextTable:=false;
end;
End;
Function GoToPreviousTable (table_:integer):boolean;
const wdGoToTable=2;
begin
GoToPreviousTable:=true;
try
W.Selection.GoToPrevious(wdGoToTable);
except
GoToPreviousTable:=false;
end;
End;
Obtiene las columnas de una tabla:
Function GetColumnsRowsTable(table_:integer;
var
Columns,Rows:integer):boolean;
const
wdMaximumNumberOfColumns=18;
wdMaximumNumberOfRows=15;
begin
GetColumnsRowsTable:=true;
try
Columns:=W.Selection.Information
(wdMaximumNumberOfColumns);
Rows:=W.Selection.Information
(wdMaximumNumberOfRows);
except
GetColumnsRowsTable:=false;
end;
End;
Añade una fila a una tabla:
Function AddRowTableDoc (table_:integer):boolean;
begin
AddRowTableDoc:=true;
try
W.ActiveDocument.Tables.Item(table_).Rows.Add;
except
AddRowTableDoc:=false;
end;
End;
Function InsertRowsTableDoc(table_,position_,
count_:integer): boolean;
begin
InsertRowsTableDoc:=true;
try
W.ActiveDocument.Tables.Item(table_).Rows.Item(position_).Select;
W.Selection.InsertRows (count_);
except
InsertRowsTableDoc:=false;
end;
End;
Crea una caja de texto:
Function CreateTextBox (Left,Top,Width,Height:real;
var
name:string):boolean;
const msoTextOrientationHorizontal=1;
begin
CreateTextBox:=true;
try
name:=W.ActiveDocument.Shapes.AddTextbox
(msoTextOrientationHorizontal,Left,Top,Width,Height).Name;
except
CreateTextBox:=false;
end;
End;
Function TextToTextBox (TextBox:variant;text:
string):boolean;
const
msoTextBox=17;
begin
TextToTextBox:=true;
try
if
w.ActiveDocument.Shapes.Item(TextBox).Type = msoTextBox then
W.ActiveDocument.Shapes.Item(TextBox).TextFrame.TextRange.Text:=Text
else
TextToTextBox:=false;
except
TextToTextBox:=false;
end;
End;
Obtiene el índice de la forma gráfica:
Function GetNameIndexShape (NameShape:variant): variant;
begin
try
GetNameIndexShape:=W.ActiveDocument.Shapes.Item(NameShape).Name;
except
GetNameIndexShape:=false;
end;
End;
Pone el nombre a un shape:
Function SetNewNameShape (NameShape:variant;
NewNameShape:string):string;
begin
try
W.ActiveDocument.Shapes.Item(NameShape).Name:=NewNameShape;
SetNewNameShape:=NewNameShape;
except
SetNewNameShape:='';
end;
End;
Crea una línea:
Function CreateLine (BeginX,BeginY,EndX,EndY: real;
var
name:string):boolean;
begin
CreateLine:=true;
try
name:=W.ActiveDocument.Shapes.AddLine(BeginX,BeginY,EndX,EndY).Name;
except
CreateLine:=false;
end;
End;
Crea una imagen:
Function CreatePicture(FileName:string;Left,Top: real;
var
name:string):boolean;
begin
CreatePicture:=true;
try
name:=W.ActiveDocument.Shapes.AddPicture(FileName).Name;
W.ActiveDocument.Shapes.Item (name).Left:=Left;
W.ActiveDocument.Shapes.Item(name). Top:=Top;
except
CreatePicture:=false;
end;
End;
Borra un shape:
Function DeleteShape (NameShape:variant): variant;
Begin
DeleteShape:=true;
try
W.ActiveDocument.Shapes.Item (NameShape).Delete;
except
DeleteShape:=false;
end;
End;
Haloo, can i download the sample source app? thanks
ResponderEliminar