C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 8th, 2002, 03:26 AM
martin_p martin_p is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Scotland
Posts: 0 martin_p User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question How do I display an excel spreadsheet in a Microsft DataGrid Control?

How do I display an excel spreadsheet in a Microsft DataGrid Control in a MFC application? I have put a DataGrid and a Microsft ADO Data Control on my dialog. The code below is called when a button on my dialog is clicked. The variable m_adoSource is the ADO Data Control, m_dataGrid is the DataGrid. The connection is made to the excel spreadsheet but I cannot get it to display in the DataGrid. How do I do this?

void CCleaningToolDlg::OnButtonOpenFile()
{
// TODO: Add your control notification handler code here

//
// get file name from user using standard file dialog
//

//
// Connect to Excel spreadsheet
//

CString path = "E:\\CleaningTool\\TEST FILE.xls";

CString sDriver = GetExcelDriver();

CString connectionString ("Provider=MSDASQL; Driver={" + sDriver + "};" + path);
m_adoSource.SetConnectionString(connectionString);

//m_adoSource.SetRecordSource("SELECT *");

// DEBUG stuff
CString temp = m_adoSource.GetConnectionString();
MessageBox(temp);

//
// Populate grid control with contents of spreadsheet
//
C_Recordset recordSet = m_adoSource.GetRecordset();

m_adoSource.SetRecordSource("SELECT * ");

m_adoSource.Refresh();
m_dataGrid.UpdateData();
m_dataGrid.Refresh();
}

// Get the name of the Excel-ODBC driver
// Contibuted by Christopher W. Backen - Thanx Christoper
CString CCleaningToolDlg::GetExcelDriver()
{
char szBuf[2001];
WORD cbBufMax = 2000;
WORD cbBufOut;
char *pszBuf = szBuf;
CString sDriver;

// Get the names of the installed drivers
// (<odbcinst.h> and <afxdb.h> has to be included )
if (!SQLGetInstalledDrivers(szBuf, cbBufMax, &cbBufOut))
return "";

// Search for the driver...
do
{
if (strstr(pszBuf, "Excel") != 0)
{
// Found !
sDriver = CString(pszBuf);
break;
}
pszBuf = strchr(pszBuf, '\0') + 1;
}
while (pszBuf[1] != '\0');

return sDriver;
}

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > How do I display an excel spreadsheet in a Microsft DataGrid Control?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap