Delphi Excel FastReport_sed

unit Unit1;
interface
uses
Printers,Windows, Messages, SysUtils, Variants, Classes,
Graphics, Controls, Forms,
Dialogs, ExcelXP, OleServer, StdCtrls, Grids,
Mask, RzEdit,frxDesgn,
frxClass, frxExportRTF, frxDBSet, frxExportPDF;
type papgxy=record
l,t,r,b:Extended;
end;


type bktype =record      // 边框
line:boolean;
color:integer;
width:Extended;
end;


type txttpye =record
text:string;
fontcolor, fontSize:integer;
FontBold,FontItalic:boolean;
thi,tvi:integer;//文字排列位置
fontstyle, fontname:string;
fontun,fontstr:boolean;
bcolor:integer;
end;


type cell= record
 t,L,h,w :Extended ;
 row,col,row2:integer;
 txt:txttpye;
 leftb,topb,Bottomb,Rightb:bktype;// 边框
 k:integer;
end;
type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Ea1: TExcelApplication;
    Es1: TExcelWorksheet;
    fr1: TfrxReport;
    Memo1: TMemo;
    Button4: TButton;
    Button5: TButton;
    Ed2: TEdit;
    Ed1: TEdit;
    Od1: TOpenDialog;
    sd1: TSaveDialog;
    Button6: TButton;
    ed3: TEdit;
    Button7: TButton;
    Button8: TButton;
    Cs1: TComboBox;
    Button9: TButton;
    fd3: TfrxDBDataset;
    fd2: TfrxDBDataset;
    fd1: TfrxDBDataset;
    Button3: TButton;
    frxPDFExport1: TfrxPDFExport;
    procedure FormCreate(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button7Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var  Form1: TForm1;
implementation
{$R *.dfm}


function color_i(i:integer):tcolor;     //颜色转换
var c1: tcolor;
begin
case i of
1 : c1:=$000000;
2 : c1:=$FFFFFF;
3 : c1:=$0000FF;
4 : c1:=$00FF00;
5 : c1:=$FF0000;
6 : c1:=$00FFFF;
7 : c1:=$FF00FF;
8 : c1:=$FFFF00;
9 : c1:=$000080;
10 : c1:=$008000;
11 : c1:=$800000;
12 : c1:=$008080;
13 : c1:=$800080;
14 : c1:=$808000;
15 : c1:=$C0C0C0;
16 : c1:=$808080;
17 : c1:=$FF9999;
18 : c1:=$663399;
19 : c1:=$CCFFFF;
20 : c1:=$FFFFCC;
21 : c1:=$660066;
22 : c1:=$8080FF;
23 : c1:=$CC6600;
24 : c1:=$FFCCCC;
25 : c1:=$800000;
26 : c1:=$FF00FF;
27 : c1:=$00FFFF;
28 : c1:=$FFFF00;
29 : c1:=$800080;
30 : c1:=$000080;
31 : c1:=$808000;
32 : c1:=$FF0000;
33 : c1:=$FFCC00;
34 : c1:=$FFFFCC;
35 : c1:=$CCFFCC;
36 : c1:=$99FFFF;
37 : c1:=$FFCC99;
38 : c1:=$CC99FF;
39 : c1:=$FF99CC;
40 : c1:=$99CCFF;
41 : c1:=$FF6633;
42 : c1:=$CCCC33;
43 : c1:=$00CC99;
44 : c1:=$00CCFF;
45 : c1:=$0099FF;
46 : c1:=$0066FF;
47 : c1:=$996666;
48 : c1:=$969696;
49 : c1:=$663300;
50 : c1:=$669933;
51 : c1:=$003300;
52 : c1:=$003333;
53 : c1:=$003399;
54 : c1:=$663399;
55 : c1:=$993333;
56 : c1:=$333333;
 end;
  Result:=c1;
end;
function cd(i:Extended):Extended;
begin
 Result:=1.34*i;
end;


procedure papg_set(PageSet:Variant;P:Tfrxreportpage);
var a:integer;
begin
p.LeftMargin :=PageSet.LeftMargin/2.8348;
p.TopMargin  :=PageSet.topMargin/2.8348;
p.RightMargin :=PageSet.RightMargin/2.8348;
p.BottomMargin :=PageSet.BottomMargin/2.8348;
p.PrintOnPreviousPage:=True ; //合并打印
if PageSet.Orientation=2
 then p.Orientation:=poLandscape
 else p.Orientation:=poPortrait;
p.PaperSize:=PageSet.PaperSize;
{
if PageSet.PaperSize=xlPaperA3 then p.PaperSize:=DMPAPER_A3;
if PageSet.PaperSize=xlPaperA4 then p.PaperSize:=DMPAPER_A4;
if PageSet.PaperSize=xlPaperA5 then p.PaperSize:=DMPAPER_A5;
 }    
end;




function cell_du(row,col:integer;o1:integer;row2:integer):cell;
var mm:cell;
ms :boolean;
fontsyle1:string;
r2,c2:integer;
begin
with form1.Es1 do
begin
mm.txt.text :=Cells.Item[row,col];                 // 内容
mm.t        := Cells.Item[row,col].top;            //顶
mm.l        := cells.Item[row,col].left;           //左
mm.k:=0;
r2:= Cells.Item[row,col].MergeArea.Rows.Count;
mm.row2 :=R2;
if (o1>=1) and (col>=1) then
 mm.l:= cells.Item[row,col].left-cells.Item[row,2].left; //左


if (o1>=1) and (row>1)and (row>=row2) then
 mm.t:= cells.Item[row,col].top-cells.Item[row2,1].top; //顶
 ms:= cells.Item[row,col].MergeCells;   //检查是否为 合并单位
if ms then
begin
r2:= Cells.Item[row,col].MergeArea.Rows.Count;
c2:= Cells.Item[row,col].MergeArea.Columns.Count;
mm.h := Cells.Item[row+r2,col].top-Cells.Item[row,col].top;  //高度
mm.w := Cells.Item[row,col+c2].left-Cells.Item[row,col].left;//宽度
end else
begin
mm.h:= Cells.Item[row,col].height;      //高度
mm.w:= Cells.Item[row,col].width;       //宽度
end;
if o1=3 then
begin
mm.txt .FontBold := Cells.Item[row,col].font.Bold;
mm.txt .FontItalic:= Cells.Item[row,col].Font.Italic;
mm.txt .thi:=Cells.Item[row,col].HorizontalAlignment;
mm.txt .tvi:=Cells.Item[row,col].VerticalAlignment;


mm.txt.fontname := Cells.Item[row,col].font.name;      // 字名称
mm.txt.fontSize := Cells.Item[row,col].font.Size;      // 字大小
mm.txt.fontcolor:= Cells.Item[row,col].font.ColorIndex;// 字颜色
if mm.txt.fontcolor<=0 then  mm.txt.fontcolor :=1;
//mm.fontstyle:= cells.Item[row,col].FontStyle;      //字格式
mm.txt.bcolor:= Cells.Item[row,col].Interior.ColorIndex;// 底颜色


if  mm.txt.bcolor<=0 then  mm.txt.bcolor :=2;
//左1
If cells.Item[row,col].Borders[xlEdgeLeft].LineStyle = xlContinuous
     Then mm.k := 1 ;
// 右2
If cells.Item[row,col].Borders[xlEdgeRight].LineStyle = xlContinuous
    Then mm.k := mm.k + 2 ;
// 上4
If cells.Item[row,col].Borders[xlEdgeTop].LineStyle = xlContinuous
   Then mm.k := mm.k + 4 ;
//  '下8
If cells.Item[row,col].Borders[xlEdgeBottom].LineStyle = xlContinuous
 Then mm.k := mm.k + 8 ;
end;
 Result:=mm;
end;
end;


procedure txt_xie(j,i:integer;mm:cell);
var  e:TfrxMemoView; //text
begin
e:= TfrxMemoView.Create(form1.fr1.Pages[1]);
e.Left:=cd(mm.L);
e.top:=cd(mm.t);
e.Height:=cd(mm.h);
e.Width :=cd(mm.w);
e.Name  :='c'+ inttostr(j)+'r'+inttostr(i);
e.Text  :=mm.txt.text;//+' * '+  e.Name  ;
e.Font.Size :=mm.txt.fontSize ;
e.Font.Name :=mm.txt.fontname ;
e.Font.Color:= color_i(mm.txt.fontcolor);
e.Color := color_i(mm.txt.bcolor);
e.Frame.Typ:=[ftLeft,ftRight,ftTop,ftBottom];
end;
procedure pic2_xie(j,i:integer;mm:cell;pic:TfrxPictureView);
begin
pic.Left:=cd(mm.L);
pic.top:=cd(mm.t);
pic.Height:=cd(mm.h);
pic.Width :=cd(mm.w);
pic.Name  :=pic.Parent.Name+inttostr(j)+'_'+inttostr(i);
//e.Text  :=mm.txt.text ;//+' * '+  e.Name;
case mm.k of
   1:pic.Frame.Typ :=[ftLeft ];
   2:pic.Frame.Typ :=[ftRight ];
   3:pic.Frame.Typ :=[ftLeft,ftRight ];
   4:pic.Frame.Typ :=[ftTop ];
   5:pic.Frame.Typ :=[ftLeft,ftTop ];
   6:pic.Frame.Typ :=[ftRight,ftTop ];
   7:pic.Frame.Typ :=[ftLeft,ftRight,ftTop ];
   8:pic.Frame.Typ :=[ftBottom ];
   9:pic.Frame.Typ :=[ftLeft,ftBottom ];
  10:pic.Frame.Typ :=[ftRight,ftBottom ];
  11:pic.Frame.Typ :=[ftLeft,ftRight,ftBottom ];
  12:pic.Frame.Typ :=[ftTop,ftBottom ];
  13:pic.Frame.Typ :=[ftLeft,ftTop,ftBottom ];
  14:pic.Frame.Typ :=[ftRight,ftTop,ftBottom ];
  15:pic.Frame.Typ :=[ftLeft,ftRight,ftTop,ftBottom];
else
     pic.Frame.Typ :=[];
end;
end;


procedure txt2_xie(j,i:integer;mm:cell;e:TfrxMemoView);
begin
e.Left:=cd(mm.L);
e.top:=cd(mm.t);
e.Height:=cd(mm.h);
e.Width :=cd(mm.w);
e.Name  :=E.Parent.Name+inttostr(j)+'_'+inttostr(i);
e.Text  :=mm.txt.text ;//+' * '+  e.Name  ;
e.Font.Size :=mm.txt.fontSize ;
e.Font.Name :=mm.txt.fontname ;
e.Font.Style :=[];
if mm.txt.FontBold
 then  e.Font.Style:= [fsBold];
if mm.txt.FontItalic
 then  e.Font.Style:=e.Font.Style + [fsItalic];


 case mm.txt.tvi of  //垂直排版
-4108:e.VAlign:=vaCenter;
-4107:e.VAlign:=vaBottom ;
else
e.VAlign:=vatop ;
 end;


case mm.txt.thi of  //水平排版
-4108:e.HAlign := haCenter;
-4152:e.HAlign := haRight;
1    :e.HAlign := haRight;
else
e.HAlign := haLeft;
 end;
e.Font.Color:=  color_i(mm.txt.fontcolor);        //字颜色
e.Color := color_i(mm.txt.bcolor);                //背景颜色


case mm.k of
1:e.Frame.Typ:=[ ftLeft];
2:e.Frame.Typ:=[ ftRight];
3:e.Frame.Typ:=[ ftLeft,ftRight];
4:e.Frame.Typ:=[ ftTop];
5:e.Frame.Typ:=[ ftLeft,ftTop];
6:e.Frame.Typ:=[ ftRight,ftTop];
7:e.Frame.Typ:=[ ftLeft,ftRight,ftTop];
8:e.Frame.Typ:=[ ftBottom];
9:e.Frame.Typ:=[ ftLeft,ftBottom];
10:e.Frame.Typ:=[ ftRight,ftBottom];
11:e.Frame.Typ:=[ ftLeft,ftRight,ftBottom];
12:e.Frame.Typ:=[ ftTop,ftBottom];
13:e.Frame.Typ:=[ ftLeft,ftTop,ftBottom];
14:e.Frame.Typ:=[ ftRight,ftTop,ftBottom];
15:e.Frame.Typ:=[ ftLeft,ftRight,ftTop,ftBottom];
else
e.Frame.Typ :=[];
end;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
ed1.Text :=ExtractFilePath(ParamStr(0))+'模板.xls';
ed2.text:=ExtractFilePath(ParamStr(0));
ed3.Text :='ont.fr3';
end;


procedure TForm1.Button4Click(Sender: TObject);
begin
if od1.Execute then
begin
  ed1.Text := od1.FileName ;
  Button8.Click ;
end;
end;


procedure TForm1.Button5Click(Sender: TObject);
begin
if sd1.Execute then
begin
ed2.Text:=ExtractFilePath(sd1.FileName) ;
if pos('.fr3',sd1.FileName)>0
 then
   ed3.Text :=ExtractFileName(sd1.FileName)
 else
   ed3.Text :=ExtractFileName(sd1.FileName)+'.fr3';
end;
end;


{ vba
XlPaperSize 可为下面 XlPaperSize 常量之中的一个。


xlPaper11x17. 11 in. x 17 in.
xlPaperA4. A4 (210 mm x 297 mm)
xlPaperA5. A5 (148 mm x 210 mm)
xlPaperB5. A5 (148 mm x 210 mm)
xlPaperDsheet. D size sheet
xlPaperEnvelope11. Envelope #11 (4-1/2 in. x 10-3/8 in.)
xlPaperEnvelope14. Envelope #14 (5 in. x 11-1/2 in.)
xlPaperEnvelopeB4. Envelope B4 (250 mm x 353 mm)
xlPaperEnvelopeB6. Envelope B6 (176 mm x 125 mm)
xlPaperEnvelopeC4. Envelope C4 (229 mm x 324 mm)
xlPaperEnvelopeC6. Envelope C6 (114 mm x 162 mm)
xlPaperEnvelopeDL. Envelope DL (110 mm x 220 mm)
xlPaperEnvelopeMonarch. Envelope Monarch (3-7/8 in. x 7-1/2 in.)
xlPaperEsheet. E size sheet
xlPaperFanfoldLegalGerman. German Legal Fanfold (8-1/2 in. x 13 in.)
xlPaperFanfoldUS. U.S. Standard Fanfold (14-7/8 in. x 11 in.)
xlPaperLedger. Ledger (17 in. x 11 in.)
xlPaperLetter. Letter (8-1/2 in. x 11 in.)
xlPaperNote. Note (8-1/2 in. x 11 in.)
xlPaperStatement. Statement (5-1/2 in. x 8-1/2 in.)
xlPaperUser. 用户自己定义
xlPaper10x14. 25.40 cm. x 35.56 cm.
xlPaperA3. A3 (297 mm x 420 mm)
xlPaperA4Small. A4 Small (210 mm x 297 mm)
xlPaperB4. B4 (250 mm x 354 mm)
xlPaperCsheet. C size sheet
xlPaperEnvelope10. Envelope #10 (4-1/8 in. x 9-1/2 in.)
xlPaperEnvelope12. Envelope #12 (4-1/2 in. x 11 in.)
xlPaperEnvelope9. Envelope #9 (3-7/8 in. x 8-7/8 in.)
xlPaperEnvelopeB5. Envelope B5 (176 mm x 250 mm)
xlPaperEnvelopeC3. Envelope C3 (324 mm x 458 mm)
xlPaperEnvelopeC5. Envelope C5 (162 mm x 229 mm)
xlPaperEnvelopeC65. Envelope C65 (114 mm x 229 mm)
xlPaperEnvelopeItaly. Envelope (110 mm x 230 mm)
xlPaperEnvelopePersonal. Envelope (3-5/8 in. x 6-1/2 in.)
xlPaperExecutive. Executive (7-1/2 in. x 10-1/2 in.)
xlPaperFanfoldStdGerman. German Legal Fanfold (8-1/2 in. x 13 in.)
xlPaperFolio. Folio (8-1/2 in. x 13 in.)
xlPaperLegal. Legal (8-1/2 in. x 14 in.)
xlPaperLetterSmall. Letter Small (8-1/2 in. x 11 in.)
xlPaperQuarto. Quarto (215 mm x 275 mm)
xlPaperTabloid. Tabloid (11 in. x 17 in.)
}
procedure TForm1.Button8Click(Sender: TObject);
var b,a:string;
i,j,k,n:integer;
begin
ea1.Connect;
ea1.Workbooks.Open(ed1.Text ,null,null,null,null,
    null,null,null,null,null,null,null,null,null,null,0);


cs1.Items.Clear ;


k:=ea1.Workbooks[ExtractFileName(ed1.Text)].Sheets.Count;
for j:=1 to k do
begin
es1.ConnectTo(ea1.Workbooks[ExtractFileName(ed1.Text)].Worksheets[j] as ExcelWorksheet);
b:=es1.Name;
cs1.Items.Add(b);
end;
cs1.Text :=cs1.Items.Strings[0];
Button9.Enabled:=true;
end;


 procedure TForm1.Button9Click(Sender: TObject);
var
PageSet:OLEVariant;
i,j,k :integer;
frtemp: TfrxReport;
mm1,mm:cell;
r11,c11,r1:integer;
row,col:integer;
e  :TfrxMemoView;     //  text 文字框
pic:TfrxPictureView;  //  图片框


pt:TfrxReportTitle;
pf:TfrxReportSummary;
ht:TfrxPageHeader;
hf:TfrxPageFooter;
md:TfrxMasterData;
Mxd:TfrxDetailData;
sd:TfrxSubdetailData;
 P:Tfrxreportpage;
tempage:TfrxReportPage;
kk:integer;
Designer: TfrxDesignerForm;//
begin
frtemp:=TfrxReport.Create(form1);


// frtemp.DataSets.Add(fd1);
// frtemp.DataSets.Add(fd2);
// frtemp.DataSets.Add(fd3);
tempage:=TfrxReportPage.Create(frtemp);
tempage.NAME:='page1';
P:=Tfrxreportpage(tempage);
es1.ConnectTo(ea1.Workbooks
[ExtractFileName(ed1.Text)].Worksheets[cs1.text ] as ExcelWorksheet);


PAGESET:=ES1.PageSetup;
papg_set(PAGESET,p);
PAGESET:=UnAssigned;
  col :=es1.UsedRange[1].Columns.Count ; //excel   的列
  row :=es1.UsedRange[1].Rows.Count;     //excel   的行


 for k:=1 to row do
begin
  r1:= es1.Cells.Item[k,1].MergeArea.Row;//s.Count;
 if r1=k then
 begin
 mm:= cell_du(k,1,0,0);
 if mm.txt.text ='表头'
  then   begin
  pt:= TfrxReportTitle.Create(tempage);
  pt.Height:=cd(mm.h);
  pt.Name  :='pt';//'ban'+inttostr(k);
  for i:=k to k+mm.row2-1 do  //行
  for j:=2 to col do          //列
  begin
    r11:= es1.Cells.Item[i,j].MergeArea.Row;//s.Count;
    c11:= es1.Cells.Item[i,j].MergeArea.Column;//s.Count;
    if (r11=I) and (c11=J) then
    begin
     mm1:= cell_du(i,j,3,k);
      if mm1.txt.text='{[图片]}'
       then  begin
         pic:= TfrxPictureView.Create(pt);
         pic2_xie(i,j,mm1,pic);
         end else
         begin
          e:= TfrxMemoView.Create(pt);
          txt2_xie(i,j,mm1,e);
         end;
    end;
  end;
  end;


 if mm.txt.text ='页头'
 then begin
  ht:= TfrxPageHeader.Create(tempage);
  ht.Height:=cd(mm.h);
  ht.Name  :='HT';
  for i:=k to k+mm.row2-1 do  //行
  for j:=2 to col do        //列
  begin
  r11:= es1.Cells.Item[i,j].MergeArea.Row;//s.Count;
  c11:= es1.Cells.Item[i,j].MergeArea.Column;//s.Count;
  if (r11=I) and (c11=J) then
   begin
    mm1:= cell_du(i,j,3,k);    //读 excel cell的文字
       if mm1.txt.text='{[图片]}'
        then  begin
         pic:= TfrxPictureView.Create(HT);
         pic2_xie(i,j,mm1,pic);
                 end else
         begin
          e:= TfrxMemoView.Create(HT);
          txt2_xie(i,j,mm1,e);
         end;
   // e:= TfrxMemoView.Create(HT);
   // txt2_xie(i,j,mm1,e);
    end;
  end;
 end;
 if mm.txt.text ='页脚'
 then begin
  hf:=TfrxPageFooter.Create(tempage);
  hf.Height:=cd(mm.h);
  hf.Name  :='HF';
  for i:=k to k+mm.row2-1 do  //行
  for j:=2 to col do        //列
  begin
  r11:= es1.Cells.Item[i,j].MergeArea.Row;//s.Count;
  c11:= es1.Cells.Item[i,j].MergeArea.Column;//s.Count;
  if (r11=I) and (c11=J) then
   begin
    mm1:= cell_du(i,j,3,k);


     if mm1.txt.text='{[图片]}'
      then  begin
        pic:= TfrxPictureView.Create(HF);
        pic2_xie(i,j,mm1,pic);
         end else
       begin
         e:= TfrxMemoView.Create(HF);
         txt2_xie(i,j,mm1,e);
        end;
    //e:= TfrxMemoView.Create(HF);
    //txt2_xie(i,j,mm1,e);
    end;
  end;
  end;
 TRY
 if mm.txt.text ='主数据'
   then  begin
    md:=TfrxMasterData.Create(tempage);
    md.Height:=cd(mm.h);
    frtemp.DataSets.Add(fd1);
    md.Name  :='MD';
    md.DataSet:=fd1;
    MD.TOP:=MM.T;
  //md.DataSetName :='mda';
   memo1.Lines.Text :=  tempage.DataSetName;
  //.DataSet.
   for i:=k to k+mm.row2-1 do  //行
   for j:=2 to col do        //列
   begin
     r11:= es1.Cells.Item[i,j].MergeArea.Row;//s.Count;
     c11:= es1.Cells.Item[i,j].MergeArea.Column;//s.Count;
    if (r11=I) and (c11=J) then
     begin
      mm1:= cell_du(i,j,3,k);
      if mm1.txt.text='{[图片]}'
        then  begin
         pic:= TfrxPictureView.Create(MD);
         pic2_xie(i,j,mm1,pic);
        end else
         begin
          e:= TfrxMemoView.Create(MD);
          txt2_xie(i,j,mm1,e);
         end;
     // e:= TfrxMemoView.Create(MD);
      //txt2_xie(i,j,mm1,e);
     end;
   end;
  end;
 if mm.txt.text ='明细数据'
  then  begin
  Mxd:=TfrxDetailData.Create(tempage);
  Mxd.Height:=cd(mm.h);
  Mxd.Name  :='MXD';
  frtemp.DataSets.Add(fd2);
  MXD.TOP:=MM.T;
  mxd.DataSet:=fd2;
  for i:=k to k+mm.row2-1 do  //行
  for j:=2 to col do        //列
  begin
  r11:= es1.Cells.Item[i,j].MergeArea.Row;//s.Count;
  c11:= es1.Cells.Item[i,j].MergeArea.Column;//s.Count;
  if (r11=I) and (c11=J) then
   begin
    mm1:= cell_du(i,j,3,k);
       if mm1.txt.text='{[图片]}'
        then  begin
         pic:= TfrxPictureView.Create(MXD);
         pic2_xie(i,j,mm1,pic);
          end else
         begin
          e:= TfrxMemoView.Create(MXD);
          txt2_xie(i,j,mm1,e);
         end;
   // e:= TfrxMemoView.Create(MXD);
   // txt2_xie(i,j,mm1,e);
    end;
  end;
  end;


 if mm.txt.text ='子数据'
 then begin
  sd:=TfrxSubdetailData.Create(tempage);
  sd.Height:=cd(mm.h);
  sd.Name  :='SD';
  frtemp.DataSets.Add(fd3);
  sd.DataSet:=fd3;
  SD.TOP:=MM.T;
  for i:=k to k+mm.row2-1 do  //行
  for j:=2 to col do        //列
  begin
  r11:= es1.Cells.Item[i,j].MergeArea.Row;//s.Count;
  c11:= es1.Cells.Item[i,j].MergeArea.Column;//s.Count;
  if (r11=I) and (c11=J) then
   begin
    mm1:= cell_du(i,j,3,k);
       if mm1.txt.text='{[图片]}'
        then
        begin
         pic:= TfrxPictureView.Create(SD);
         pic2_xie(i,j,mm1,pic);
          end
       else
        begin
          e:= TfrxMemoView.Create(SD);
          txt2_xie(i,j,mm1,e);
         end;


    //e:= TfrxMemoView.Create(SD);
    //txt2_xie(i,j,mm1,e);
    end;
  end;
  end;
 if mm.txt.text ='表合计'  then


  begin
  pf:=TfrxReportSummary.Create(tempage);
  pf.Height:=cd(mm.h);
  pf.Name  :='PF';
  for i:=k to k+mm.row2-1 do  //行
  for j:=2 to col do        //列
   begin
   r11:= es1.Cells.Item[i,j].MergeArea.Row;//s.Count;
   c11:= es1.Cells.Item[i,j].MergeArea.Column;//s.Count;
    if (r11=I) and (c11=J) then
    begin
     mm1:= cell_du(i,j,3,k);


       if mm1.txt.text='{[图片]}'
        then  begin
         pic:= TfrxPictureView.Create(PF);
         pic2_xie(i,j,mm1,pic);
                 end else
         begin
          e:= TfrxMemoView.Create(PF);
          txt2_xie(i,j,mm1,e);
         end;
    //e:= TfrxMemoView.Create(pF);
    //txt2_xie(i,j,mm1,e);
    end;
   end;
  end;
   except
   SHOWMESSAGE('错误出如今 K='+INTTOSTR(K)+' I='+INTTOSTR(I)+ ' JC='+INTTOSTR(I) )
   END;
 end;




 end;
// frtemp.SetProperty()
 //.setpr
 frtemp.DesignReport();
 frtemp.SaveToFile(ed2.Text +ed3.Text);
 frtemp.Free;
  fr1.LoadFromFile(ed2.Text +ed3.Text);
  


 //fr1.DesignPreviewPage;
 end;




{
ver:
aaaa:OLEVariant
ExcelApp.activeworkbook.close;
  ExcelApp.Quit;
  ExcelApp:=UnAssigned;
}
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
es1.Disconnect;
ea1.Quit ;
ea1.Disconnect ;


end;


procedure TForm1.Button7Click(Sender: TObject);
var i:Integer;
begin


fr1.DesignReport();
end;


procedure TForm1.Button2Click(Sender: TObject); //连续打印2个报表
begin
//   fr1.LoadFromFile(ed2.Text +ed3.Text);
fr1.LoadFromFile('D:\excel\新建目录 (2)\1.fr3');


fr1.PrepareReport(True );
fr1.LoadFromFile('D:\excel\新建目录 (2)\3.fr3');
fr1.PrepareReport(False );


fr1.ShowPreparedReport ;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin   
fr1.ShowReport(True );
end;


procedure TForm1.Button3Click(Sender: TObject);
var i:Integer ;
p : TfrxReportPage;


begin     //3个报表连续 合并
fr1.LoadFromFile('D:\excel\新建目录 (2)\4.fr3');
fr1.PrepareReport(True);


fr1.LoadFromFile('D:\excel\新建目录 (2)\1.fr3');
fr1.PrepareReport(false);
p := TfrxReportPage(fr1.Objects[1]);
p.PrintOnPreviousPage :=True;
fr1.DesignReport();


fr1.LoadFromFile('D:\excel\新建目录 (2)\3.fr3');
fr1.PrepareReport(False);
p := TfrxReportPage(fr1.Objects[1]);
p.PrintOnPreviousPage :=True;


fr1.DesignReport();
 { i:= fr1.PreviewPages.Count;
  ShowMessage(IntToStr(i));
fr1.PreviewPages.Page[0].PrintOnPreviousPage:=True;
}
fr1.DesignReport();
 p := TfrxReportPage(fr1.Objects[1]);
p.PrintOnPreviousPage :=True;
p := TfrxReportPage(fr1.Objects[1]);
p.PrintOnPreviousPage :=True;
fr1.ShowPreparedReport ;
end;


end.