OpenOffice Automation Delphi 如何从不相邻的列创建分散图表
有人可以帮助我如何从不相邻的列创建 XY 图吗? 我想在 Delphi 中使用 OOoTools.pas 接口来执行此操作。这是工作代码,我只能选择相邻的列: 用户 The_Fox 为我解决了一些问题提供了很多帮助,谢谢。
procedure TForm1.ProcessNewChart(aFilename: String);
Var
oTheFile, oAllSheets, oMySheet, oCharts, oChart,
oCellRangeAddress, oRectangle, oSize, oChartDoc,
oTitleTextShape, oDiagram, oMySymbolType : Variant;
begin
ConnectOpenOffice;
(* Get a handle to the file *)
oTheFile := OpenSheet(aFilename, True);
(* Get a handle to the sheets of the Calc file *)
oAllSheets:= oTheFile.Sheets;
(* Select the first sheet to work with *)
oMySheet:= oAllSheets.getByIndex(0); // first sheet of the spreadsheet
(* Create a handle to the the charts object *)
oCharts := oMySheet.getCharts;
(* Specify the position and dimensions of the to be created chart *)
oRectangle := oMySheet.Bridge_GetStruct('com.sun.star.awt.Rectangle');
oRectangle.X := 8000; // X position
oRectangle.Y := 1000; // Y position
oRectangle.Width := 15000;// width
oRectangle.Height := 5000; // height
(* Specify the Cell ranges where to create a chart from
The first column specifies the X axis
The rest specifies the Y values
The first row specifies the labels of the series
*)
oCellRangeAddress := oTheFile.Bridge_getStruct('com.sun.star.table.CellRangeAddress');
oCellRangeAddress.Sheet := 0; // First sheet of the file
oCellRangeAddress.StartColumn := 1; // was 10
oCellRangeAddress.StartRow := 6;
oCellRangeAddress.EndColumn := 10;
oCellRangeAddress.EndRow := 71;
(* Create the Chart *)
oCharts.addNewByName('MyGraph',oRectangle,VarArrayOf(oCellRangeAddress),True, True);
(* Now place the chart on the sheet *)
oChart := oCharts.getByName('MyGraph').EmbeddedObject;
(* Set The chart type (scatter) *)
oChart.Diagram := oChart.createInstance('com.sun.star.chart.XYDiagram');
(* Turn the symbol of the data points off *)
oChart.Diagram.SymbolType := -3;
(* Set the spline method 0=none, 1 is cubic and 2 = spline B *)
oChart.Diagram.SplineType := 0;
(* Set the color of the font *)
oChart.Diagram.wall.FillColor := RGB(150,150,150);
(*Set the maximym Yaxis value*)
oChart.Diagram.YAxis.Max := 40000;
(* Set a Y axis title *)
oChart.Diagram.HasYAxisTitle := True;
oChart.Diagram.YAxisTitle.string := 'Values';
(* Set an X axis title *)
oChart.Diagram.HasXAxisTitle := True;
oChart.Diagram.XAxisTitle.string := 'Logged Points';
(* The first row contains the names of the columns *)
oChart.DataSourceLabelsInFirstColumn := False;
oChart.DataSourceLabelsInFirstRow := True;
(* Rotate the X axis values *)
oChart.Diagram.XAxis.TextRotation := 9000;// '90 degrés
(* Set the character height of the labels *)
oChart.Diagram.YAxis.CharHeight := 8;
oChart.Diagram.XAxis.CharHeight := 8;
(* Set The main title and color of the graph *)
oChart.HasMainTitle := True;
oChart.Title.String := 'VPC logged data visualization';
oChart.Title.CharColor := RGB(200,0,0);
DisconnectOpenOffice;
end;
can someone please help me on how to create a XYdiagram from non-adjacent columns?
I want to do this in Delphi using the OOoTools.pas interface. This is the working code where I can only select adjacent columns:
User The_Fox helped me a lot with some issues I had, thanks for that.
procedure TForm1.ProcessNewChart(aFilename: String);
Var
oTheFile, oAllSheets, oMySheet, oCharts, oChart,
oCellRangeAddress, oRectangle, oSize, oChartDoc,
oTitleTextShape, oDiagram, oMySymbolType : Variant;
begin
ConnectOpenOffice;
(* Get a handle to the file *)
oTheFile := OpenSheet(aFilename, True);
(* Get a handle to the sheets of the Calc file *)
oAllSheets:= oTheFile.Sheets;
(* Select the first sheet to work with *)
oMySheet:= oAllSheets.getByIndex(0); // first sheet of the spreadsheet
(* Create a handle to the the charts object *)
oCharts := oMySheet.getCharts;
(* Specify the position and dimensions of the to be created chart *)
oRectangle := oMySheet.Bridge_GetStruct('com.sun.star.awt.Rectangle');
oRectangle.X := 8000; // X position
oRectangle.Y := 1000; // Y position
oRectangle.Width := 15000;// width
oRectangle.Height := 5000; // height
(* Specify the Cell ranges where to create a chart from
The first column specifies the X axis
The rest specifies the Y values
The first row specifies the labels of the series
*)
oCellRangeAddress := oTheFile.Bridge_getStruct('com.sun.star.table.CellRangeAddress');
oCellRangeAddress.Sheet := 0; // First sheet of the file
oCellRangeAddress.StartColumn := 1; // was 10
oCellRangeAddress.StartRow := 6;
oCellRangeAddress.EndColumn := 10;
oCellRangeAddress.EndRow := 71;
(* Create the Chart *)
oCharts.addNewByName('MyGraph',oRectangle,VarArrayOf(oCellRangeAddress),True, True);
(* Now place the chart on the sheet *)
oChart := oCharts.getByName('MyGraph').EmbeddedObject;
(* Set The chart type (scatter) *)
oChart.Diagram := oChart.createInstance('com.sun.star.chart.XYDiagram');
(* Turn the symbol of the data points off *)
oChart.Diagram.SymbolType := -3;
(* Set the spline method 0=none, 1 is cubic and 2 = spline B *)
oChart.Diagram.SplineType := 0;
(* Set the color of the font *)
oChart.Diagram.wall.FillColor := RGB(150,150,150);
(*Set the maximym Yaxis value*)
oChart.Diagram.YAxis.Max := 40000;
(* Set a Y axis title *)
oChart.Diagram.HasYAxisTitle := True;
oChart.Diagram.YAxisTitle.string := 'Values';
(* Set an X axis title *)
oChart.Diagram.HasXAxisTitle := True;
oChart.Diagram.XAxisTitle.string := 'Logged Points';
(* The first row contains the names of the columns *)
oChart.DataSourceLabelsInFirstColumn := False;
oChart.DataSourceLabelsInFirstRow := True;
(* Rotate the X axis values *)
oChart.Diagram.XAxis.TextRotation := 9000;// '90 degrés
(* Set the character height of the labels *)
oChart.Diagram.YAxis.CharHeight := 8;
oChart.Diagram.XAxis.CharHeight := 8;
(* Set The main title and color of the graph *)
oChart.HasMainTitle := True;
oChart.Title.String := 'VPC logged data visualization';
oChart.Title.CharColor := RGB(200,0,0);
DisconnectOpenOffice;
end;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你可以通过指定超过 1 个 CellRangeAddress 来实现(请注意,你可以在 addNewByName 中给出一个 CellRangeAddresses 数组)。
所以我的猜测是:
请注意,这些列不再相邻(1、3、5、7)。
I think you can do it by specifying more than 1 CellRangeAddress (note that you can give an array of CellRangeAddresses in addNewByName).
So my guess:
Note that the columns are not adjacent anymore (1, 3, 5, 7).