请教有用过TEXCELAPPLICATION 组件的高手,俺有个报表,格式过于复杂,非得用Excel才能实现.
    俺试过用两种方法引用Excel:
   一种直接用CREATATEOLEOBJECT( 'EXCEL.APPLICATION')创建OLE对象,但是无法 USES XLCONST ,编码时没有提示信息,简直无法干活-----所以,俺选择放弃,试用
     第二种方法:直接引用DELPHI 的SERVER 组件,TEXCELAPPLICATION 舆TEXCELWORKSHEET ,但是,俺不大懂使用,请教有使用该组件的大虾,万分感谢!最好能有源代码.

解决方案 »

  1.   

    其实第一种方法完全可以达到你的要求!
    看:http://expert.csdn.net/Expert/topic/958/958264.xml?temp=.4421045
      

  2.   

    http://expert.csdn.net/Expert/topic/958/958264.xml?temp=.2145044
      

  3.   

    兄弟;俺要用TEXCELAPPLICATION 组件的源代码.
    用CREATATEOLEOBJECT( 'EXCEL.APPLICATION')创建OLE对象编码时没有提示信息!怎么干活?
      

  4.   

    procedure TfrExportFilterEx.OpenExcel;
    var Template:OleVariant;
    begin
      ExcelApp.Connect;
      ExcelApp.Visible[0] := true;
      ExcelApp.Caption := '结算中心报表=====by steel;
      Template:=EmptyParam;
      ExcelWorkbook.ConnectTo(ExcelApp.Workbooks.Add(Template,0));
    end;procedure TfrExportFilterEx.CloseExcel;
    var RptFile:OleVariant;
    begin
      RptFile:=SaveDlg.FileName;
      ExcelWorkbook.SaveCopyAs(RptFile);
      ExcelWorkbook.Close(false);
      ExcelWorkbook.Disconnect;
      ExcelApp.Quit;
      ExcelApp.Disconnect;
      showmessage('报表保存成功!');
    end;procedure TfrExportFilterEx.ExportToExcel;
    var rng,rng1,rng2:Range;
        i,m,n, nCol,nRow, iRow,iCol,iTop,iLeft:integer;
        vItem:OleVariant;
        s:string;
    begin
      SetRowCol;
      ReSetRowCol;
      OpenExcel;
      for i:=1 to CDS.RecordCount do
      begin
        CDS.RecNo:=i;
        iRow:=CDS.fieldbyname('Row').AsInteger;
        iCol:=CDS.fieldbyname('Col').AsInteger;      ExcelApp.Cells.Item[iRow,iCol]:=CDS.FieldByName('Text').AsString;
          ExcelApp.Cells.Item[iRow,iCol].Font.Size:=CDS.FieldByName('FontSize').AsInteger;;
          ExcelApp.Cells.Item[iRow,iCol].Font.Name:=CDS.FieldByName('FontName').AsString;
          if CDS.FieldByName('FontBold').AsBoolean then
             ExcelApp.Cells.Item[iRow,iCol].Font.Bold:=true;
          if CDS.FieldByName('FrameTyp').AsInteger=15 then
             ExcelApp.Cells.Item[iRow,iCol].Borders.LineStyle:=1;  //1线
          ExcelApp.Cells.Item[iRow,iCol].HorizontalAlignment:=4; //1,2:左 3:水平居中 4:右
          ExcelApp.Cells.Item[iRow,iCol].VerticalAlignment:=2;   //1:上  2:中  3:下
          ExcelApp.Cells.Item[iRow,iCol].RowHeight:=CDS.FieldByName('Height').AsInteger;
      end;
      //处理标题
      CDS.Locate('FrameTyp',15,[]);
      CDS.Filter:='Row='+inttostr(CDS.fieldbyname('Row').AsInteger);
      CDS.Filtered:=true;
      CDS.Last;
      nCol:=CDS.fieldbyname('Col').AsInteger+CDS.fieldbyname('nCol').AsInteger-1;
      iLeft:=CDS.fieldbyname('Left').AsInteger+CDS.fieldbyname('Width').AsInteger;
      s:=ExcelApp.Cells.Item[1,1];
      rng:=ExcelApp.Range[ExcelApp.Cells.Item[1,1],
             ExcelApp.Cells.Item[1,nCol]];
      rng.Merge(0);
      rng.Item[1,1]:=s;
      rng.Item[1,1].HorizontalAlignment:=3; //1,2:左 3:水平居中 4:右
      //----------------------------------------------------------------
      //处理页头页尾
      CDS.Filtered:=false;
      CDS.Filter:='FrameTyp<>15';
      CDS.Filtered:=true;
      for i:=2 to CDS.RecordCount-3 do
      begin
        CDS.RecNo:=i;
        iRow:=CDS.fieldbyname('Row').AsInteger;
        iCol:=CDS.fieldbyname('Col').AsInteger;
        ExcelApp.Cells.Item[iRow,iCol]:='';
        s:=CDS.fieldbyname('Text').AsString;
        if iLeft=CDS.fieldbyname('Left').AsInteger+
                     CDS.fieldbyname('Width').AsInteger  then
        begin
          ExcelApp.Cells.Item[iRow,nCol]:=s;
          ExcelApp.Cells.Item[iRow,nCol].HorizontalAlignment:=4; //1,2:左 3:水平居中 4:右
          ExcelApp.Cells.Item[iRow,nCol].VerticalAlignment:=2;   //1:上  2:中  3:下
          ExcelApp.Cells.Item[iRow,nCol].Font.Size:=CDS.FieldByName('FontSize').AsInteger;;
          ExcelApp.Cells.Item[iRow,nCol].Font.Name:=CDS.FieldByName('FontName').AsString;
        end
        else begin
          rng:=ExcelApp.Range[ExcelApp.Cells.Item[iRow,1],
                  ExcelApp.Cells.Item[iRow,3]];
          rng.Merge(0);
          rng.Item[1,1]:=s;
          rng.HorizontalAlignment:=1;
          rng.VerticalAlignment:=2;
        end;
      end;
      //----------------------------------------------------------------
      CDS.Filtered:=false;
      CDS.Filter:='Col=1 or ((Col>1) and (Row=3 or Row=4))';
      CDS.Filtered:=true;
      for i:=2 to CDS.RecordCount do
      begin
        CDS.RecNo:=i;
        nCol:=CDS.fieldbyname('nCol').AsInteger;
        nRow:=CDS.fieldbyname('nRow').AsInteger;
        iRow:=CDS.fieldbyname('Row').AsInteger;
        iCol:=CDS.fieldbyname('Col').AsInteger;
        if (nCol>1) or (nRow>1) then begin
           rng:=ExcelApp.Range[ExcelApp.Cells.Item[iRow,iCol],
                  ExcelApp.Cells.Item[iRow+nRow-1,iCol+nCol-1]];
           rng.Merge(0);
           rng.Borders.LineStyle:=1;    //1线
           rng.HorizontalAlignment:=3; //1,2:左 3:水平居中 4:右
        end;
      end;
      //---------------------------------------------------------------
      CDS.Filtered:=false;
      CDS.Filter:='';  //ExcelWorkbook.PrintPreview;
      //sleep(5000);
      //ExcelApp  CloseExcel;
    end;
      

  5.   

    可参考有关vba编码方面的书籍,
      

  6.   

    谢谢所有进来帮助我得大虾,在此要特意谢谢 steel1991(※淡月兔影老钢琴※) !