Copy from Excel and Save as Image in email body

Hello Friends,
I would like to insert an image in the body of the email. These images are from multiple excel files from a particular folder want to copy a range of cells from each excel and save it as an image. Load the image as a variable and insert it into the body of the email and send it out as per mail for per excel.
Does anybody know how to do it? Any input will be appreciable.

Hello.
I am new on this forum - but hope that I can contribute.

Why do you what to attatch an image? Would it not be better to add a table?

@Bot_Learner - you can program a bot to:
(1) open up excel file
(2) capture screenshot
(3) save screenshot
(4) attach screenshot to email

1 Like

Hi @Bot_Learner ,

To embed image in email body by using uipath. Please review the below tutorial in YouTube. I hope it might helpful for your requirement.

The below points are the key points you have to develop.

Open your desired excel and select the desired cells and take screenshot activity to take screenshot of the excel and use html code to insert the picture to your email body.

In alternative way as suggested by @Morten_Sigaard_Jacobsen

You can select the range of cells into datatable and convert back to html table so that you can pass this table directly to your email body instead of image. Thanks.

2 Likes

Hello @Morten_Sigaard_Jacobsen
Attaching an image is the project requirement.

Hi Bot Learner,

We use invoke code activity to convert selected range/pivotTable to an image,

Here you have the way to get an image from a a desired range:

  1. Invoked arguments:

  2. Invoked body:

Dim xlWorkBook As  Microsoft.Office.Interop.Excel.Workbook
Dim xlWorkSheet As Microsoft.Office.Interop.Excel.Worksheet
Dim xlRange As Microsoft.Office.Interop.Excel.Range

Try

app.DisplayAlerts=False
xlWorkBook=app.Workbooks.Open(filePath)
xlWorkSheet = CType(xlWorkBook.Sheets(SheetName), Microsoft.Office.Interop.Excel.Worksheet)
xlWorksheet.Range(Range).CopyPicture(Microsoft.Office.Interop.Excel.XlPictureAppearance.xlScreen, Microsoft.Office.Interop.Excel.XlCopyPictureFormat.xlBitmap)

System.Windows.Forms.Clipboard.GetImage.Save(ImagePath, System.Drawing.Imaging.ImageFormat.Jpeg)
xlWorkBook.Close

Console.WriteLine("Image placed in: " + ImagePath)

Catch e As Exception
	xlWorkBook.Close
exceptionMessage =exceptionMessage + e.Message
End Try

Regards

Hi @Bot_Learner

Since you are capturing the image of excel and pasting in email as image.

I think instead of pasting as image, you can embed a table simmilar to excel in email, itself

Try that approach .

Thanks & regards,
Nived N

Hello @NIVED_NAMBIAR ,

It does not only have a table it has other Dynamic content so capturing an image is an easy option.

I think u are capturing excel data as screenshot

Would u share a sample screenshot to look into

Thanks and regards

Nived N

Hello @NIVED_NAMBIAR ,
That’s confidential, it’s like email templet has Logo, table & dynamic text.

Ok @Bot_Learner

You can go with the approach of image based.

Thanks & Regards,
Nived N

Thanks @NIVED_NAMBIAR u means using invoke code activity suggested by @jmedinacarbonell ,what is best approach ? i have multiple excel in folder wanted to send per mail for per excel .

Hello @jmedinacarbonell,
Any special package need to install for this

Nope…
As said, just use Invoke code activity. It comes as default system activity, you can check how to use it here.

Btw in the example I gave you, you just need to copy paste on your project inside the invoke code activity block.

Just give it a try and tell me if you have any issue.
Hug

Hello @jmedinacarbonell ,

Can u plz help me to understand below exception.
Invoke code: No compiled code to run
error BC30456: ‘Clipboard’ is not a member of ‘Forms’. At line 12

Thanks

Hi, this normally comes from a wrong Imports declaration.

Here I provide you a working example:

project.json (930 Bytes)
test.xaml (6.0 KB)
Test.xlsx (9.0 KB)
Output:
Test

So it takes the specified range and transforms it into a jpg image

Tell me if any issue :slight_smile:
PD: If it works fine, please, mark as solution

Hello @jmedinacarbonell,

It Works thanks for u r help… :+1:

Hi @Bot_Learner ,

Nice to heard that!
Please, mark as solution either this or this other reply in order to mark it in the header

Hug

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.