C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
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:
Ziff Davis Enterprise Virtual Tradeshows: Hot Topics, Cutting Edge Technology, Real-time Networking among IT Professionals. Learn more
  #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?


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

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway