Translate

2014/02/18

Excel Component 的寫作技巧

在全域變數區可設定一個 LCID 變數
var _LCID: Cardinal;

在 TForm 上放置 ExcelApplication, ExcelWorkbook, ExcelWorksheet 三個元件。

開啟 EXCEL + 開啟活頁簿 + 指定工作表:
var
  _WBK: _Workbook;
  _IndexSheet: Integer
begin
  _LCID := GetUserDefaultLCID();
  _WBK := ExcelApplication.Workbooks.Open(
          {Filename        =}aFileName,
          {UpdateLinks     =}EmptyParam,
          {ReadOnly        =}EmptyParam,
          {Format          =}EmptyParam,
          {Password        =}EmptyParam,
          {WriteResPassword=}EmptyParam,
          {IgnoreReadOnly  =}EmptyParam,
          {Origin          =}EmptyParam,
          {Delimiter       =}EmptyParam,
          {Editable        =}EmptyParam,
          {Notify          =}EmptyParam,
          {Converter       =}EmptyParam,
          {AddToMru        =}EmptyParam,
          {Local           =}EmptyParam,
          {CorruptLoad     =}EmptyParam,
          {LCID            =}_LCID);
  ExcelWorkbook.ConnectTo(_WBK);
  ExcelWorksheet.ConnectTo(ExcelWorkbook.Worksheets[_IndexSheet] as _Worksheet);
end;

關閉活頁簿 + 關閉 Excel:
begin
  ExcelWorkbook.Close(
    {SaveChanges  =}EmptyParam,
    {Filename     =}EmptyParam,
    {RouteWorkbook=}EmptyParam,
    {LCID         =}_LCID);
  ExcelApplication.Quit;
  ExcelApplication.Disconnect;
end;




沒有留言:

張貼留言

JSON Parse in Delphi XE (03)

前情提要: JSON Parse in Delphi XE (01) JSON Parse in Delphi XE (02) 這篇要說明 JSON 格式在 Delphi 裡是怎麼被理解的。 JSON 名詞解釋: JSON(JavaScript Object N...