티스토리 뷰

Study/Application > Windows

OLE 작업

Jake Yoon 2010. 8. 12. 21:02


=====================================================

 // Commonly used OLE variants.
 COleVariant
  covTrue((short)TRUE),
  covFalse((short)FALSE),
  covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
 
 _Application app;
 Workbooks books;
 _Workbook book;
 
 Worksheets sheets;
 _Worksheet sheet;
 Range range;
 
 int n = 1;
 CString strCurrentCell;
 CString read_value;
 VARIANT value;
 
 // Excel Init.
 if(!AfxOleInit())
 {
  AfxMessageBox("Could not initialize COM dll");
 }
 
 // Start Excel and get Application object.
 if(!app.CreateDispatch("Excel.Application"))
 {
  AfxMessageBox("Couldn't start Excel and get Application object.");
 }
 
 // Get Workbooks
 books = app.GetWorkbooks();
 
 // File Open
 CString excel_path  = "C:\\Test.xls";
 COleVariant VOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
 book = books.Open(excel_path, VOptional, VOptional,
  VOptional, VOptional, VOptional, VOptional,
  VOptional, VOptional, VOptional, VOptional,
  VOptional, VOptional, VOptional, VOptional);
 
 // Get the first sheet.
 int sheet_number = 1;
 sheets =book.GetSheets();
 sheet = sheets.GetItem(COleVariant((short)sheet_number));
 sheet.Activate();

 int n_shape_index=1;
 Shapes shapes;
 Shape  shape;
 shapes = sheet.GetShapes();

 shape = shapes.Item(COleVariant((short)1));   

 shape.Copy(); 
 
 app.SetVisible(TRUE);
 app.ReleaseDispatch();
 app.DetachDispatch();



출처 : http://www.devpia.com/MAEUL/Contents/Detail.aspx?BoardID=50&MAEULNO=20&no=831280&ref=831280&page=1

댓글