G
Gil
I created an automation project using MFC and created classes from the Excel
2003 type library. I am trying to get the coordinates of a hyperlink in the
worksheet by using the range get_Top(), get_Left(), get_Width() and
get_Height() methods of the range class. I always get a value of 0 returned.
I have included some code below. Any ideas why the values for the top, left,
width and height are always 0?
A VBA macro using the same Top, Left, etc does return the coordinates.
Thanks for any help that you can provide,
Gil
for (int idx = 1; idx <= numSheets; idx++)
{
CComVariant vIntSheet;
vIntSheet.llVal = idx;
vIntSheet.vt = VT_I4;
// Get Hyperlinks
sheet = sheets.get_Item(vIntSheet);
hyperLinks = sheet.get_Hyperlinks();
long iNumHyperLinks = hyperLinks.get_Count();
msg.Format("Sheet %d - Number of HyperLinks = %d\n", idx,
iNumHyperLinks);
// For number of hyperlinks on the Worksheet
for (int iLink = 1; iLink <= iNumHyperLinks; iLink++)
{
CComVariant vIntHyperlink;
vIntHyperlink.lVal = iLink;
vIntHyperlink.vt = VT_I4;
hyperlink = hyperLinks.get_Item(vIntHyperlink);
CComBSTR bstrName;
CComBSTR bstrAddress;
CString Name;
CString Address;
CString SubAddress;
Name = hyperlink.get_Name();
bstrName = Name.AllocSysString();
Address = hyperlink.get_Address();
bstrAddress = Address.AllocSysString();
SubAddress = hyperlink.get_SubAddress();
int pageNum = vIntSheet.lVal;
msg.Format("Sheet Number: %d\n", pageNum);
OutputDebugString(msg);
msg.Format("Hyperlink Name: %s\nHyperlink Address: %s\n",
Name, Address);
OutputDebugString(msg);
msg.Format("Hyperlink SubAddress: %s\n", SubAddress);
OutputDebugString(msg);
range = hyperlink.get_Range();
CComVariant vRangeInfoTop;
vRangeInfoTop = range.get_Top();
msg.Format("Hyperlink Range - Top: %10.5lf\n",
vRangeInfoTop.fltVal);
OutputDebugString(msg);
CComVariant vRangeInfoLeft;
vRangeInfoLeft = range.get_Left();
msg.Format("Hyperlink Range - Left: %s\n", (LPCSTR)
vRangeInfoLeft.bstrVal);
OutputDebugString(msg);
CComVariant vRangeInfoWidth;
vRangeInfoWidth = range.get_Width();
CComVariant vRangeInfoHeight;
vRangeInfoHeight = range.get_Height();
font = range.get_Font();
CComVariant vIntFontSize;
vIntFontSize = font.get_Size();
double fontSizePts = vIntFontSize.fltVal;
rect_xlow = (double) vRangeInfoLeft.fltVal;
rect_ylow = (double) vRangeInfoTop.fltVal;
rect_xhi = rect_xlow + (double) vRangeInfoWidth.fltVal;
rect_yhi = rect_ylow + (double) vRangeInfoHeight.fltVal;
}
}
2003 type library. I am trying to get the coordinates of a hyperlink in the
worksheet by using the range get_Top(), get_Left(), get_Width() and
get_Height() methods of the range class. I always get a value of 0 returned.
I have included some code below. Any ideas why the values for the top, left,
width and height are always 0?
A VBA macro using the same Top, Left, etc does return the coordinates.
Thanks for any help that you can provide,
Gil
for (int idx = 1; idx <= numSheets; idx++)
{
CComVariant vIntSheet;
vIntSheet.llVal = idx;
vIntSheet.vt = VT_I4;
// Get Hyperlinks
sheet = sheets.get_Item(vIntSheet);
hyperLinks = sheet.get_Hyperlinks();
long iNumHyperLinks = hyperLinks.get_Count();
msg.Format("Sheet %d - Number of HyperLinks = %d\n", idx,
iNumHyperLinks);
// For number of hyperlinks on the Worksheet
for (int iLink = 1; iLink <= iNumHyperLinks; iLink++)
{
CComVariant vIntHyperlink;
vIntHyperlink.lVal = iLink;
vIntHyperlink.vt = VT_I4;
hyperlink = hyperLinks.get_Item(vIntHyperlink);
CComBSTR bstrName;
CComBSTR bstrAddress;
CString Name;
CString Address;
CString SubAddress;
Name = hyperlink.get_Name();
bstrName = Name.AllocSysString();
Address = hyperlink.get_Address();
bstrAddress = Address.AllocSysString();
SubAddress = hyperlink.get_SubAddress();
int pageNum = vIntSheet.lVal;
msg.Format("Sheet Number: %d\n", pageNum);
OutputDebugString(msg);
msg.Format("Hyperlink Name: %s\nHyperlink Address: %s\n",
Name, Address);
OutputDebugString(msg);
msg.Format("Hyperlink SubAddress: %s\n", SubAddress);
OutputDebugString(msg);
range = hyperlink.get_Range();
CComVariant vRangeInfoTop;
vRangeInfoTop = range.get_Top();
msg.Format("Hyperlink Range - Top: %10.5lf\n",
vRangeInfoTop.fltVal);
OutputDebugString(msg);
CComVariant vRangeInfoLeft;
vRangeInfoLeft = range.get_Left();
msg.Format("Hyperlink Range - Left: %s\n", (LPCSTR)
vRangeInfoLeft.bstrVal);
OutputDebugString(msg);
CComVariant vRangeInfoWidth;
vRangeInfoWidth = range.get_Width();
CComVariant vRangeInfoHeight;
vRangeInfoHeight = range.get_Height();
font = range.get_Font();
CComVariant vIntFontSize;
vIntFontSize = font.get_Size();
double fontSizePts = vIntFontSize.fltVal;
rect_xlow = (double) vRangeInfoLeft.fltVal;
rect_ylow = (double) vRangeInfoTop.fltVal;
rect_xhi = rect_xlow + (double) vRangeInfoWidth.fltVal;
rect_yhi = rect_ylow + (double) vRangeInfoHeight.fltVal;
}
}