質問

I'm doing an application in Delphi (with Embarcadero XE3) that requires Excel automation.

I need to insert a TeeChart, generated by my app, into a XLS file. I export the chart as BMP as follows:

// Globals.getEnvTempPath() returns the temp directory of the current Windows user.
bmpPath := Globals.getEnvTempPath() + 'enp.bmp';
// enpChart is my TeeChart instance.
enpChart.SaveToBitmapFile(bmpPath);

The image is exported correctly.
Then I insert the image in Excel as follows:

//WkBook is the Workbook
sheet := WkBook.Worksheets[1];
{ params: @rutaImagen, @? @? @xPosicion @yPosicion @? @? }
sheet.shapes.addpicture(bmpPath,False, True, 145, 125, -1, -1);

The insert is successful, but the Chart gridlines do not not line up (vertically) with the WorkSheet gridlines:

enter image description here

Any ideas how solve this ?.

役に立ちましたか?

解決

Three possible solutions:

  1. Ensure the same row height of the chart before exporting to bitmap,
  2. Ensure the same row height in Excel,
  3. Stretch the image by modifying the height parameter to get equal row heights.

他のヒント

First note that, what you call "Cells", in TeeChart are actually the grid lines of the left and bottom axes crossing; and these axes grid lines are drawn when a label is drawn for that axis. So what you are actually willing to control are the exact position of the axes labels.

These exact positions depend on the chart dimensions, the number of labels to draw and their positions:

  • The chart dimensions can be modified changing the whole TChart object directly at design time in the form, or you can also change the chart's ChartRect (area delimited by the axes) by code.

  • The labels that are drawn in an axis are calculated automatically by default or you can also set them manually. You can play with the axes Increment, Minimum and Maximum properties to tune the automatic calculation, and you can Clear the axis Items array and populate it with the Add(position, text) function.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top