Excel中Chart的DataLabels.NumberFormatLocal的問題 |
尚未結案
|
Dabaw
一般會員 ![]() ![]() 發表:1 回覆:2 積分:0 註冊:2004-04-24 發送簡訊給我 |
各位前輩請問一下: DataLabels.NumberFormatLocal 如何設定?
我這樣設定:
DataLabels.NumberFormatLocal := '0.00%'
會得到這樣的錯誤訊息:
"Invalid variant operation" 我的圓餅圖中數值想顯示至小數第二位。 原始程式如下:
//******************************** //xlsAP: TExcelApplication; //xlsWB: TExcelWorkbook; //xlsWS: TExcelWorksheet; //xlsCT: TExcelChart; //******************************** //樞紐分析表 xlsAP.Charts.Add(EmptyParam,EmptyParam,EmptyParam,EmptyParam,iLcID); xlsCT.ConnectTo(xlsAP.Charts[1] as _Chart); xlsCT.Name := '投資比例'; xlsCT.ChartType := xl3DPie; xlsCT.SetSourceData(xlsWS.Range[_CellCorFir, _Cell], xlColumns); xlsCT.ApplyDataLabels(xlDataLabelsShowLabelAndPercent, False, EmptyParam, True); SeriesCollection := xlsCT.SeriesCollection(1); //下面這一行錯誤 SeriesCollection.DataLabels.Select.NumberFormatLocal := '0.00%'; xlsCT.Location(xlLocationAutomatic, '投資比例');謝謝各位前輩。 |
ajaxhuang
一般會員 ![]() ![]() 發表:2 回覆:5 積分:1 註冊:2003-03-24 發送簡訊給我 |
procedure TForm1.aaaaa; var xlsAp: TExcelApplication; xlsWB: TExcelWorkbook; xlsWS: TExcelWorksheet; xlsCT: TExcelChart; SC: SeriesCollection; Series1: Series; DL: DataLabel; iLcID: integer; i, j: integer; begin iLcID := GetUserDefaultLCID; xlsAp:= TExcelApplication.Create(nil); xlsWB:= TExcelWorkbook.Create(nil); xlsWS:= TExcelWorksheet.Create(nil); xlsCT:= TExcelChart.Create(nil); xlsAP.Connect; xlsAP.Visible[iLcID] := true; xlsWB.ConnectTo(xlsAP.Workbooks.Add(null,0)); xlsWS.ConnectTo(xlsWB.Worksheets[1] as _Worksheet); xlsAP.Charts.Add(EmptyParam,EmptyParam,EmptyParam,EmptyParam,iLcID); xlsCT.ConnectTo(xlsAP.Charts[1] as _Chart); xlsCT.Name := '投資比例'; xlsCT.ChartType := xl3DPie; xlsCT.SetSourceData(xlsWS.Range['A1', 'B5'], xlColumns); xlsCT.ApplyDataLabels(xlDataLabelsShowLabelAndPercent, False, EmptyParam, True); SC := xlsCT.SeriesCollection as SeriesCollection; xlsWs.Cells.Item[1,2] := 'aaa'; xlsWs.Cells.Item[2,1] := 'A'; xlsWs.Cells.Item[2,2] := '10'; xlsWs.Cells.Item[3,1] := 'B'; xlsWs.Cells.Item[3,2] := '20'; xlsWs.Cells.Item[4,1] := 'C'; xlsWs.Cells.Item[4,2] := '30'; xlsWs.Cells.Item[5,1] := 'D'; xlsWs.Cells.Item[5,2] := '40'; for i := 1 to SC.Count do begin for j := 1 to 4 do begin DL := SC.Item(i).DataLabels(j) as DataLabel; DL.NumberFormat := '0.00%'; end; end; xlsCT.Location(xlLocationAutomatic, '投資比例'); end;不過要先知道數列中資料的數量...我想程式中應該可以記錄到... 試用看看吧~ |
Dabaw
一般會員 ![]() ![]() 發表:1 回覆:2 積分:0 註冊:2004-04-24 發送簡訊給我 |
引言:我在宣告 "SC: SeriesCollection" 有誤,如下: Constant or type identifier expected. 是我宣告方式錯誤嗎?還是還需要 Use 哪一個 Unit?procedure TForm1.aaaaa; var xlsAp: TExcelApplication; xlsWB: TExcelWorkbook; xlsWS: TExcelWorksheet; xlsCT: TExcelChart; SC: SeriesCollection; Series1: Series; DL: DataLabel; iLcID: integer; i, j: integer; begin iLcID := GetUserDefaultLCID; xlsAp:= TExcelApplication.Create(nil); xlsWB:= TExcelWorkbook.Create(nil); xlsWS:= TExcelWorksheet.Create(nil); xlsCT:= TExcelChart.Create(nil); xlsAP.Connect; xlsAP.Visible[iLcID] := true; xlsWB.ConnectTo(xlsAP.Workbooks.Add(null,0)); xlsWS.ConnectTo(xlsWB.Worksheets[1] as _Worksheet); xlsAP.Charts.Add(EmptyParam,EmptyParam,EmptyParam,EmptyParam,iLcID); xlsCT.ConnectTo(xlsAP.Charts[1] as _Chart); xlsCT.Name := '投資比例'; xlsCT.ChartType := xl3DPie; xlsCT.SetSourceData(xlsWS.Range['A1', 'B5'], xlColumns); xlsCT.ApplyDataLabels(xlDataLabelsShowLabelAndPercent, False, EmptyParam, True); SC := xlsCT.SeriesCollection as SeriesCollection; xlsWs.Cells.Item[1,2] := 'aaa'; xlsWs.Cells.Item[2,1] := 'A'; xlsWs.Cells.Item[2,2] := '10'; xlsWs.Cells.Item[3,1] := 'B'; xlsWs.Cells.Item[3,2] := '20'; xlsWs.Cells.Item[4,1] := 'C'; xlsWs.Cells.Item[4,2] := '30'; xlsWs.Cells.Item[5,1] := 'D'; xlsWs.Cells.Item[5,2] := '40'; for i := 1 to SC.Count do begin for j := 1 to 4 do begin DL := SC.Item(i).DataLabels(j) as DataLabel; DL.NumberFormat := '0.00%'; end; end; xlsCT.Location(xlLocationAutomatic, '投資比例'); end;不過要先知道數列中資料的數量...我想程式中應該可以記錄到... 試用看看吧~ |
Dabaw
一般會員 ![]() ![]() 發表:1 回覆:2 積分:0 註冊:2004-04-24 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |