10. RPA Challenge - Copy Information in Excel and Save as Image?


#1

I would like to insert a image in the body of the email. This image is from a excel. I want to copy range of cells from the excel and save it as a image. Load the image as a variable and insert it into the body of the email and send out. Does anybody know how to do it? Thanks a lot!


Automation Challenge Winners
#2

Moved it to RPA Challenge


#3

Finished this, but i think my solution is stupid. I was unable to save the Image took from excel (get from clipboard doesn’t work)

Attached is solution, may have selector issues. I think running macro to take screenshot and saving file to a location is a far better idea.

ImageFromExcel.zip (226.0 KB)


Outlook image issue
Excel copy 3 row named range down 1 row and make the new cells the new named range
#4

Thanks a lot!!! We are inspired by your solution. We create a new object by choosing the "Bitmap Image"type and save the image in a file. This solution is not that smart but it works. Thank you!


#5

Could you please share?


#6

Hello Everyone,

This is MHO on how to get this done. this is using outlook 2013 also will get the last row in case the data change, also if outlook is not open, if is not will open outlook and will send the image.

Please take a look and let me know if this works. Happy automation.

regards.
RPA_10.zip (591.7 KB)


#7

I think something like this

                Rectangle bounds = this.Bounds;
                using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
                {
                    using (Graphics g = Graphics.FromImage(bitmap))
                    {
                        g.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size);
                    }
                    bitmap.Save(path, ImageFormat.Png);
                }

#8

Looks like you pasting the image by opening outlook.Figure out a way to avoid that, I used paint which can be avoided. I tried below code but not sure how to implement highlighted code in Uipath (doesn’t work using Invoke method)

     bmp = Clipboard.GetImage()
    JpegBitmapEncoder encoder = new JpegBitmapEncoder();
    BitmapFrame outputFrame = BitmapFrame.Create(bmp);
    encoder.Frames.Add(outputFrame);
    encoder.QualityLevel = quality;

using (FileStream file = File.OpenWrite(fileName))

{
encoder.Save(file);
}
PS: watched 80% of the movies :wink:


#9

Please kindly help why i always get like picture shows, Thanks!


#10

If you still are still in need of this…


#11

We can copy the range to a new dummy sheet, take screens hot and send an email. Since image should be in the body, we should build the html for send mail message body content and check ishtml property for the activity, so that the image appears as body. Later we can delete the dummy sheet or not save the excel.


#12

We can copy from excel sheet and paste in paint and save this image ImageAttachInMail.xaml (18.4 KB)


#13

This might be a bit late, but I got the solution for this. Combinations of techniques and answers I got from forum and google. Took me sometime as well to figure, here it is:

  1. Use the ‘Invoke Code’ activity to copy Excel Range to Image.
    Arguments:
    [a] strExcelFile
    [b] strImageFileName
    [c] Range (Optional)

Code:
''Initialize
Dim xlPicture As Microsoft.Office.Interop.Excel.XlCopyPictureFormat
Dim xlScreen As Microsoft.Office.Interop.Excel.XlPictureAppearance
Dim objExcel As Microsoft.Office.Interop.Excel.Application = Nothing
Dim objWorkbook As Microsoft.Office.Interop.Excel.Workbook = Nothing
Dim objSheet As Microsoft.Office.Interop.Excel.Sheets = Nothing
Dim objWorkSheet As Microsoft.Office.Interop.Excel.Worksheet = Nothing
Dim oRangeToCopy As Microsoft.Office.Interop.Excel.Range

On Error Resume Next
''Create Excel Object
objExcel = New Microsoft.Office.Interop.Excel.ApplicationClass
objWorkbook = objExcel.Workbooks._Open(strExcelFile)
objExcel.DisplayAlerts = False

''Get Sheet
objSheet = objWorkbook.Sheets
objWorkSheet = CType(objSheet(1), Microsoft.Office.Interop.Excel.Worksheet)

''Get Range
oRangeToCopy = objWorkSheet.Range(“A2:D55”)
oRangeToCopy.CopyPicture(Microsoft.Office.Interop.Excel.XlPictureAppearance.xlScreen, Microsoft.Office.Interop.Excel.XlCopyPictureFormat.xlPicture)

''Create Shape for Chart
Dim shape As Microsoft.Office.Interop.Excel.Shape
shape= objWorkSheet.Shapes.AddChart(Microsoft.Office.Interop.Excel.XlChartType.xlColumnClustered, CDbl(oRangeToCopy.Left.ToString), CDbl(oRangeToCopy.Top.ToString), CDbl(oRangeToCopy.Width.ToString), CDbl(oRangeToCopy.Height.ToString))
shape.chart.ChartArea.ClearContents()
shape.Chart.Paste()
shape.Chart.Export(FileName:=strImageFileName)
shape.Delete()

''Save Excel File
objWorkbook.Save
objWorkbook.Close
objExcel.Application.Quit

''Destroy objects
objWorkSheet = Nothing
objWorkbook = Nothing
objExcel = Nothing
On Error GoTo 0

Note: I used shape to be able to create a chart, was trying to use the chartobject/s but it was throwing some exceptions. Got stuck on this one for long.

  1. Send Email - I used ‘Send Outlook Mail Message’ (Will move this via SMTP)
    As some have suggested, make use of the ‘IsBodyHtml’ property and create an html code for the body.
    This is the one I used for the image part and works fine. Just change the path to variable to make it dynamic. Can remove the width and height, I just added for mine as the image we have is quite long.

img src=‘D:\UIPATH\Image_130518_075410401.jpg’ Width = ‘5500’ Height =‘15000’
img src=’" & strImageFileName & "’ Width = ‘5500’ Height =‘15000’

Regards,
Mharliee


#14

Hi,

Here is my attempt I’m just automating button pushes on the whole rather than the integrated activities for Excel and Outlook so it’s probably not the best solution?

I’m using Office 365 (in case that makes a difference to the selectors).

All the best,

Chall10_CopyRangeFromExcelAsImage.zip (114.8 KB)


#15

How does your Send Mail activity look like in the attachment property?

The path used in the body string needs to be the same as in the attachment property in the mail activity.

Please check, if that works.


#16

Great solution!

I have an issue whenever I run the process fully out of the Orchestrator.

Recipients reading the mail in Outlook Web App can not see the image. Recipients using MS Outlook desktop app can see the image.

Any idea why that happens?


#17

#18