一个SDI程序,里面有一个OleContainer,其对象是一个Excel,我现在想控制这个Excel,修改表格的内容或者其他内容,不知道怎么实现,不知道各位大哥有没有建议?

解决方案 »

  1.   

    var
      i, j: integer;
      ch: char;
      fn: string;
      sheet, range: OleVariant;
    begin
      if opendialog1.Execute then
        fn := opendialog1.FileName;
      if not fileExists(fn) then exit;
      OleContainer1.CreateObjectFromFile(fn, true);
      OleContainer1.DoVerb(ovShow);
      ExcelApp := OleContainer1.OleObject;
      ExcelApp.Application.CommandBars['Standard'].Visible := true;
      ExcelApp.Application.CommandBars['Formatting'].Visible := true;
    //  sheet := ExcelApp.worksheets[1];
    //  sheet.Activate;//  range := sheet.range[sheet.cells[1, 1], sheet.cells[11, 10]];
     //   range.select;
     //   range.merge; // ºÏ²¢µ¥Ôª¸ñ
    //  range.borders.linestyle := xlcontinuous;
    //  range.font.size := 9;
    end
      

  2.   

    flashtong(阿木) :
    请问 ExcelApp 是什么类型的?
    如果是TExcelApplication,ExcelApp := OleContainer1.OleObject;无法通过编译
    如果是OleVariant或者Variant,ExcelApp := OleContainer1.OleObject;提示Interface not supported
      

  3.   

    还有一个奇怪的现象,我用:strFileName :=  ExtractFilePath(Application.ExeName) + 'AAAA.xls';
    OleContainer1.CreateObjectFromFile(strFileName, False);打开一个Excel文件,会提示“……已终止操作……”无法进行编辑,这个现象只在某几台电脑中有,有些电脑中却没有。在那些有提示的电脑中,我要是打开"AAAA.doc",一个Word文档,就能正常打开,不会产生这个提示,也能正常编辑。在那些有问题的电脑中,Excel程序是可以正常使用的。
      

  4.   

    flashtong(阿木) :
    ExcelApp是OleVariant类型的,上边提示的Interface not support是由于Excel加载有问题所致。我来打开WORD文档时,就可以了。