a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 編程 > Delphi > 正文

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

2020-01-31 20:51:57
字體:
來源:轉載
供稿:網友
復制代碼 代碼如下:

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
  //創建OLE對象
  try
    Excelid:=CreateOleObject( 'Excel.Application' );
  except
    on Exception do raise exception.Create('無法創建Xls文件,請確認是否安裝EXCEL')
  end;
  Excelid.Visible := false; //Excel顯示設置
  Excelid.WorkBooks.Add;  //生成新的excel文件
  //不用excel以前的頁
  Excelid.worksheets.add;
  dataPage:=Excelid.Worksheets.count;   //用作數據頁
  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
      //動態生成excel頁數
      //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 ;  //生成何種類型的圖********在此生成的是餅圖
      //設置x軸、y軸數據
      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]; //設定Chart類別坐標軸(x軸)的取值區域
      Range2 := Excelid.worksheets[dataPage].Range[cell3, cell4]; //設定Chart數值坐標軸(y軸)的取值區域
      series1:= achart1.chart.seriescollection ;
      //series1.add (Range2,xlColumns,false);  //設置y軸的數據
      series1.add (Range2,true);          //可以使用,能夠生成餅圖
      achart1.chart.seriescollection[1].name:='nihao';
      //設置餅圖的形式
      achart1.chart.seriescollection[1].ApplyDataLabels(xlDataLabelsShowLabelAndPercent,true,true,true);
      achart1.Chart.Axes[xlCategory].CategoryNames := Range1;  //設置x軸數據
      //series1.add (Range2,xlColumns,false);  //設置y軸的數據
      //achart1.Chart.Axes[xlCategory].CategoryNames := Range1;  //設置x軸數據
      //刪除右側的標題
      achart1.Chart.Legend.delete;
      //添加圖表標題
      achart1.Chart.HasTitle:=True;
      achart1.Chart.ChartTitle.Characters.Text:='收視率走勢圖';
      achart1.Chart.HasLegend:=true;
      achart1.Chart.Legend.Position := xlBottom;
      //圖表左標說明
      //achart1.Chart.Axes(xlValue,xlPrimary).HasTitle := True;
      //achart1.Chart.Axes(xlValue,xlPrimary).AxisTitle.Characters.Text := '收視率(%)';
      //圖表下標說明
      //achart1.Chart.Axes(xlCategory,xlPrimary).HasTitle:=True;
      //achart1.Chart.Axes(xlCategory,xlPrimary).AxisTitle.Characters.Text:='時間';
      ExRowsName:=ExRowsName+2;
      ExRowsValue:=ExRowsValue+2;
    end;  //如果時段設置被選中
    leftPostion:=20;
    topPostion:=topPostion+600;
    //showmessage(inttostr(dataPage));
  end;
  Excelid.Visible := true;
end;
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 国产精品资源在线 | 亚洲h视频在线观看 | 三级日韩 | 国产乱码精品一品二品 | 国产精品日韩专区 | 国产视频一区二区三区四区 | 精品在线免费观看 | 在线精品观看 | 一本色道久久综合亚洲精品不 | 成人国产精品久久久 | 婷婷综合网| 成人精品视频在线观看 | 国产精品中文字幕在线播放 | 欧美理论片在线 | 日韩电影免费在线观看中文字幕 | 亚洲精品乱码久久久久久蜜桃不卡 | 国产精品无码久久综合网 | 午夜高清免费视频 | 国产免费一区二区三区 | 欧美一区二区三区四区视频 | 成人免费淫片aa视频免费 | 久久99精品国产91久久来源 | 亚洲精品久久久久久久久 | 另类天堂| 欧美国产日韩另类 | av黄在线| 九九热视频在线 | 免费在线观看一区二区 | 国产91在线免费观看 | 十环传奇在线观看完整免费高清 | 欧洲亚洲成人 | 中文字幕三级 | 欧美综合视频在线观看 | 国内精品久久久久久久影视蜜臀 | 天天亚洲 | 美女天堂网 | 懂色av一区二区三区免费观看 | 免费av毛片| 99这里只有精品 | 久热伊人 | 久草新免费 |