麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > Delphi > 正文

Delphi 生成excel中餅圖的實例代碼

2020-01-31 20:51:57
字體:
供稿:網(wǎng)友
復(fù)制代碼 代碼如下:

var
  i,j,m,n,count1:integer;
  str:string;
  Jdate:tdatetime;
  channellist,potBstrtime,potEstrtime,Jchannelname:string;
  Rres:boolean;
  JSHR:double;
  Excelid,achart1,cell1,cell2,cell3,cell4,cellMiddle,Range1,Range2,series1:variant;
  ExRowsValue,ExRowsName,ExClos:Integer;
  ImagePage,dataPage:integer;
  leftPostion,topPostion,widthPostion,heightPostion:integer;
begin
  //創(chuàng)建OLE對象
  try
    Excelid:=CreateOleObject( 'Excel.Application' );
  except
    on Exception do raise exception.Create('無法創(chuàng)建Xls文件,請確認是否安裝EXCEL')
  end;
  Excelid.Visible := false; //Excel顯示設(shè)置
  Excelid.WorkBooks.Add;  //生成新的excel文件
  //不用excel以前的頁
  Excelid.worksheets.add;
  dataPage:=Excelid.Worksheets.count;   //用作數(shù)據(jù)頁
  Excelid.worksheets.add;
  ImagePage:=Excelid.Worksheets.count;
  //showmessage(inttostr(dataPage));
  //showmessage(inttostr(ImagePage)+'sdfg');
  Jdate:=DateTimePicker1.Date;
  count1:=0;
  ExRowsValue:=1; //存儲值
  ExRowsName:=2;  //存儲名稱
  //取得頻率編號
  for i:=0 to CheckListBoxFQ.Items.Count-1 do
  begin
    if CheckListBoxFQ.Checked[i] then
    begin
     channellist:= QCaky.FChannelList[i]+','+channellist;
    end;
  end;
  delete(channellist,length(channellist),1);
  leftPostion:=20;
  topPostion:=50;
  widthPostion:=450;
  heightPostion:=230;
  for i:=0 to CheckListBoxPOTT.Items.Count-1 do
  begin
    if CheckListBoxPOTT.Checked[i] then
    begin
      //動態(tài)生成excel頁數(shù)
      //Excelid.worksheets.add;
      //sheetCount:=sheetCount+1;
      //Excelid.worksheets[sheetCount].name:='圖表頁'+inttostr(sheetCount);
      //在這里生成圖表
      if CheckListBoxPOTT.Items[i]='全天' then
      begin
        potBstrtime:='';
        potEstrtime:='';
      end
      else
      begin
        potBstrtime:=QCaky.FPOTbeginList[i];
        potEstrtime:=QCaky.FPOTendList[i];
      end;
      Rres:=QCaky.getFQShr(Jdate,FormMain.QAreacode,channellist,potBstrtime,potEstrtime);  //取得占有率
      ExClos:=1;
      while not QCaky.FADOQueryFQ.Eof do
      begin
        Excelid.worksheets[dataPage].Activate;
        Jchannelname:=QCaky.FADOQueryFQ.fieldbyname('channelname').AsString;
        JSHR:=QCaky.FADOQueryFQ.fieldbyname('allshr').AsFloat;
        Excelid.worksheets[dataPage].Cells[ExRowsName,ExClos].Value :=Jchannelname;
        Excelid.worksheets[dataPage].Cells[ExRowsValue,ExClos].Value :=JSHR;
        inc(ExClos);
        QCaky.FADOQueryFQ.Next;
      end;
       {添加一個二維圖(20,50,450,230)表示(左,頂,寬,高)}
      //achart1 := Excelid.worksheets[ImagePage].chartobjects.add(20,50,450,230);
      achart1 := Excelid.worksheets[ImagePage].chartobjects.add(leftPostion,topPostion,widthPostion,heightPostion);
      achart1.chart.charttype := xl3DPie ;  //生成何種類型的圖********在此生成的是餅圖
      //設(shè)置x軸、y軸數(shù)據(jù)
      cell1 :=  Excelid.worksheets[dataPage].Cells[ExRowsName,1];
      cell2 :=  Excelid.worksheets[dataPage].Cells[ExRowsName,ExClos];
      cell3 :=  Excelid.worksheets[dataPage].Cells[ExRowsValue,1];
      cell4 :=  Excelid.worksheets[dataPage].Cells[ExRowsValue,ExClos];
      Range1 := Excelid.worksheets[dataPage].Range[cell1, cell2]; //設(shè)定Chart類別坐標(biāo)軸(x軸)的取值區(qū)域
      Range2 := Excelid.worksheets[dataPage].Range[cell3, cell4]; //設(shè)定Chart數(shù)值坐標(biāo)軸(y軸)的取值區(qū)域
      series1:= achart1.chart.seriescollection ;
      //series1.add (Range2,xlColumns,false);  //設(shè)置y軸的數(shù)據(jù)
      series1.add (Range2,true);          //可以使用,能夠生成餅圖
      achart1.chart.seriescollection[1].name:='nihao';
      //設(shè)置餅圖的形式
      achart1.chart.seriescollection[1].ApplyDataLabels(xlDataLabelsShowLabelAndPercent,true,true,true);
      achart1.Chart.Axes[xlCategory].CategoryNames := Range1;  //設(shè)置x軸數(shù)據(jù)
      //series1.add (Range2,xlColumns,false);  //設(shè)置y軸的數(shù)據(jù)
      //achart1.Chart.Axes[xlCategory].CategoryNames := Range1;  //設(shè)置x軸數(shù)據(jù)
      //刪除右側(cè)的標(biāo)題
      achart1.Chart.Legend.delete;
      //添加圖表標(biāo)題
      achart1.Chart.HasTitle:=True;
      achart1.Chart.ChartTitle.Characters.Text:='收視率走勢圖';
      achart1.Chart.HasLegend:=true;
      achart1.Chart.Legend.Position := xlBottom;
      //圖表左標(biāo)說明
      //achart1.Chart.Axes(xlValue,xlPrimary).HasTitle := True;
      //achart1.Chart.Axes(xlValue,xlPrimary).AxisTitle.Characters.Text := '收視率(%)';
      //圖表下標(biāo)說明
      //achart1.Chart.Axes(xlCategory,xlPrimary).HasTitle:=True;
      //achart1.Chart.Axes(xlCategory,xlPrimary).AxisTitle.Characters.Text:='時間';
      ExRowsName:=ExRowsName+2;
      ExRowsValue:=ExRowsValue+2;
    end;  //如果時段設(shè)置被選中
    leftPostion:=20;
    topPostion:=topPostion+600;
    //showmessage(inttostr(dataPage));
  end;
  Excelid.Visible := true;
end;
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 久久sp | 精品亚洲综合 | 性盈盈盈影院 | 色综合精品 | 日本中文字幕久久 | 亚洲九色 | 色淫影院 | 一区二区久久久久草草 | 国产高清美女一级毛片久久 | 操你逼| 黄视频免费在线 | 欧美中文字幕一区二区 | av成人免费观看 | 中国黄色一级生活片 | 欧美一级做性受免费大片免费 | 污视频在线免费播放 | 国产精品自拍99 | 露脸各种姿势啪啪的清纯美女 | 久久久tv| 怦然心动50免费完整版 | 黄污网站在线观看 | 国产精品久久久久久久久粉嫩 | 免费黄色小网站 | 国产精品一区二区视频 | 青青草在线免费观看 | 天天看成人免费毛片视频 | 91成人在线网站 | 日本中文字幕高清 | 精品亚洲一区二区三区 | 国产成人77亚洲精品www | 青青草华人在线 | 国产 日韩 亚洲 欧美 | 国产精品美女久久久久久网站 | 久久影城 | 午夜激情视频免费 | 香蕉成人在线视频 | 精选久久 | 国产999视频在线观看 | 国产妇女乱码一区二区三区 | 欧美一级网 | 99精品视频久久精品视频 |