如何指定Excel圖表中,X軸的資料來源? |
尚未結案
|
mnsf
初階會員 發表:104 回覆:90 積分:48 註冊:2003-11-25 發送簡訊給我 |
各位大大好,我利用以下程式產生一個Excel的圖表,產生出來的圖表如下
要 uses ActiveX;
var lcid: integer;
_Template, SheetType, _Type: OleVariant;
begin
lcid := GetUserDefaultLCID;
try
ExcelApplication1.Connect;
ExcelApplication1.Visible[lcid]:=True;
_Template:=xlWBATWorksheet;
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks.Add(_Template, lcid));
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1] as _Worksheet);
ExcelWorksheet1.Name := 'Data';
except
messagedlg('無法開啟Excel!',mtInformation,[mbok],0);
exit;
end; //(1)將資料轉出至Excel中
ExcelWorksheet1.Cells.Item[1,2]:='A';
ExcelWorksheet1.Cells.Item[1,3]:='B';
ExcelWorksheet1.Cells.Item[2,1]:='P1';
ExcelWorksheet1.Cells.Item[2,2]:='10';
ExcelWorksheet1.Cells.Item[2,3]:='20';
ExcelWorksheet1.Cells.Item[3,1]:='P2';
ExcelWorksheet1.Cells.Item[3,2]:='20';
ExcelWorksheet1.Cells.Item[3,3]:='10';
ExcelWorksheet1.Cells.Item[4,1]:='P3';
ExcelWorksheet1.Cells.Item[4,2]:='50';
ExcelWorksheet1.Cells.Item[4,3]:='30'; //(2)產生Chart
SheetType := TOleEnum(xlChart); // cast to avoid compiler range warnings
ExcelChart1.ConnectTo(ExcelWorkbook1.Sheets.Add(EmptyParam, EmptyParam, 1, SheetType, lcid) as _Chart);
ExcelChart1.Name := 'Chart'; //Sheet Name
ExcelChart1.HasLegend[lcid]:= True; //圖例 Legend
ExcelChart1.ChartType := TOleEnum(xlLineMarkers); //折線圖有Point,xlLine則是沒有Point
ExcelChart1.SetSourceData(ExcelWorksheet1.Range['A2','C4'],TOleEnum(xlRows)); //資料來源
_type:=xlValue; //設定橫軸
(ExcelChart1.Axes(_type,xlPrimary,lcid) as Axis).HasMajorGridlines:=True; //主要格線
(ExcelChart1.Axes(_type,xlPrimary,lcid) as Axis).HasMinorGridlines:=False; //次要格線
(ExcelChart1.Axes(_type,xlPrimary,lcid) as Axis).HasTitle:=true;
(ExcelChart1.Axes(_type,xlPrimary,lcid) as Axis).AxisTitle.Text:='Y軸';
_type:=xlCategory;
(ExcelChart1.Axes(_type,xlPrimary,lcid) as Axis).HasTitle:=true;
(ExcelChart1.Axes(_type,xlPrimary,lcid) as Axis).AxisTitle.Text:='X軸'; ExcelChart1.Disconnect;
ExcelWorksheet1.Disconnect;
ExcelWorkbook1.Disconnect;
ExcelApplication1.Disconnect; end; 請問,要怎麼做才可以把X軸的資料改成我想要的型式?(由1,2改為A,B)
|
deity
尊榮會員 發表:90 回覆:876 積分:678 註冊:2003-05-09 發送簡訊給我 |
您好:
//(2)產生Chart SheetType := TOleEnum(xlChart); // cast to avoid compiler range warnings ExcelChart1.ConnectTo(ExcelWorkbook1.Sheets.Add(EmptyParam, EmptyParam, 1, SheetType, lcid) as _Chart); ExcelChart1.Name := 'Chart'; //Sheet Name ExcelChart1.HasLegend[lcid]:= True; //圖例 Legend ExcelChart1.ChartType := TOleEnum(xlLineMarkers); //折線圖有Point,xlLine則是沒有Point============================ 为什么经过多年以后,得失的过程如此冷漠 ============================ |
mnsf
初階會員 發表:104 回覆:90 積分:48 註冊:2003-11-25 發送簡訊給我 |
|
pcboy
版主 發表:177 回覆:1838 積分:1463 註冊:2004-01-13 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |