VC 작업 Excel sheet 머리글 작업

1353 단어 VC
	CApplication ExcelApp;
	CWorkbooks books;
	CWorkbook book;
	CWorksheets sheets;
	CWorksheet sheet;
	CRange range;
	CPageSetup pageup;
	LPDISPATCH lpDisp = NULL;
	LPDISPATCH lpDisp1 = NULL;
	// Excel  ( Excel)
	if(!ExcelApp.CreateDispatch(_T("Excel.Application"),NULL))
	{
		AfxMessageBox(_T(" Excel !"));
		return ;
	}
 
	ExcelApp.put_Visible(TRUE);
	ExcelApp.put_UserControl(FALSE);
 
	/* */
	books.AttachDispatch(ExcelApp.get_Workbooks());
 
	CString strBookPath = _T("E:\\ .xls");
 
		try
	{
		/* */
		lpDisp = books.Open(strBookPath, 
			vtMissing, vtMissing, vtMissing, vtMissing, vtMissing,
			vtMissing, vtMissing, vtMissing, vtMissing, vtMissing, 
			vtMissing, vtMissing, vtMissing, vtMissing);
		book.AttachDispatch(lpDisp);
	}
	catch(...){}
	/* Sheet */
	sheets.AttachDispatch(book.get_Sheets());
	CString strSheetName;
	strSheetName = _T(" 1");
	lpDisp = sheets.get_Item(_variant_t((long)7));
	sheet.AttachDispatch(lpDisp);
 
	pageup = sheet.get_PageSetup();
	pageup.put_LeftHeader(_T("&9
&20
&\" , \"&9 "));//pageup sheet.ReleaseDispatch(); sheets.ReleaseDispatch(); book.ReleaseDispatch(); books.ReleaseDispatch(); ExcelApp.Quit(); ExcelApp.ReleaseDispatch();

좋은 웹페이지 즐겨찾기