码迷,mamicode.com
首页 > 其他好文 > 详细

VC 插入excel

时间:2015-11-02 17:38:26      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:

CString ePath,iPath;
	m_ePath.GetWindowText(ePath);
	m_iPath.GetWindowText(iPath);
	
	_Application app;    
	Workbooks books;
	_Workbook book;
	Worksheets sheets;
	_Worksheet sheet;
	Shapes shp;
	
	//创建Excel 2000服务器(启动Excel) 
	if (!app.CreateDispatch("Excel.Application",NULL)) 
	{ 
		AfxMessageBox("创建Excel服务失败!"); 
		exit(1); 
	} 
	books.AttachDispatch(app.GetWorkbooks()); 
	book.AttachDispatch(books.Add(_variant_t(ePath)));
	//得到Worksheets 
	sheets.AttachDispatch(book.GetWorksheets());	
	sheet.AttachDispatch(sheets.GetItem(_variant_t("Sheet1")));
	shp.AttachDispatch(sheet.GetShapes());
	shp.AddPicture(iPath,false,true,0,0,400,300);
	
	app.SetVisible(true); 
	book.PrintPreview(_variant_t( false ));//打印预览
	//释放对象 
	sheet.ReleaseDispatch(); 
	sheets.ReleaseDispatch(); 
	book.ReleaseDispatch(); 
	books.ReleaseDispatch();
	app.ReleaseDispatch(); 

  

VC 插入excel

标签:

原文地址:http://www.cnblogs.com/qq76211822/p/4930516.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!