excel := new TSExcelFile();
_test_addchart(excel);
//_test_getcharts(excel);


Function _test_getcharts(excel);
Begin
	f := 'F:\\temp\\test.xlsx';
	[err, errmsg] := excel.OpenFile('', f);
	if err then return 
		echo 'Open Fail:', errmsg, '\n';
	[err, charts] := excel.GetCharts('Sheet1');
	for i:=0 to length(charts)-1 do Begin
		println('ChartName={}, Title={}, Series={}',charts[i].Chart.Name, charts[i].Chart.Title, charts[i].Chart.Series);
	End;
	charts[1].RemoveSeries(1);
	[err, errmsg] := excel.SaveAs('', 'f:\\temp\\ch.xlsx');
	println('SaveAs->{}',err);
	//charts[i].RemoveSeries(i);
	//charts[i].AddSeries(Name, Categories, Values);
	//charts[i].UpdateSeries(i, Name, Categories, Values);
	//charts[i].UpdateTitle(i, title);
End;

Function _test_addchart(excel);
Begin
	//f := 'F:\\temp\\test.xlsx';
	[err, errmsg] := excel.NewFile();
	//[err, errmsg] := excel.OpenFile('', f);
	if err then return 
		echo 'Open Fail:', errmsg, '\n';
	//插入数据表
	data := array(("Name":"Small","Apple":2,"Orange":3,"Pear":3),
        ("Name":"Normal","Apple":5,"Orange":2,"Pear":4),
        ("Name":"Large","Apple":6,"Orange":7,"Pear":8));
	chart := TOfficeObj('TChart');
	chart.Type := 'col';
	chart.VaryColors := true;
	chart.BegColOff := 80000;
	chart.BegRowOff := 80000;
	chart.Name := 'test chart 1';
	chart.Title := 'Hans Chart';
	
	chart.AddSeries('Sheet1!$A$6', 'Sheet1!$B$5:$D$5', 'Sheet1!$B$6:$D$6');
	chart.AddSeries('Sheet1!$A$7', 'Sheet1!$B$5:$D$5', 'Sheet1!$B$7:$D$7');
	chart.AddSeries('Sheet1!$A$8', 'Sheet1!$B$5:$D$5', 'Sheet1!$B$8:$D$8');
	
	chart.ShowLegendKey := false;
	chart.Legend.Position := 'left';
	
	chart.ShowBubbleSize := true;
	chart.ShowCatName := false;
	chart.ShowLeaderLines := false;
	chart.ShowPercent := true;
	chart.ShowSerName := true;
	chart.ShowVal := true;
	chart.ShowBlanksAs := 'zero';
	
	
	[err, errinfo] := excel.InsertTable("Sheet1","A5",data, true);
	chart1 := excel.AddChart('Sheet1', 'A11:G30', chart);
	println('AddChart1={}', chart1);
	
	
	chart.Type := 'pie3D';
	chart.VaryColors := true;
	chart.BegColOff := 0;
	chart.BegRowOff := 0;
	chart.Name := 'test chart 2';
	chart.Title := 'Hans Chart 2';
	chart.Legend.Position := 'bottom';
	chart.Series := array(('Name':"Sheet3!$A$6", 'Categories':"Sheet3!$B$5:$D$5", 'Values':"Sheet3!$B$6:$D$6"));
	chart.ShowSerName := false;
	chart.ShowVal := false;
	excel.NewSheet('Sheet3');
	[err, errinfo] := excel.InsertTable("Sheet3","A5",data, true);
	chart2 := excel.AddChart('Sheet3', 'I11:P30', chart);
	println('AddChart2={}', chart2);
	
	[err, errmsg] := excel.SaveAs('', 'f:\\temp\\ch.xlsx');
	println('SaveAs->{}',err);
End;
