Не работает передача данных по OLE в русский Excel
Nomadic отвечает:
A: (SM): Дело в том что в VCL твои команды OLE2 передаются Excel'у в русском контексте (не знаю, как это правильно назвать). Для исправления необходимо найти в файле OLEAUTO.pas в функции GetIDsOfNames строчку
if Dispatch.GetIDsOfNames(GUID_NULL, @NameRefs, NameCount, LOCALE_SYSTEM_DEFAULT, DispIDs) <> 0 then
и заменить ее на
if Dispatch.GetIDsOfNames(GUID_NULL, @NameRefs, NameCount, ((LANG_ENGLISH+SUBLANG_DEFAULT*1024)+SORT_DEFAULT* 65536), DispIDs) <> 0 then
После этого у меня Excel стал понимать нормальные английские команды :)). Необходимая комбинация для установки английского языка взята из C-шных хедеров.
Microsoft Word
Как отследить открытие и закрытие документов в приложении Microsoft Word?
Nomadic советует:
В копилку. Исходный код, FAQ — желающие могут взять с Internet сами (информация взята спроверено — работает).
…
public
{ Public declarations }
FWordApp: _Application;
FWordDoc: _Document;
FWordSink: TWordConnection;
…
procedure StartWordConnection(WordApp: _Application; WordDoc: _Document; var WordSink: TWordConnection);
var
PointContainer: IConnectionPointContainer;
Point: IConnectionPoint;
begin
try
// TWordConnection is the COM object which receives the
// notifications from Word. Make sure to free WordSink when
// you are done with it.
WordSink := TWordConnection.Create;
WordSink.WordApp := WordApp;
WordSink.WordDoc := WordDoc;
// Sink with a Word application
OleCheck(WordApp.QueryInterface(IConnectionPointContainer, PointContainer));
if Assigned(PointContainer) then begin
OleCheck(PointContainer.FindConnectionPoint(ApplicationEvents, Point));
if Assigned(Point) then Point.Advise((WordSink as IUnknown), WordSink.AppCookie);
end;
// Sink with a Word document advise
OleCheck(WordDoc.QueryInterface(IConnectionPointContainer, PointContainer));
if Assigned(PointContainer) then begin
OleCheck(PointContainer.FindConnectionPoint(DocumentEvents, Point));
if Assigned(Point) then Point.Advise((WordSink as IUnknown), WordSink.DocCookie);
end;
excepton E: Exception do
ShowMessage(E.Message);
end;
end;
procedure TmainForm.btnStartClick(Sender: TObject);
begin
FWordApp := CoApplication_.Create;
FWordDoc := FWordApp.Documents.Add(EmptyParam, EmptyParam);
FWordApp.Visible := True;StartWordConnection(FWordApp, FWordDoc, FWordSink);
end;
procedure TmainForm.btnExitClick(Sender: TObject);
begin
FWordApp := CoApplication_.Create;
FWordDoc := FWordApp.Documents.Add(EmptyParam, EmptyParam);
FWordApp.Visible := True;
StartWordConnection(FWordApp, FWordDoc, FWordSink);
end;
procedure tmainform.btnexitclick(sender: tobject);
begin
FWordApp.Quit(EmptyParam, EmptyParam, EmptyParam);
end;
unit ConnectionObject;
interface
uses Word_TLB, dialogs;
type TWordConnection = class(TObject, IUnknown, IDispatch)
protected