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?
GGriffithAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mhervaisCommented:
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
0
intheCommented:
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
0
drnadeemCommented:
Listening
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

intheCommented:
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)
0
craig_capelCommented:
NOOOOOOOOOOO how dare you mention VB!!!!!!!! I found a list of Word / Excel Calls on the net somewhere, looking now....
0
kubeerjaCommented:
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;
0
kubeerjaCommented:
0
florisbCommented:
Tell me if you want some Word examples (Word Perfect too).

Floris.
0
intheCommented:
GGriffith ,
does this help ?

"
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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
florisbCommented:
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.
0
GGriffithAuthor Commented:
I thank everyone for their help.....
0
kubeerjaCommented:
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!!!!!!!!!!!!!!!!
0
florisbCommented:
:---
0
intheCommented:
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 ??
0
GGriffithAuthor Commented:
I'm sorry if I offended anyone....I don't even think I know how to distribute the points out to multiple people....
0
florisbCommented:
=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.
0
kubeerjaCommented:
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!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.