Click here to Skip to main content
16,006,474 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralGenerate Reports Using Crystal Reports 7 in VC Pin
Statbat11-Oct-01 20:39
Statbat11-Oct-01 20:39 
GeneralRe: Generate Reports Using Crystal Reports 7 in VC Pin
Masaaki Onishi12-Oct-01 4:26
Masaaki Onishi12-Oct-01 4:26 
GeneralRe: Generate Reports Using Crystal Reports 7 in VC Pin
Rashid Thadha12-Oct-01 6:53
Rashid Thadha12-Oct-01 6:53 
GeneralFiles and Directories Pin
Michael Martin11-Oct-01 18:31
professionalMichael Martin11-Oct-01 18:31 
GeneralRe: Files and Directories Pin
Bernhard11-Oct-01 19:37
Bernhard11-Oct-01 19:37 
GeneralRe: Files and Directories Pin
Nish Nishant11-Oct-01 21:01
sitebuilderNish Nishant11-Oct-01 21:01 
QuestionHelp Me? Pin
11-Oct-01 17:08
suss11-Oct-01 17:08 
AnswerRe: Help Me? Pin
Dan Madden14-Oct-01 2:29
Dan Madden14-Oct-01 2:29 
I have this in one of my applications...I get a Menu...take what you need out of it!

<br />
try<br />
{<br />
	_Application app;  // app is the Excel 2000 _Application object.<br />
	_Workbook book;<br />
	_Worksheet sheet;<br />
	_Chart chart;<br />
<br />
	Workbooks books;<br />
	Worksheets sheets;<br />
	Range range;<br />
	ChartObjects chartobjects;<br />
	Charts charts;<br />
	LPDISPATCH lpDisp;<br />
<br />
	// Common OLE variants. These are easy variants to use for<br />
	// calling arguments.<br />
	COleVariant<br />
		  covTrue((short)TRUE),<br />
		  covFalse((short)FALSE),<br />
		  covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);<br />
<br />
	// Start Excel and get Application object.<br />
	if(!app.CreateDispatch("Excel.Application"))<br />
	{<br />
		AfxMessageBox("Couldn't CreateDispatch on Excel");<br />
		return;<br />
	}<br />
<br />
	// Get Workbooks collection.<br />
	lpDisp = app.GetWorkbooks();  // Get an IDispatch pointer<br />
	ASSERT(lpDisp);               // or fail.<br />
	books.AttachDispatch( lpDisp );  // Attach the IDispatch pointer<br />
<br />
	// to the books object.<br />
	app.SetVisible(TRUE);<br />
<br />
	// Open a workbook.<br />
	lpDisp = books.Open(csFilename,<br />
		  covOptional, covOptional, covOptional, covOptional,<br />
		  covOptional, covOptional, covOptional, covOptional,<br />
		  covOptional, covOptional, covOptional, covOptional<br />
					  );<br />
	ASSERT(lpDisp);  // It worked!<br />
<br />
	// Attach to a Workbook object.<br />
	book.AttachDispatch( lpDisp );  // Attach the IDispatch pointer<br />
					// to the book object.<br />
<br />
	// Get sheets.<br />
	lpDisp = book.GetSheets();<br />
	ASSERT(lpDisp);<br />
	sheets.AttachDispatch(lpDisp);<br />
<br />
	// Get the sheet. Note that 1 is added to the index to make sure<br />
	// it is 1-based, not zero-based. Otherwise, you will get odd<br />
	// exceptions.<br />
	// the Worksheets collection = worksheet #.<br />
	// lpDisp = sheets.GetItem( COleVariant((short)(n+1)) );<br />
	lpDisp = sheets.GetItem( COleVariant((short)(1)) );<br />
	ASSERT(lpDisp);<br />
	sheet.AttachDispatch(lpDisp);<br />
<br />
	// Activate and sleep for two seconds so you can see it happen.<br />
	sheet.Activate();<br />
<br />
	// From cell# To cell#.<br />
	lpDisp = sheet.GetRange(COleVariant("A3"), COleVariant("G10000"));<br />
	ASSERT(lpDisp);<br />
	range.AttachDispatch(lpDisp);  // Attach the IDispatch pointer to the range.<br />
	range.Clear();  // Could be ClearContents().<br />
<br />
	CString csCellData = _T("");<br />
	CString csCell = _T("");<br />
<br />
	// Enumerate through worksheets in book and activate in<br />
	// succession.<br />
	for(int n=0; n<lc.GetItemCount(); n++)<br />
	{<br />
<br />
		csCellData = lc.GetItemText(n,0);<br />
		csCell.Format("C%i", n+3);<br />
		lpDisp = sheet.GetRange(COleVariant(csCell), COleVariant(csCell));<br />
		ASSERT(lpDisp);<br />
		range.AttachDispatch(lpDisp);<br />
		range.SetValue(COleVariant(csCellData));<br />
<br />
		csCellData = lc.GetItemText(n,1);<br />
		csCell.Format("A%i", n+3);<br />
		lpDisp = sheet.GetRange(COleVariant(csCell), COleVariant(csCell));<br />
		ASSERT(lpDisp);<br />
		range.AttachDispatch(lpDisp);<br />
		range.SetValue(COleVariant(csCellData));<br />
<br />
		csCellData = lc.GetItemText(n,2);<br />
		csCell.Format("B%i", n+3);<br />
		lpDisp = sheet.GetRange(COleVariant(csCell), COleVariant(csCell));<br />
		ASSERT(lpDisp);<br />
		range.AttachDispatch(lpDisp);<br />
		range.SetValue(COleVariant(csCellData));<br />
<br />
		csCellData = lc.GetItemText(n,3);<br />
		csCell.Format("D%i", n+3);<br />
		lpDisp = sheet.GetRange(COleVariant(csCell), COleVariant(csCell));<br />
		ASSERT(lpDisp);<br />
		range.AttachDispatch(lpDisp);<br />
		range.SetValue(COleVariant(csCellData));<br />
<br />
		csCellData = lc.GetItemText(n,4);<br />
		csCell.Format("E%i", n+3);<br />
		lpDisp = sheet.GetRange(COleVariant(csCell), COleVariant(csCell));<br />
		ASSERT(lpDisp);<br />
		range.AttachDispatch(lpDisp);<br />
		range.SetValue(COleVariant(csCellData));<br />
<br />
		csCellData = lc.GetItemText(n,5);<br />
		csCell.Format("F%i", n+3);<br />
		lpDisp = sheet.GetRange(COleVariant(csCell), COleVariant(csCell));<br />
		ASSERT(lpDisp);<br />
		range.AttachDispatch(lpDisp);<br />
		range.SetValue(COleVariant(csCellData));<br />
<br />
		csCellData = lc.GetItemText(n,6);<br />
		csCell.Format("G%i", n+3);<br />
		lpDisp = sheet.GetRange(COleVariant(csCell), COleVariant(csCell));<br />
		ASSERT(lpDisp);<br />
		range.AttachDispatch(lpDisp);<br />
		range.SetValue(COleVariant(csCellData));<br />
<br />
	} // End of For loop. You walked through all three sheets of the<br />
<br />
	// Release dispatch pointer.<br />
	sheet.ReleaseDispatch();<br />
<br />
	// Give the user control over Excel<br />
	app.SetUserControl(TRUE);<br />
<br />
	// Save the file...<br />
	book.Save();<br />
<br />
}  // End of Processing logic.<br />
catch(COleException *e)<br />
{<br />
	char buf[1024];<br />
	sprintf(buf, "COleException. SCODE: %08lx.", (long)e->m_sc);<br />
	::MessageBox(NULL, buf, "COleException", MB_SETFOREGROUND | MB_OK);<br />
}<br />
catch(COleDispatchException *e)<br />
{<br />
	char buf[1024];<br />
	sprintf(buf, <br />
		"COleDispatchException. SCODE: %08lx,Description: \"%s\".",<br />
		(long)e->m_wCode, (LPSTR)e->m_strDescription.GetBuffer(1024));<br />
	::MessageBox(NULL, buf, "COleDispatchException", MB_SETFOREGROUND | MB_OK);<br />
}<br />
catch(...)<br />
{<br />
	::MessageBox(NULL, "General Exception caught.", "Catch-All", 				MB_SETFOREGROUND | MB_OK);<br />
}<br />



Thanks in advance,

Dan
QuestionNamespace extension - cut-and-paste feedback from explorer? Pin
reverendshoebox11-Oct-01 15:45
reverendshoebox11-Oct-01 15:45 
QuestionHow can I extract numbers from string using basic::string? (STL) Pin
Ryan Park11-Oct-01 15:11
Ryan Park11-Oct-01 15:11 
AnswerRe: How can I extract numbers from string using basic::string? (STL) Pin
Chris Losinger11-Oct-01 16:10
professionalChris Losinger11-Oct-01 16:10 
GeneralRe: How can I extract numbers from string using basic::string? (STL) Pin
Rashid Thadha12-Oct-01 6:49
Rashid Thadha12-Oct-01 6:49 
GeneralRe: How can I extract numbers from string using basic::string? (STL) Pin
12-Oct-01 7:44
suss12-Oct-01 7:44 
GeneralRe: How can I extract numbers from string using basic::string? (STL) Pin
Ryan Park12-Oct-01 15:50
Ryan Park12-Oct-01 15:50 
AnswerRe: How can I extract numbers from string using basic::string? (STL) Pin
George Anescu12-Oct-01 11:19
George Anescu12-Oct-01 11:19 
GeneralRe: How can I extract numbers from string using basic::string? (STL) Pin
Ryan Park12-Oct-01 15:48
Ryan Park12-Oct-01 15:48 
GeneralSetLayeredWindowAttributes, no effect... Pin
JHLee11-Oct-01 14:49
JHLee11-Oct-01 14:49 
GeneralRe: SetLayeredWindowAttributes, no effect... Pin
Christian Graus11-Oct-01 17:07
protectorChristian Graus11-Oct-01 17:07 
GeneralRe: SetLayeredWindowAttributes, no effect... Pin
Mukkie14-Oct-01 0:51
Mukkie14-Oct-01 0:51 
GeneralRe: SetLayeredWindowAttributes, no effect... maybe this... Pin
JHLee15-Oct-01 16:07
JHLee15-Oct-01 16:07 
GeneralFunctor help ( STL problem) Pin
Christian Graus11-Oct-01 14:19
protectorChristian Graus11-Oct-01 14:19 
GeneralRe: Functor help ( STL problem) Pin
Christian Graus11-Oct-01 14:28
protectorChristian Graus11-Oct-01 14:28 
General_StreamPtr (ADO object) Pin
Hadi Rezaee11-Oct-01 13:25
Hadi Rezaee11-Oct-01 13:25 
GeneralRe: _StreamPtr (ADO object) Pin
Rashid Thadha12-Oct-01 6:44
Rashid Thadha12-Oct-01 6:44 
GeneralRe: _StreamPtr (ADO object) Pin
Hadi Rezaee13-Oct-01 12:19
Hadi Rezaee13-Oct-01 12:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.