Search code examples
exceldelphiteechartgridlines

TeeChart and Excel gridlines


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 ?.


Solution

  • 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.