【问题标题】:select sheets excel选择工作表excel
【发布时间】:2013-03-30 10:53:51
【问题描述】:

XE3 使用 delphi 和 excel ole 自动化。 使用此代码,我在单元格中打开并读取/写入,但我无法选择不同的工作表(Sheet1、Sheet3 等)

begin
L_vi.Caption: = 'D: \ bd1 \ file_supporto \ Vi.xls';
Ex: = createoleobject ('Excel.Application');
Ex.visible: = true;
Ex.workbooks.open (L_vi.Caption);
Ex.cells [1,1]: = 'test';
Sheets: = Ex.Workbooks [1]. Worksheets ['Sheet3'];

你能帮忙吗?

谢谢

附: 我解决了:

Ex.Workbooks [1]. Worksheets ['Sheet3'].select;

谢谢。

【问题讨论】:

    标签: delphi delphi-xe3


    【解决方案1】:

    这对我在 XE3 中很有效:

    var
      XLApp: OleVariant;
      Sheet: OleVariant;
    begin
      XLApp := CreateOleObject('Excel.Application');
      XLApp.Visible := True;
      XLApp.Workbooks.Open('C:\Test\Testing.xls');
      ShowMessage(XLApp.Workbooks[1].Worksheets[1].Name);  // Sheet1
      Sheet := XLApp.Worksheets.Item['Sheet3']; 
      ShowMessage(Sheet.Name);                             // Sheet3
      Sheet.Select;
      // This also works
      XLApp.WorkSheets.Item['Sheet1'].Select;              // Sheet1
    end;
    

    【讨论】:

      猜你喜欢
      • 2015-10-12
      • 1970-01-01
      • 2018-12-28
      • 2012-08-01
      • 2015-12-07
      • 1970-01-01
      • 1970-01-01
      • 2015-08-09
      • 2017-01-05
      相关资源
      最近更新 更多