Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Closed Thread
 
Thread Tools Display Modes
  #1  
Old 11-09-2015, 09:50 AM
ShaunVW ShaunVW is offline
Member
 
Join Date: Feb 2012
Posts: 47
Default Including an Excel chart in email

I have created an Excel spreadsheet with a chart from Delphi code. I want to automate the process where only the chart itself is sent out in an email inline with the body message.
I realise that the chart is linked to the spreadsheet itself, however, I know that from Excel itself I am able to copy the chart, and then paste it into an email without the spreadsheet data.

Below is a snippet of the code I use to generate the spreadsheet and chart object, although when this is automatically generated, I won't necessarily be wanting to open Excel, I just want to use it to produce the chart for me.
The data being transferred to Excel is stored in arrData array.

Code:
 //make first part of the chart invisible
 ChartObj.Chart.SeriesCollection[1].Format.Fill.ForeColor.RGB := RGB(255, 255, 255); //white
 ChartObj.Chart.SeriesCollection[1].Format.Fill.Transparency := 1;
 ChartObj.Chart.SeriesCollection[2].Format.Fill.ForeColor.RGB := RGB(0, 128, 0); //green
 ChartObj.Chart.SeriesCollection[2].Format.Fill.Transparency := 0.8;
 xls.Rows[1].Font.Bold := True;
 xls.Cells.EntireColumn.HorizontalAlignment := 3; //middle-align entire table
 xls.Columns[1].HorizontalAlignment := 2; //left-align
 xls.Cells.EntireColumn.AutoFit; //autofit entire table all columns
 xls.Columns[1].EntireColumn.AutoFit;
 xls.Columns[2].EntireColumn.AutoFit;
 Range := wb.WorkSheets[1].Range[wb.WorkSheets[1].Cells[1, 1], wb.WorkSheets[1].Cells[noRows, noColumns]];
 Range.Value := ArrData;
table
 xls.Visible := True;
If the chart still needs to be linked to the data, another option would be to have the chart be converted to a picture, and that emailed.
However, I'm not sure how to generate this inline attachment in order to include in an email. Once I have it though, I do know how to attach it.
  #2  
Old 11-09-2015, 12:24 PM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,059
Default

Try to copy the chart to the clipboard and paste it in the email.
__________________
Regards,
Abdulaziz Jasser
  #3  
Old 11-09-2015, 12:27 PM
ShaunVW ShaunVW is offline
Member
 
Join Date: Feb 2012
Posts: 47
Default

That's the problem, I'm not sure how to do that programmatically
Obviously easy enough to do by right-clicking on it, etc. but I am wanting to generate the graph as doing now from code, copy the graph into email (in-line as people don't always care or know to open up the attachment), and then close the Excel spreadsheet again.
  #4  
Old 11-09-2015, 12:36 PM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,059
Default

Should be something like this:

Code:
var
          OV : OleVariant;
begin
          ExcelApplication1.Range['A1','B2'].Copy(OV);
__________________
Regards,
Abdulaziz Jasser
  #5  
Old 11-09-2015, 12:49 PM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,059
Default

See the blow:

Code:
//This will copy the chart directly to the clipboard.
ExcelApplication1.Range['A1','C10'].Copy(EmptyParam);

After that you can paste it from the clipboard object (TClipboard) into your email.
__________________
Regards,
Abdulaziz Jasser

Last edited by Jasser; 11-09-2015 at 12:53 PM.
  #6  
Old 11-09-2015, 01:24 PM
ShaunVW ShaunVW is offline
Member
 
Join Date: Feb 2012
Posts: 47
Default

Thank you, I will test it out.
Looking at the code it makes me think it will copy the cell contents onto clipboard, but will feedback tomorrow sometime...
  #7  
Old 11-09-2015, 01:31 PM
ShaunVW ShaunVW is offline
Member
 
Join Date: Feb 2012
Posts: 47
Default

Thanks Jasser for the help, but it copies the cell contents, not the chart itself to the clipboard.
After I ran it, I then checked what was on the clipboard by pasting it into an empty email, and it was the columns.
  #8  
Old 11-09-2015, 01:51 PM
ShaunVW ShaunVW is offline
Member
 
Join Date: Feb 2012
Posts: 47
Default

Hi Jasser, I managed to do it like the following, based on your initial answer got me looking in the correct place. Thank you...

Code:
//This will copy the chart directly to the clipboard.
 xls.ActiveSheet.ChartObjects('Chart 1').Activate;
 xls.ActiveChart.ChartArea.Select;
 xls.ActiveChart.ChartArea.Copy;
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 08:35 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2018, vBulletin Solutions, Inc.