I use OLE method like this:
var
xlApp, xlWorkBook, xlWorkSheet, arr: Variant;
begin
xlApp := CreateOLEObject('Excel.Application');
xlApp.Visible := True;
end;
How to add a button to Excel?
And how to assign a exist marco on this button?
Where can I find Delphi-OLE-Office document?
Thx.
I worked this out by recording a VBA macro and then pasting it into your Delphi routine:
xlApp := CreateOLEObject('Excel.Application');
xlApp.Visible := True;
xlWorkBook := xlApp.Workbooks.Add;
xlWorkBook.ActiveSheet.Buttons.Add(10, 10, 80, 30).Select;
xlWorkBook.Selection.OnAction := 'Macro1';
There is no Delphi documentation of Office COM automation. You have to use the MSDN documentation and translate it into Delphi yourself.
Related
I want to align a text to center and I have no idea on how to achieve it.
Here is my code:
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 := 22;
MSWord.Selection.Font.Bold := true;
MSWord.Selection.TypeText(#13#10);
MSWord.Selection.TypeText('I want this to be center-aligned');
...
MSWord.ActiveDocument.SaveAs('C:\doc2.doc');
Please help.
Thanks
This works for me:
procedure TForm1.Button1Click(Sender: TObject);
var
MSWord : OleVariant;
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 := 22;
MSWord.Selection.Font.Bold := true;
MSWord.Selection.TypeText(#13#10);
MSWord.Selection.TypeText('I want this to be center-aligned');
MSWord.Selection.ParagraphFormat.Alignment := wdAlignParagraphCenter;
MSWord.ActiveDocument.SaveAs('C:\doc2.doc');
end;
Btw, the way to find the answer yourself is to go into Word, start recording a macro, perform the action, stop recording then edit the macro to see what code Word generates. Converting that to Delphi is usually fairly trivial if you're using late binding (accessing Word from Delphi via an OleVariant) but can be a bit long winded if you're using early binding, because early binding requires all parameters to be specified, whereas late binding lets you leave most of them out.
With a customer I'm stuck developing for this very old version (2.1) of ExpressQuantumGrid by DevExpress. In Delphi 4. I can't find any documentation about it.
Basically I just need to create a bunch of TdxDBGridMaskColumn and "insert" them into the grid (TdxDBGrid) at runtime. From the code completion pop-up I can't figure out how.
Thanks!
We have an old app that uses Delphi 5 and DevExpress v3, the code might not be identical but should get you started.
A function that can create a column of any type (TdxDBDateColumn for example):
function CreateColumn(const aField: string; aColClass: TdxDBTreeListColumnClass): TdxDBTreeListColumn;
var
begin
Result := dxGrid.CreateColumn(aColClass);
Result.Name := dxGrid.Name + aField;
TdxDBGridColumn(Result).DisableFilter := True;
TdxDBGridColumn(Result).DisableGrouping := True;
TdxDBGridColumn(Result).Alignment := taRightJustify;
TdxDBGridColumn(Result).FieldName := aField;
TdxDBGridColumn(Result).Caption := aField;
TdxDBGridColumn(Result).Width := 70;
end;
Then you can call this function like so:
NewColumn := CreateColumn('Username', TdxDBGridColumn);
What is a new way to get current file that is being worked on in Experts for Delphi XE
Previously in Delphi 5-7 we used ToolServices.getCurrentFile
Perhaps the deprecated units ToolIntf, ExptIntf etc. are no longer working. You can use IOTAModuleServices.CurrentModule instead. Here's a quick example:
function GetCurrentEditorFileName: string;
var
Module: IOTAModule;
Editor: IOTAEditor;
begin
Result := '';
Module := (BorlandIDEServices as IOTAModuleServices).CurrentModule;
if Assigned(Module) then
begin
Editor := Module.CurrentEditor;
if Assigned(Editor) then
Result := Editor.FileName;
end;
end;
An alternate method is to pass the "name of file in the editor" to your tool as a parameter. $EDNAME
I using Delphi BDS 2006 and have a DevExpress cxGridDBColumn with properties set to DateEdit and was wondering whether it is possible to add a checkbox to the displayed date time picker popup?
I am not sure that I understand what you wish to achieve. Anyway, it is impossible without creating a custom cxEditor which supports this look&feel and desired functionality.
Here is a quick hack which should help you implement this feature. However, you should handle the checkBox yourself. I have done this for the standalone editor, however, the same approach will work with the inplace editor:
procedure TForm1.cxDateEdit1PropertiesPopup(Sender: TObject);
var
AEdit: TcxDateEdit;
ACalendar: TcxPopupCalendar;
ACheckBox: TcxCheckBox;
begin
AEdit := TcxDateEdit(Sender);
if AEdit.Tag <> 1 then
begin
AEdit.Tag := 1;
ACalendar := TcxPopupCalendar(AEdit.Properties.PopupControl);
ACheckBox := TcxCheckBox.Create(Self);
ACheckBox.Parent := ACalendar.Parent;
ACheckBox.Align := alBottom;
ACheckBox.Transparent := True;
ACalendar.Parent.Height := ACalendar.Parent.Height + ACheckBox.Height;
end;
end;
I'm struggling with the following:
The goal is to parametrize an automation server for openoffice and I'm programming in Delphi.
The piece of basic code I want to translate into Delphi code is:
Dim aProps(1) As New com.sun.star.beans.PropertyValue
aProps(0).Name = "FilterName"
aProps(0).Value = "Text - txt - csv (StarCalc)"
aProps(1).Name = "FilterOptions"
aProps(1).Value = sFilterOptions
My attempt in Delphi looks like
type TPrmRecord = packed Record
Name : String;
Value : String;
End;
Var
ooParams:Variant;
MyData : TPrmRecord;
Begin
ooParams:= VarArrayCreate([0, 1], varVariant);
MyData.Name := 'FilterName';
MyData.Value := 'Text - txt - csv (StarCalc)';
ooParams[0] := MyData;
MyData.Name := 'FilterOptions';
MyData.Value := '59/44,34,ANSI,1,';
ooParams[1] := MyData;
End;
This is not working does anyone have a suggestion how to tackle this?
Your TPrmRecord type is not what OO.org expects. You should not try to write your own types, but use those that OO.org exposes.
There is an LPGL-licensed toolbox for Delphi: Delphi OOo. In it you will find a unit OOoTools.pas, which exports a function CreateUnoStruct(). Use this and pass 'com.sun.star.beans.PropertyValue' as the name of the struct. You will get a Variant (or an array of those, depending on the other parameter value) back that you can use instead of TPrmRecord (something like the following, untested):
var
Params: Variant;
begin
Params := CreateUnoStruct('com.sun.star.beans.PropertyValue', 1);
Params[0].Name := 'FilterName';
Params[0].Value := 'Text - txt - csv (StarCalc)';
Params[1].Name := 'FilterOptions';
Params[1].Value := '59/44,34,ANSI,1,';
end;
It looks as though you're missing the creation of the COM class, which would be the equivalent of the New com.sun.star.beans.PropertyValue line in your code.
I suspect you need to import the type library into Delphi which would give you the objects, properties and methods you need to emulate the Basic behaviour.
Here is straight Delphi code without using Delphi OOo:
uses comobj;
var
OO_ServiceManager: OleVariant;
FileParams: OleVariant;
begin
OO_ServiceManager := CreateOleObject ('com.sun.star.ServiceManager');
FileParams := VarArrayCreate([0, 1], varVariant);
FileParams[0] := OO_ServiceManager.Bridge_GetStruct('com.sun.star.beans.PropertyValue');
FileParams[0].Name := 'FilterName';
FileParams[0].Value := 'Text - txt - csv (StarCalc)';
FileParams[1] := OO_ServiceManager.Bridge_GetStruct('com.sun.star.beans.PropertyValue');
FileParams[1].Name := 'FilterOptions';
FileParams[1].Value := '59/44,34,ANSI,1,';
end;
Have a look at this Thread in the german Delphi-PRAXiS forums. There is a whole delphi Unit posted doing some OOo automation.
use
var
ooParams:array[0..1] of TPrmRecord;
delphi uses strict type-casting, so this is causing an assignment error.