socc3rpr0
11 years agoOccasional Contributor
Crop Picture with Excel 2007 via COM Server
Hello,
I can seem to figure out how to crop a picture after I insert it from a location onto a worksheet. I can get the code to run in VB macro, but not with TestComplete. Can someone guide me to the place where I can get more info or see anything wrong?
function InsertPicture(Location)
{
var MsExcel = Sys["OleObject"]("Excel.Application");
//This works
MsExcel["ActiveSheet"]["Pictures"]["Insert"](Location);
/**This Doesn;t work
MsExcel["ActiveSheet"]["Shape"]["Select"]["ShapeRange"]["Height"] = 300;
}
I got this to work in VB
ActiveSheet.Pictures.Insert(Location)
ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Select
With Selection
.ShapeRange.Height = 300
.ShapeRange.Width = 400
End with
I can seem to figure out how to crop a picture after I insert it from a location onto a worksheet. I can get the code to run in VB macro, but not with TestComplete. Can someone guide me to the place where I can get more info or see anything wrong?
function InsertPicture(Location)
{
var MsExcel = Sys["OleObject"]("Excel.Application");
//This works
MsExcel["ActiveSheet"]["Pictures"]["Insert"](Location);
/**This Doesn;t work
MsExcel["ActiveSheet"]["Shape"]["Select"]["ShapeRange"]["Height"] = 300;
}
I got this to work in VB
ActiveSheet.Pictures.Insert(Location)
ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Select
With Selection
.ShapeRange.Height = 300
.ShapeRange.Width = 400
End with
Hi Ed Gonzales,
Try using following functions,
function Test() {
crop_image("C:\\Dev_Chaminda\\QA\\Automation_Testing\\TestComplete\\TestData\\UserName.xls","Sheet2",50,500)
}
function crop_image(filepath,sheetname,heightval,widthval){
var excel=new ActiveXObject("Excel.Application");
excel.DisplayAlerts = false;
var excel_file = excel.Workbooks.Open(filepath);
var excel_sheet = excel_file.Worksheets(sheetname);
excel_sheet.Pictures.ShapeRange.Height = heightval
excel_sheet.Pictures.ShapeRange.Width = widthval
excel_file.Save;
excel_file.Close;
excel.Exit;
}