Board index » delphi » "Language Unknown" in Excel

"Language Unknown" in Excel

 I'm starting to do some work that needs the integration of Delphi 3
with Excel 7(95). I've already read some articles, but I couldn't find
the answer to my problem: when I make the first call to Excel which is
       v.Visible : = True;
 Delphi stops with this exception:  EOleSysError, message: "Language
Unknown". I can't do anything with the Application object that I've
made! The frustrating part is that the very same project runs flawlessly
in Delphi 2. My Excel and Delphi are in English, just the system
configuration is set to Brazilian Portuguese. The system is NT4.0 with
Sp3.0.

Does anyone know what's happening? How can I make the program runs in
Delphi 3? Or where can I get information on this subject?

 

Re:"Language Unknown" in Excel


Quote
Alexandre Martins Saur wrote in message <34F779A9.165DA...@domain.com.br>...
> I'm starting to do some work that needs the integration of Delphi 3
>with Excel 7(95). I've already read some articles, but I couldn't find
>the answer to my problem: when I make the first call to Excel which is
>       v.Visible : = True;
> Delphi stops with this exception:  EOleSysError, message: "Language
>Unknown". I can't do anything with the Application object that I've
>made! The frustrating part is that the very same project runs flawlessly
>in Delphi 2. My Excel and Delphi are in English, just the system
>configuration is set to Brazilian Portuguese. The system is NT4.0 with
>Sp3.0.

>Does anyone know what's happening? How can I make the program runs in
>Delphi 3? Or where can I get information on this subject?

First, Excel from Office 97 gonna work.
Second, if you'll have localized version of Office, it will not work at all,
you will need to replace v.Visible : = True to translated version of
'Visible' word (look how Borland handling that in \DEMOS\OLEAUTO\AUTOCTRL).
But workaround exist, and it is in use of dispatch id's. Here is the small
unit that performs some simple Excel automation.
-----------------------------------------------------------------
unit ExcelOle;
//  Created 02/13/98 by Sergey Aldoukhov.
//
//  This is a simple unit, that allows Ole Automation access to MS Excel,
using disp id's.
//  Below is the example of usage.
//
//  uses ComObj;
//
//  procedure TForm1.Button1Click(Sender: TObject);
//  var
//    Excel: IExcelAppDisp;
//  begin
//    Excel:=CreateComObject(Class_Excel_Application) as IExcelAppDisp;
//    Excel.Visible:=true;
//    if Excel.WorkBooks.Count=0 then Excel.WorkBooks.Add;
//
Excel.ActiveSheet.Range[Excel.ActiveSheet.Cells[1,1],Excel.ActiveSheet.Cells
[100,100]].Clear;
//    Excel.ActiveSheet.Cells[1,1].Value:='Hello, World!';
//  end;
interface
const
  Class_Excel_Application: TGUID = '{00024500-0000-0000-C000-000000000046}';
type
  Range = dispinterface
    ['{00020846-0000-0000-C000-000000000046}']
    procedure Clear; dispid 111;
    procedure ClearContents; dispid 113;
    property _Default[RowIndex, ColumnIndex: OleVariant]: OleVariant dispid
0; default;
    property Text: OleVariant readonly dispid 138;
    property Value: OleVariant dispid 6;
  end;
  WorksheetDisp = dispinterface
    ['{000208D8-0000-0000-C000-000000000046}']
    property Cells: Range readonly dispid 238;
    property Range[Cell1, Cell2: OleVariant]: Range readonly dispid 197;
  end;
  WorkbooksDisp = dispinterface
    ['{000208DB-0000-0000-C000-000000000046}']
    function Add: IDispatch; dispid 181;
    procedure Close(lcid: Integer); dispid 277;
    property Count: Integer readonly dispid 118;
  end;
  IExcelAppDisp = dispinterface
    ['{000208D5-0000-0000-C000-000000000046}']
    property ActiveSheet: WorksheetDisp readonly dispid 307;
    property Workbooks: WorkbooksDisp readonly dispid 572;
    property Visible: WordBool dispid 558;
  end;
implementation
end.
----------------------------------------------------------

Re:"Language Unknown" in Excel


Sergey, thanks a lot for your answer. The workaround did work well. However, I
have another question: When you use interfaces instead of variants, do you have
to identify every interface and tis procedures and properties on the type
declaration of your unit? If so, how can I get this identification numbers?

Quote
Sergey Aldoukhov wrote:
> First, Excel from Office 97 gonna work.
> Second, if you'll have localized version of Office, it will not work at all,
> you will need to replace v.Visible : = True to translated version of
> 'Visible' word (look how Borland handling that in \DEMOS\OLEAUTO\AUTOCTRL).
> But workaround exist, and it is in use of dispatch id's. Here is the small
> unit that performs some simple Excel automation.
> -----------------------------------------------------------------
> unit ExcelOle;
> //  Created 02/13/98 by Sergey Aldoukhov.
> //
> //  This is a simple unit, that allows Ole Automation access to MS Excel,
> using disp id's.
> //  Below is the example of usage.
> //
> //  uses ComObj;
> //
> //  procedure TForm1.Button1Click(Sender: TObject);
> //  var
> //    Excel: IExcelAppDisp;
> //  begin
> //    Excel:=CreateComObject(Class_Excel_Application) as IExcelAppDisp;
> //    Excel.Visible:=true;
> //    if Excel.WorkBooks.Count=0 then Excel.WorkBooks.Add;
> //
> Excel.ActiveSheet.Range[Excel.ActiveSheet.Cells[1,1],Excel.ActiveSheet.Cells
> [100,100]].Clear;
> //    Excel.ActiveSheet.Cells[1,1].Value:='Hello, World!';
> //  end;
> interface
> const
>   Class_Excel_Application: TGUID = '{00024500-0000-0000-C000-000000000046}';
> type
>   Range = dispinterface
>     ['{00020846-0000-0000-C000-000000000046}']
>     procedure Clear; dispid 111;
>     procedure ClearContents; dispid 113;
>     property _Default[RowIndex, ColumnIndex: OleVariant]: OleVariant dispid
> 0; default;
>     property Text: OleVariant readonly dispid 138;
>     property Value: OleVariant dispid 6;
>   end;
>   WorksheetDisp = dispinterface
>     ['{000208D8-0000-0000-C000-000000000046}']
>     property Cells: Range readonly dispid 238;
>     property Range[Cell1, Cell2: OleVariant]: Range readonly dispid 197;
>   end;
>   WorkbooksDisp = dispinterface
>     ['{000208DB-0000-0000-C000-000000000046}']
>     function Add: IDispatch; dispid 181;
>     procedure Close(lcid: Integer); dispid 277;
>     property Count: Integer readonly dispid 118;
>   end;
>   IExcelAppDisp = dispinterface
>     ['{000208D5-0000-0000-C000-000000000046}']
>     property ActiveSheet: WorksheetDisp readonly dispid 307;
>     property Workbooks: WorkbooksDisp readonly dispid 572;
>     property Visible: WordBool dispid 558;
>   end;
> implementation
> end.
> ----------------------------------------------------------

Re:"Language Unknown" in Excel


Quote
Alexandre Martins Saur wrote:

> Sergey, thanks a lot for your answer. The workaround did work well. However, I
> have another question: When you use interfaces instead of variants, do you have
> to identify every interface and tis procedures and properties on the type
> declaration of your unit? If so, how can I get this identification numbers?

--------------------------------------------------
Hi!
I have read previous Sergey's article and tried to do the same thing.
His example worked fine, but I wanted to improve it.
Firstly, I needed interface's IDs - I've got them from System Registry
in "interfaces" key.
Secondly, properties and functions IDs I took using Visual C++ 5.0 ( A
little bit strange, but I had not time to find out another way to do it)
If You will know another one, please tell me.

Unfortunately I cannot deside the next problem: my application cannot
work with both Excels: 95 and 97 (localized versions).Something is
different in its interfaces.

Vyacheslav Barulin

Other Threads