Link to home
Start Free TrialLog in
Avatar of GGriffith
GGriffith

asked on

OLE Programming

Would like to know following:

Using Delphi with DBase 4....

I'm being supplied a Excel Worksheet file that I need to convert to a DBF file....I know how to open the file and get access to it as a worksheet...but can't find any doc on the commands used to first change the file type and then save file as xyz.....

Example...would think it would be something similar to this....

ExcelApp.Workbooks.Open(FileName);
ExcelApp.FileType.(dbas4);  //not sure
ExcelApp.SaveAs('xyz'); //not sure

Any help will be greatly appreciated...
p.s.
Where is a good place to find doc on the program commands that must be used when utilizing OLE with Word or Excel?
Avatar of mhervais
mhervais

What I would do is this :

I would go in excel, and create a macro doing manually what I want. then I would sabe the macro and look at the source

I think in this source you would find the commands you need to run

I would then try to invoke them from
oleautomation.

This is not an answer, and frankly, I am not sure it works, but I would look in this direction.

regards, Marc
Hello,
in delphi use the "import type library" from the project menu (import excels .olb file) then can see the functions etc:

the saveas one is like:

procedure SaveAs(const Filename: WideString; FileFormat: OleVariant; Password: OleVariant;
                     WriteResPassword: OleVariant; ReadOnlyRecommended: OleVariant;
                     CreateBackup: OleVariant; AddToMru: OleVariant; TextCodepage: OleVariant;
                     TextVisualLayout: OleVariant; lcid: Integer); safecall;


called something like following:

        ExcelApp.SaveAs(
        'E:\Book1.dbf',
        'xlDBF4',
        False,
        '',
        False,
        xlNoChange,
        xlLocalSessionChanges,
        False,
        xlReadWrite,
        0,
        False,
        0,
        0,
        LCID);

Regards Barry
Listening
you can also find out about functions using vba (argggh ;-) help files if you can get a copy or have verions of office with them.
(there are some various vba.hlp files around net)
NOOOOOOOOOOO how dare you mention VB!!!!!!!! I found a list of Word / Excel Calls on the net somewhere, looking now....
try this

     XL := CreateOLEObject('Excel.Application');
     try
       XL.DisplayAlerts := false; //don't display confirm overwrite dialogs
       XL.workbooks.open(xlsFileName); //supply the directory path if needed
       XL.ActiveWorkBook.SaveAs(Filename := dbfFileName, FileFormat := 11); {dbf}
     Finally
      if not VarIsEmpty(XL) then XL.quit;
      XL := unassigned;
     end;
Tell me if you want some Word examples (Word Perfect too).

Floris.
ASKER CERTIFIED SOLUTION
Avatar of inthe
inthe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Ggriffith and inthe and others,

I'm having this generous morning, found an old unit I used (and made, Okee), for some simple Excel communications. Offcourse in dutch, but that shouldn;t be too mumch a problem...?

unit ExcelUnit;

interface

uses Excel_TLB, sysUtils;

type
  TExcelActiveX = class
  public
    procedure Start(Visible: Boolean);
    procedure Open(Bestand: string);
    procedure SelecteerEnVerander(EenCell: String; Waarde: integer; tekst:string);
    procedure LocaliseerEnVeranderInt(Bladwijzer:string; Waarde: integer; tekst:string);
    procedure Stop;

    procedure Bewaar(Bestand: String);
    procedure Print;

  end;

var
  ExcelActiveX: TExcelActiveX;
  FExcel: _Application = nil;

implementation

procedure TExcelActiveX.Start(Visible: Boolean);
begin
FExcel := CoApplication.Create;
FExcel.Visible[0] := True;
end;

procedure TExcelActiveX.Stop;
begin
if not assigned(FExcel) then exit;
FExcel.Quit;
end;

procedure TExcelActiveX.Open(Bestand: string);
var
  FileName, UpdateLinks, ReadOnly, Format, Password,
  WriteResPassword, IgnoreReadOnlyRecommended, Origin,
  Delimiter, Editable, Notify, Converter, AddToMRU: OleVariant;
begin
if not assigned(FExcel) then exit;
FileName := Bestand;
UpdateLinks := '0';
ReadOnly := False;
Format := 5; {geen scheidingsteken}
PassWord := '';
WriteResPassWord := '';
IgnoreReadOnlyRecommended := False;
Origin := xlWindows;
Delimiter := '';
Editable := True;
Notify := True;
Converter := 1; {was 0}
AddToMRU := False;
FExcel.Workbooks.Open(FileName, UpdateLinks, ReadOnly, Format, Password,
  WriteResPassword, IgnoreReadOnlyRecommended, Origin,
  Delimiter, Editable, Notify, Converter, AddToMRU, 0);
end;

procedure TExcelActiveX.Print;
var
  From, To_, Copies, Preview, ActivePrinter, PrintToFile, Collate, CLID: OleVariant;
begin
{Sub Macro1()
    ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1, _
    Preview:=False, ActivePrinter:="", PrintToFile:=False, Collate:=False
End Sub}
if not assigned(FExcel) then exit;
From := Null;
To_ := Null;
Copies := '1';
Preview := False;
ActivePrinter := FExcel.ActivePrinter[0];
PrintToFile := False;
Collate := False;
CLID := 0;
FExcel.ActiveWindow.SelectedSheets.PrintOut(From, To_, Copies, Preview, ActivePrinter, PrintToFile, Collate, CLID);
end;

procedure TExcelActiveX.LocaliseerEnVeranderInt(Bladwijzer:string;Waarde:integer;tekst:string);
//localize and change
var
  Scroll, Reference: OleVariant;
begin
if not assigned(FExcel) then
   exit;
///
Scroll := 0;
Reference := Bladwijzer;
FExcel.Application.Goto_(Reference, Scroll, 0);
///
if tekst = '' then
   FExcel.ActiveCell.Value := waarde
else
   begin
   tekst := ''''+tekst;
   FExcel.ActiveCell.Value := tekst;
   end;
end;

procedure TExcelActiveX.SelecteerEnVerander(EenCell:String;Waarde:integer;tekst:string);
//select and change
var
  Cell1, Cell2: OleVariant;
begin
if not assigned(FExcel) then
   exit;
///
Cell1 := EenCell;
Cell2 := EenCell;
FExcel.Range[Cell1, Cell2].Select;
///
if not( waarde = 1) then
   tekst := ''''+tekst;
FExcel.ActiveCell.Value := tekst;
end;

procedure TExcelActiveX.Bewaar(Bestand: String);
//save!
var
  Filename, FileFormat, Password, WriteResPassword,
  ReadOnlyRecommended, CreateBackup, AccessMode, ConflictResolution,
  AddToMru, TextCodePage, TextVisualLayout : OleVariant;
begin
Filename := Bestand;
FileFormat := xlNormal;
Password := '';
WriteResPassword := '';
ReadOnlyRecommended := False;
CreateBackup := False;
AccessMode := xlNoChange;
ConflictResolution := xlLocalSessionChanges;
AddToMru := True;
TextCodePage := '';
TextVisualLayout := '';
FExcel.ActiveWorkbook.SaveAs(Filename, FileFormat, Password, WriteResPassword,
                      ReadOnlyRecommended, CreateBackup, AccessMode, ConflictResolution,
                      AddToMru, TextCodePage, TextVisualLayout, 0);
end;

end.
Avatar of GGriffith

ASKER

I thank everyone for their help.....
I don't see why you accepted inthe comment and you didn't evaluate others comments, this will make me in the future answer directly and instead of submitting a comment!!!!!!!!!!!!!!!!
:---
kubeerja please hold your panties on and read the question and then read in order the answers(keeping in mind the question).

my first comment was like 24 hours before yours and shows "more or less" the answer so whats the problem ??
I'm sorry if I offended anyone....I don't even think I know how to distribute the points out to multiple people....
=Okee with me. I just dumped some info here...

Distributing points you can only do by posting some dummy questions as far as I know. Always welcome...:-)

F.
Sorry Barry,
Although your comment is working but I think I gave ggriffith a better one and easy to use for a beginner plus more help to look into. I don't mind giving you the points though I think ggriffith will use my answer!