Difference between revisions of "Office Automation/ru"

From Free Pascal wiki
Jump to navigationJump to search
Line 10: Line 10:
 
[http://wiki.services.openoffice.org/wiki/Uno/Article/About_Bridges About_Bridges]
 
[http://wiki.services.openoffice.org/wiki/Uno/Article/About_Bridges About_Bridges]
  
== Using COM Automation to interact with OpenOffice and Microsoft Office==
+
== Использование COM Automation для работы с OpenOffice и Microsoft Office ==
Automation is unique to Windows so the following two examples won't work on OS X or Linux. For those platforms, please refer to  [http://wiki.lazarus.freepascal.org/Multiplatform_Programming_Guide#Making_do_without_Windows_COM_Automation Making do without Windows COM Automation]. If you only need to create and/or view a word processing document from your program, take a look at the [http://web.fastermac.net/~MacPgmr/XDev/XDevStatus.html#RTF XDev Toolkit].
+
COM Automation существует только в Windows, поэтому следующие два примера не будет работать на OS X или Linux. Для этих платформ см. [http://wiki.lazarus.freepascal.org/Multiplatform_Programming_Guide#Making_do_without_Windows_COM_Automation Making do without Windows COM Automation]. Если вам нужно только создать и/или просмотреть текстовый документ из вашей программы, то взгляните на [http://web.fastermac.net/~MacPgmr/XDev/XDevStatus.html#RTF XDev Toolkit].
 +
 
 +
Вот простой пример того, как открыть документ из программы с помощью сервера автоматизации OpenOffice. Не забываем, что это работает только на Windows.
  
Here's a simple example of how to open a document with your program using the OpenOffice Automation server. Note that this works only on Windows.
 
 
<PRE>
 
<PRE>
 
program TestOO;
 
program TestOO;
Line 61: Line 62:
 
</PRE>
 
</PRE>
  
Here's a simple example of how to open a document with your program using the Word Automation server. Note that this works only on Windows and currently can't be compiled with Free Pascal 2.2, only Delphi. Please check back later or test with a future version of FPC.
+
Вот простой пример того, как открыть документ из программы с помощью сервера автоматизации Word. Не забываем, что это работает только на Windows, и в настоящее время не может быть скомпилировано в Free Pascal 2.2, только в Delphi. Пожалуйста, проверьте эту информацию позже или протестируйте на болеее актуальной версии FPC.
 
<PRE>
 
<PRE>
 
program TestMsOffice;
 
program TestMsOffice;

Revision as of 21:01, 12 April 2010

Deutsch (de) English (en) español (es) français (fr) italiano (it) русский (ru) 中文(中国大陆)‎ (zh_CN)

The ability to interact with office software and generate spreadsheets, text documents and presentations from code can be invaluable in the office, and win a lot of time for those that can do it. One example of this is the creation of applications that can read files in an arbitrary format and output an Excel file, a task much more efficient to be done with code then manually.

Использование OpenOffice UNO Bridge

OpenOffice имеет надстройки для использования в C++ и Java и в Windows также может использоваться COM Automation (см. ниже), но сейчас достаточно сложно использовать UNO (Universal Network Objects) из Object Pascal в OS X и Linux. Если Вы заинтересованны в разработке OO "bridge" для Pascal, пожалуйста следуйте по следующим ссылкам (внимание: these links are quite techie in true Sun fashion):

api.openoffice.org

About_Bridges

Использование COM Automation для работы с OpenOffice и Microsoft Office

COM Automation существует только в Windows, поэтому следующие два примера не будет работать на OS X или Linux. Для этих платформ см. Making do without Windows COM Automation. Если вам нужно только создать и/или просмотреть текстовый документ из вашей программы, то взгляните на XDev Toolkit.

Вот простой пример того, как открыть документ из программы с помощью сервера автоматизации OpenOffice. Не забываем, что это работает только на Windows.

program TestOO;

{$IFDEF FPC}
 {$MODE Delphi}
{$ELSE}
 {$APPTYPE CONSOLE}
{$ENDIF} 

uses
  SysUtils, Variants, ComObj;

const
  ServerName = 'com.sun.star.ServiceManager';
var          
  Server     : Variant;
  Desktop    : Variant;
  LoadParams : Variant;
  Document   : Variant;
  TextCursor : Variant;
begin
  if Assigned(InitProc) then
    TProcedure(InitProc);

  try
    Server := CreateOleObject(ServerName);
  except
    WriteLn('Unable to start OO.');
    Exit;
  end;

  Desktop := Server.CreateInstance('com.sun.star.frame.Desktop');

  LoadParams := VarArrayCreate([0, -1], varVariant);

   {Create new document}
  Document := Desktop.LoadComponentFromURL('private:factory/swriter',
                                           '_blank', 0, LoadParams);

  TextCursor := Document.Text.CreateTextCursor;

   {Insert existing document}  //Substitute your path and doc
  TextCursor.InsertDocumentFromURL('file:///C|/my/path/mydoc.doc',  
                                   LoadParams);
end.

Вот простой пример того, как открыть документ из программы с помощью сервера автоматизации Word. Не забываем, что это работает только на Windows, и в настоящее время не может быть скомпилировано в Free Pascal 2.2, только в Delphi. Пожалуйста, проверьте эту информацию позже или протестируйте на болеее актуальной версии FPC.

program TestMsOffice;

{$IFDEF FPC}
 {$MODE Delphi}
{$ELSE}
 {$APPTYPE CONSOLE}
{$ENDIF} 

uses
  SysUtils, Variants, ComObj;

const
  ServerName = 'Word.Application';
var
  Server     : Variant;
begin
  if Assigned(InitProc) then
    TProcedure(InitProc);

  try
    Server := CreateOleObject(ServerName);
  except
    WriteLn('Unable to start Word.');
    Exit;
  end;

   {Open existing document}  //Substitute your path and doc
  Server.Documents.Open('c:\my\path\mydoc.doc'); 

  Server.Visible := True;  {Make Word visible}

end.

Using the Free Pascal Spreasheet Library

Another way to automate repetetive work with spreadsheets is to generate the file using the FPSpreadsheet library. This method doesn't require having any external application installed on the machine and several formats are supported.

Writing an Excel file using ADO

please write me.

External links