描述:
我在VC里嵌入的Excel,当鼠标选中单元格时,如何得到选中的起始行列?
POSITION_INFO ob;//存储起始行列的自定义结构
IDispatch* pIDispatch;
_Workbook workbook;
_Worksheet worksheet;
Range range,Cell;
pIDispatch = g_pCntrItem->GetIDispatch();
workbook.AttachDispatch(pIDispatch);
worksheet = workbook.GetActiveSheet();
range = worksheet.GetUsedRange();
Cell = range.GetColumns();
ob.icol = Cell.GetColumn();
ob.icolc = Cell.GetCount();
Cell = range.GetRows();
ob.irow = Cell.GetRow();
ob.irowc = Cell.GetCount();
为什么得到的结果都是1??
该怎么做啊????????????????????????
解决方案1:
IDispatch* pIDispatch;
_Application app;
_Workbook workbook;
_Worksheet worksheet;
Range range,Cell;
workbook.AttachDispatch(pIDispatch);
worksheet = workbook.GetActiveSheet();
app =workbook.GetApplication();
range.AttachDispatch(app.GetSelection());
Storm 01:47:44
Cell = range.GetRows();
irow = Cell.GetRow();
irowc = Cell.GetCount();
strRowSta.Format("%d",irow);
strRowEnd.Format("%d",irow + irowc -1);
Cell = range.GetColumns();
icol = Cell.GetColumn();
icolc = Cell.GetCount();
strColSta.Format("%d",icol);
strColEnd.Format("%d",icol + icolc -1);