Click here to Skip to main content
16,019,427 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Question_variant_t vItem = pRange->Item[ iRow ][ iCol ]; [modified] Pin
MsmVc29-Sep-09 20:19
MsmVc29-Sep-09 20:19 
AnswerRe: _variant_t vItem = pRange->Item[ iRow ][ iCol ]; Pin
Franck Paquier29-Sep-09 23:12
Franck Paquier29-Sep-09 23:12 
GeneralRe: _variant_t vItem = pRange->Item[ iRow ][ iCol ]; Pin
MsmVc29-Sep-09 23:14
MsmVc29-Sep-09 23:14 
GeneralRe: _variant_t vItem = pRange->Item[ iRow ][ iCol ]; Pin
Richard MacCutchan29-Sep-09 23:56
mveRichard MacCutchan29-Sep-09 23:56 
GeneralRe: _variant_t vItem = pRange->Item[ iRow ][ iCol ]; Pin
MsmVc30-Sep-09 0:17
MsmVc30-Sep-09 0:17 
GeneralRe: _variant_t vItem = pRange->Item[ iRow ][ iCol ]; Pin
Richard MacCutchan30-Sep-09 1:12
mveRichard MacCutchan30-Sep-09 1:12 
GeneralRe: _variant_t vItem = pRange->Item[ iRow ][ iCol ]; Pin
MsmVc30-Sep-09 1:34
MsmVc30-Sep-09 1:34 
GeneralRe: _variant_t vItem = pRange->Item[ iRow ][ iCol ]; Pin
MsmVc30-Sep-09 2:07
MsmVc30-Sep-09 2:07 
i think need to post some more code.
try
	{
		.
	CoInitialize(NULL);
	

	while ( m_list.DeleteColumn( 0 ) );
	HRESULT hr;

	CFileDialog fileDlg(TRUE, _T("xls"), NULL, OFN_PATHMUSTEXIST|OFN_OVERWRITEPROMPT,_T("Excel Files|*.xls;*.xlsx|"));
	if (fileDlg.DoModal () == IDCANCEL) 
		return;

	CString OpenFile = fileDlg.GetPathName ();

	// Load the Excel application in the background.
	Excel::_ApplicationPtr pApplication;
	if (FAILED( pApplication.CreateInstance( _T("Excel.Application") ) ) )
	{
		
		return;
	}

	_variant_t	varOption( (long) DISP_E_PARAMNOTFOUND, VT_ERROR );

	Excel::_WorkbookPtr pBook = pApplication->Workbooks->Open( (_bstr_t)OpenFile, varOption, varOption, varOption, varOption, varOption, varOption, varOption, varOption, varOption, varOption, varOption, varOption );
	if ( pBook == NULL )
	{
			pBook->Close( VARIANT_FALSE );

	// Need to quit, otherwise Excel remains active and locks the .xls file.
	pApplication->Quit( );
		Errorf( _T("Failed to open Excel file!") );
		return;
	}
	

	for(int i=1;i<4;i++)
	{
		Excel::_WorksheetPtr pSheet = pBook->Sheets->Item[ i ];
		
		_bstr_t na=pSheet->GetName();
				
		
	if ( pSheet == NULL )
	{
		
		return;
	}

	// Load the column headers.
	Excel::RangePtr pRange = pSheet->GetRange( _bstr_t( _T("A1") ), _bstr_t( _T("Z1" ) ) );
	


	if ( pRange == NULL )
	{
		Errorf( _T("Failed to get header cell range( A1:iv )!") );
		return;
	}

	int	iColumns = 0;

	for ( int iColumn = 1; iColumn < 26; ++iColumn )
	{
		_variant_t	vItem = pRange->Item[ 1 ][ iColumn ];
		_bstr_t		bstrText( vItem );

		if ( bstrText.length( ) == 0 )
			break;

		m_list.InsertColumn(iColumns++,bstrText,LVCFMT_LEFT,170 );
	}

	// Load the rows (up to the first blank one).
	pRange = pSheet->GetRange( _bstr_t( _T("A2") ), _bstr_t( _T("Z16384" ) ) );
	

	int iColumn=0;
	for ( int iRow = 1; ; ++iRow )
	{
		for (  iColumn = 1; iColumn <= iColumns; ++iColumn )
		{
			_variant_t	vItem = pRange->Item[ iRow  ][ iColumn ];
//Here i am getting values.
			_bstr_t		bstrText( vItem );

			if ( bstrText.length( ) == 0 )
				break;

			if ( iColumn == 1 )
				m_list.InsertItem( iRow - 1, bstrText );
			else
				m_list.SetItemText( iRow - 1, iColumn - 1, bstrText );
		}

		if ( iColumn == 1 )
			break;
	}

	// Make it all look pretty.
	for ( int iColumn = 1; iColumn <= iColumns; ++iColumn )
		m_list.SetColumnWidth( iColumn, LVSCW_AUTOSIZE_USEHEADER );
	}
	// Don't save any inadvertant changes to the .xls file.
	pBook->Close( VARIANT_FALSE );

	// Need to quit, otherwise Excel remains active and locks the .xls file.
	pApplication->Quit( );
	}
	catch(...)
	{
	
		
	}

Here i take some constant value so please don't make issues of constant values.
GeneralRe: _variant_t vItem = pRange-&gt;Item[ iRow ][ iCol ]; Pin
Richard MacCutchan30-Sep-09 3:34
mveRichard MacCutchan30-Sep-09 3:34 
GeneralRe: _variant_t vItem = pRange-&gt;Item[ iRow ][ iCol ]; Pin
MsmVc30-Sep-09 18:43
MsmVc30-Sep-09 18:43 
GeneralRe: _variant_t vItem = pRange-&gt;Item[ iRow ][ iCol ]; Pin
Franck Paquier30-Sep-09 19:10
Franck Paquier30-Sep-09 19:10 
GeneralRe: _variant_t vItem = pRange-&gt;Item[ iRow ][ iCol ]; Pin
MsmVc30-Sep-09 19:33
MsmVc30-Sep-09 19:33 
GeneralRe: _variant_t vItem = pRange-&gt;Item[ iRow ][ iCol ]; Pin
Franck Paquier30-Sep-09 20:00
Franck Paquier30-Sep-09 20:00 
GeneralRe: _variant_t vItem = pRange-&gt;Item[ iRow ][ iCol ]; Pin
MsmVc30-Sep-09 20:08
MsmVc30-Sep-09 20:08 
GeneralRe: _variant_t vItem = pRange-&gt;Item[ iRow ][ iCol ]; Pin
Franck Paquier30-Sep-09 20:37
Franck Paquier30-Sep-09 20:37 
GeneralRe: _variant_t vItem = pRange-&gt;Item[ iRow ][ iCol ]; Pin
MsmVc30-Sep-09 20:42
MsmVc30-Sep-09 20:42 
GeneralRe: _variant_t vItem = pRange-&gt;Item[ iRow ][ iCol ]; Pin
Franck Paquier30-Sep-09 21:43
Franck Paquier30-Sep-09 21:43 
GeneralRe: _variant_t vItem = pRange-&gt;Item[ iRow ][ iCol ]; Pin
Franck Paquier30-Sep-09 21:45
Franck Paquier30-Sep-09 21:45 
GeneralRe: _variant_t vItem = pRange-&gt;Item[ iRow ][ iCol ]; Pin
MsmVc30-Sep-09 23:03
MsmVc30-Sep-09 23:03 
Questionhtml help and ms front-page Pin
includeh1029-Sep-09 19:24
includeh1029-Sep-09 19:24 
AnswerRe: html help and ms front-page Pin
Hans Dietrich29-Sep-09 20:19
mentorHans Dietrich29-Sep-09 20:19 
QuestionWhere is regedit.exe located in Pocket PC? Pin
Le@rner29-Sep-09 19:03
Le@rner29-Sep-09 19:03 
AnswerRe: Where is regedit.exe located in Pocket PC? Pin
Game-point29-Sep-09 19:14
Game-point29-Sep-09 19:14 
QuestionDirectX - Direct Show programming? Pin
$uresh $hanmugam29-Sep-09 18:35
$uresh $hanmugam29-Sep-09 18:35 
QuestionHow to disable non-visible dialog items Pin
FloatingMarc29-Sep-09 16:19
FloatingMarc29-Sep-09 16: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.