use strict ; use OLE; use Win32::OLE::Const "Microsoft Excel"; my ($excel, $workbook, $sheet, $j, $row, $range, $cell_str, $content, $contentb, , $contentc, $width_found, $id, $test_cell_idg ); my ($worktable_name, $jwk, $jr, $sheets_total, $new_wk); my ($cell_tg, $v_pos, $h_pos, $pic_cur, $image_file_full, $cell_id, $cur_width, $cur_height, $aspect_ratio); #___ DEFINE EXCEL $excel = CreateObject OLE "Excel.Application"; #___ MAKE EXCEL VISIBLE $excel -> {Visible} = 1; #___ ADD NEW WORKBOOK $workbook = $excel -> Workbooks -> Add; $sheet = $workbook -> Worksheets("Sheet1"); $sheet -> Activate; $image_file_full = “the full directory path and file name of an image is written here” $cell_id = "B3"; $cell_tg = $sheet->Range($cell_id); $v_pos = $cell_tg->Top; $h_pos = $cell_tg->Left; # insert picture with top left hand corner at cell_id $pic_cur = $sheet->Pictures->Insert($image_file_full); $pic_cur ->{Top} = $cell_tg->Top; $pic_cur ->{Left} = $cell_tg->Left; # get the size and aspect ratio of the original image $cur_width = $pic_cur ->{Width}; $cur_height = $pic_cur ->{Height}; $aspect_ratio = $cur_height / $cur_width; print "original width <$cur_width> height <$cur_height> aspect ratio <$aspect_ratio>\n"; # change the width and size of the image $pic_cur ->{Width} = 200; $pic_cur ->{Height} = 100; # get the size and aspect ratio of the resized image $cur_width = $pic_cur ->{Width}; $cur_height = $pic_cur ->{Height}; $aspect_ratio = $cur_height / $cur_width; print "new width <$cur_width> height <$cur_height> aspect ratio <$aspect_ratio>\n";