嵌入EXCEL,高手帮忙啊!

hosin 2005-11-17 04:54:13
如何向选中的单元格(range)写入一个值。就是说如何在程序中获取用户选中的单元格的行号和列号。
...全文
129 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
hahu 2005-11-17
  • 打赏
  • 举报
回复
//Get the document associated with this view, and be sure it's
//valid.
CEmbed_ExcelDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

CEmbed_ExcelCntrItem* pItem = NULL;
pItem = (CEmbed_ExcelCntrItem* )pDoc->GetInPlaceActiveItem(this);
//Make sure the new CContainerItem is valid.
ASSERT_VALID(pItem);
//Query for the dispatch pointer for the embedded object. In
//this case, this is the Excel worksheet.
LPDISPATCH lpDisp;
lpDisp = pItem->GetIDispatch();

//Add text in cell A1 of the embedded Excel sheet
_Workbook wb;
Worksheets wsSet;
_Worksheet ws;
Range range;
_Application app;

//set _Workbook wb to use lpDisp, the IDispatch* of the
//actual workbook.
wb.AttachDispatch(lpDisp);


//Then get the worksheet's application.
app = wb.GetApplication();
range = app.GetActiveCell();
range.SetColumnWidth(COleVariant((long)100));
//Fill A1 with the string "Hello, World!"
range.SetValue(COleVariant("Hello, World!"));
hosin 2005-11-17
  • 打赏
  • 举报
回复
真的没有人知道吗?55555~~~~
lianglp 2005-11-17
  • 打赏
  • 举报
回复
gz

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧