D5+SQLSERVER7现在报表是用FASTREPORT写的,没有问题。
可是现在要求导入EXCEL,发现FASTREPORT可以导入但是问题是乱七八糟。
有什么方法可以提供解决这个问题。报表数据是用存储过程写的。
报表是主从式的。有销售表,客户表,类别表三张!
比方
国内
    客户A
          A001   900
          A002   200
    合计:       1100
    客户B
          B001   800
          B002   100
    合计:       900
分类合计:       2000  
国际


是不是,觉得有点难度哦!

解决方案 »

  1.   

    我刚刚才写的,已经调试通过了,你改改吧!function Excelop(x:integer):String;
    var
            abc:array[1..26] of String;
            head:integer;
            yu:integer;
    begin
            abc[1]:='a';
            abc[2]:='b';
            abc[3]:='c';
            abc[4]:='d';
            abc[5]:='e';
            abc[6]:='f';
            abc[7]:='g';
            abc[8]:='h';
            abc[9]:='i';
            abc[10]:='j';
            abc[11]:='k';
            abc[12]:='l';
            abc[13]:='m';
            abc[14]:='n';
            abc[15]:='o';
            abc[16]:='p';
            abc[17]:='q';
            abc[18]:='r';
            abc[19]:='s';
            abc[20]:='t';
            abc[21]:='u';
            abc[22]:='v';
            abc[23]:='w';
            abc[24]:='x';
            abc[25]:='y';
            abc[26]:='z';
            head:=x div 26;
            yu:=x mod 26;
            if head=0 then Excelop:=abc[yu]
            else
                    if yu=0 then
                            Excelop:=abc[26]
                    else
                            Excelop:=abc[head]+abc[yu];
    end;procedure TJCFPrintFrm.SpeedButton2Click(Sender: TObject);
    var
    chexingshu:integer;
    Excelx1:string;
    Excelx2:string;
    xl,Cell1: olevariant;
    Sum:integer;
    begin
            ExcelApp := CreateOleObject( 'Excel.Application' );
            ExcelApp.Caption := '报表打印';
            ExcelApp.WorkBooks.Add;
            ExcelApp.WorkSheets[1].Activate;
                            ExcelApp.Visible := True;
                            ExcelApp.ActiveWindow.Zoom := 75;
    chexingshu:=20;
            excelx1:=excelop(chexingshu)+'1';
            excelx2:='a1';
            ExcelApp.Range[excelx2, excelx1].Merge(xl);
            ExcelApp.Cells[1,1].Value :='电费收费报表';
            ExcelApp.cells.Item[1, 1].font.size := 20;
            ExcelApp.cells.Item[1, 1].RowHeight := 25;
            ExcelApp.cells.Item[1 , 1].Font.Bold := True;
            ExcelApp.cells.Item[1, 1].HorizontalAlignment := xlCenter;
            ExcelApp.cells.Item[1, 1].font.Name := '隶书';
            ExcelApp.cells.Item[2, 1].HorizontalAlignment := xlCenter;
            ExcelApp.Range['a2', 'a3'].Merge(xl);
            ExcelApp.Cells[2,1].Value :='商户名';
            ExcelApp.cells.Item[2 , 1].Font.Bold := True;
            ExcelApp.Range['a2', 'a3'].ColumnWidth := 20;
            ExcelApp.cells.Item[2, 1].RowHeight := 20;
            ExcelApp.Range['a2', 'a3'].Merge(xl);
            ExcelApp.Cells[2,2].Value := '收费时间';
            ExcelApp.cells.Item[2 , 2].Font.Bold := True;
            ExcelApp.Range['b2', 'b3'].Merge(xl);
            ExcelApp.cells.Item[2, 2].HorizontalAlignment := xlCenter;
            ExcelApp.Cells[2,3].Value := '门市';
            ExcelApp.cells.Item[2 , 3].Font.Bold := True;
            ExcelApp.Range['c2', 'c3'].Merge(xl);
            ExcelApp.cells.Item[2, 3].HorizontalAlignment := xlCenter;
            ExcelApp.Cells[2,4].Value := '上期用电(度)';
            ExcelApp.cells.Item[2 , 4].Font.Bold := True;
            ExcelApp.Range['d2', 'd3'].Merge(xl);
            ExcelApp.Range['d2', 'd2'].ColumnWidth := 15;
            ExcelApp.cells.Item[2, 4].HorizontalAlignment := xlCenter;
            ExcelApp.Cells[2,5].Value := '本期用电(度)';
            ExcelApp.cells.Item[2 , 5].Font.Bold := True;
            ExcelApp.Range['e2', 'e3'].Merge(xl);
            ExcelApp.cells.Item[2, 5].HorizontalAlignment := xlCenter;
            ExcelApp.Cells[2,6].Value := '实际用电(读)';
            ExcelApp.cells.Item[2 , 6].Font.Bold := True;
            ExcelApp.Range['f2', 'f3'].Merge(xl);
            ExcelApp.cells.Item[2, 6].HorizontalAlignment := xlCenter;
            ExcelApp.Cells[2,7].Value := '单价(元/度)';
            ExcelApp.cells.Item[2 , 7].Font.Bold := True;
            ExcelApp.Range['g2', 'g3'].Merge(xl);
            ExcelApp.cells.Item[2, 7].HorizontalAlignment := xlCenter;
            ExcelApp.Cells[2,8].Value := '金额(元)';
            ExcelApp.cells.Item[2 , 8].Font.Bold := True;
            ExcelApp.Range['h2', 'h3'].Merge(xl);
            ExcelApp.cells.Item[2, 8].HorizontalAlignment := xlCenter;
            ExcelApp.Cells[2,9].Value := '住房';
            ExcelApp.cells.Item[2 , 9].Font.Bold := True;
            ExcelApp.Range['i2', 'i3'].Merge(xl);
            ExcelApp.cells.Item[2, 9].HorizontalAlignment := xlCenter;
            ExcelApp.Cells[2,10].Value := '本期用电(度)';
            ExcelApp.cells.Item[2 , 10].Font.Bold := True;
            ExcelApp.Range['j2', 'j3'].Merge(xl);
            ExcelApp.cells.Item[2, 10].HorizontalAlignment := xlCenter;
            ExcelApp.Cells[2,11].Value := '本期用电(度)';
            ExcelApp.cells.Item[2 , 11].Font.Bold := True;
            ExcelApp.Range['k2', 'k3'].Merge(xl);
            ExcelApp.cells.Item[2, 11].HorizontalAlignment := xlCenter;
      

  2.   

            ExcelApp.Cells[2,12].Value := '实际用电(度)';
            ExcelApp.cells.Item[2 , 12].Font.Bold := True;
            ExcelApp.Range['l2', 'l3'].Merge(xl);
            ExcelApp.cells.Item[2, 12].HorizontalAlignment := xlCenter;
            ExcelApp.Cells[2,13].Value := '单价(元/度)';
            ExcelApp.cells.Item[2 , 13].Font.Bold := True;
            ExcelApp.Range['m2', 'm3'].Merge(xl);
            ExcelApp.cells.Item[2, 13].HorizontalAlignment := xlCenter;
            ExcelApp.Cells[2,14].Value := '金额(元)';
            ExcelApp.cells.Item[2 , 14].Font.Bold := True;
            ExcelApp.Range['n2', 'n3'].Merge(xl);
            ExcelApp.cells.Item[2, 14].HorizontalAlignment := xlCenter;
            ExcelApp.Cells[2,15].Value := '合计(大写)';
            ExcelApp.cells.Item[2 , 15].Font.Bold := True;
            ExcelApp.Range['o2', 'o3'].Merge(xl);
            ExcelApp.cells.Item[2, 15].HorizontalAlignment := xlCenter;
            ExcelApp.Cells[2,16].Value := '合计(小写)';
            ExcelApp.cells.Item[2 , 16].Font.Bold := True;
            ExcelApp.Range['p2', 'p3'].Merge(xl);
            ExcelApp.cells.Item[2, 16].HorizontalAlignment := xlCenter;
            ExcelApp.Cells[2,17].Value := '单位名称';
            ExcelApp.cells.Item[2 , 17].Font.Bold := True;
            ExcelApp.Range['q2', 'q3'].Merge(xl);
            ExcelApp.cells.Item[2, 17].HorizontalAlignment := xlCenter;
            ExcelApp.Cells[2,18].Value := '操作员';
            ExcelApp.cells.Item[2 , 18].Font.Bold := True;
            ExcelApp.Range['r2', 'r3'].Merge(xl);
            ExcelApp.cells.Item[2, 18].HorizontalAlignment := xlCenter;
                    Sum:=4;
                            JCFFrm.ADOQuery1.Close;
                            JCFFrm.ADOQuery1.SQL.Clear;
                            JCFFrm.ADOQuery1.SQL.Add('Select * from DianTab');
                            JCFFrm.ADOQuery1.Open;                        While JCFFrm.ADOQuery1.Eof<>True do
                              begin
                            ExcelApp.Cells[sum,1].Value :=JCFFrm.ADOQuery1.FieldByName('DHName').AsString;
                    ExcelApp.cells.Item[sum,1].HorizontalAlignment := xlCenter;
                            ExcelApp.Cells[sum,2].Value :=JCFFrm.ADOQuery1.FieldByName('DFDate').AsString;
                    ExcelApp.cells.Item[sum,2].HorizontalAlignment := xlCenter;
                            ExcelApp.Cells[sum,3].Value :=JCFFrm.ADOQuery1.FieldByName('DMenshi').AsString;
                    ExcelApp.cells.Item[sum,3].HorizontalAlignment := xlCenter;
                            ExcelApp.Cells[sum,4].Value :=JCFFrm.ADOQuery1.FieldByName('DMshangqi').AsString;
                    ExcelApp.cells.Item[sum,4].HorizontalAlignment := xlCenter;
                            ExcelApp.Cells[sum,5].Value :=JCFFrm.ADOQuery1.FieldByName('DMbenqi').AsString;
                    ExcelApp.cells.Item[sum,5].HorizontalAlignment := xlCenter;
                            ExcelApp.Cells[sum,6].Value :=JCFFrm.ADOQuery1.FieldByName('DMshiji').AsString;
                    ExcelApp.cells.Item[sum,6].HorizontalAlignment := xlCenter;
                            ExcelApp.Cells[sum,7].Value :=JCFFrm.ADOQuery1.FieldByName('DMdanjia').AsString;
                    ExcelApp.cells.Item[sum,7].HorizontalAlignment := xlCenter;
                            ExcelApp.Cells[sum,8].Value :=JCFFrm.ADOQuery1.FieldByName('DMjinge').AsString;
                    ExcelApp.cells.Item[sum,8].HorizontalAlignment := xlCenter;
                            ExcelApp.Cells[sum,9].Value :=JCFFrm.ADOQuery1.FieldByName('DZhufang').AsString;
                    ExcelApp.cells.Item[sum,9].HorizontalAlignment := xlCenter;
                            ExcelApp.Cells[sum,10].Value :=JCFFrm.ADOQuery1.FieldByName('DZshangqi').AsString;
                    ExcelApp.cells.Item[sum,10].HorizontalAlignment := xlCenter;
                            ExcelApp.Cells[sum,11].Value :=JCFFrm.ADOQuery1.FieldByName('DZbenqi').AsString;
                    ExcelApp.cells.Item[sum,11].HorizontalAlignment := xlCenter;
                            ExcelApp.Cells[sum,12].Value :=JCFFrm.ADOQuery1.FieldByName('DZshiji').AsString;
                    ExcelApp.cells.Item[sum,12].HorizontalAlignment := xlCenter;
                            ExcelApp.Cells[sum,13].Value :=JCFFrm.ADOQuery1.FieldByName('DZdanjia').AsString;
                    ExcelApp.cells.Item[sum,13].HorizontalAlignment := xlCenter;
                            ExcelApp.Cells[sum,14].Value :=JCFFrm.ADOQuery1.FieldByName('DZjinge').AsString;
                    ExcelApp.cells.Item[sum,14].HorizontalAlignment := xlCenter;
                            ExcelApp.Cells[sum,15].Value :=JCFFrm.ADOQuery1.FieldByName('DDZHJ').AsString;
                    ExcelApp.cells.Item[sum,15].HorizontalAlignment := xlCenter;
                            ExcelApp.Cells[sum,16].Value :=JCFFrm.ADOQuery1.FieldByName('DXZHJ').AsString;
                    ExcelApp.cells.Item[sum,16].HorizontalAlignment := xlCenter;
                            ExcelApp.Cells[sum,17].Value :=JCFFrm.ADOQuery1.FieldByName('DWMC').AsString;
                    ExcelApp.cells.Item[sum,17].HorizontalAlignment := xlCenter;
                            ExcelApp.Cells[sum,18].Value :=JCFFrm.ADOQuery1.FieldByName('DCZY').AsString;
                    ExcelApp.cells.Item[sum,18].HorizontalAlignment := xlCenter;
                                    sum:=sum+1;
                                    JCFFrm.ADOQuery1.next;
                                end;
      

  3.   

    to  ksaiy(孤星的泪) "
    你这样好象只是对单张表进行导出,我现在要求报表分组用到三张表,你怎么做呢?
      

  4.   

    我也遇到你这个问题,到最后没办法把它导到ReportMachine中做的。