Click here to Skip to main content
15,905,563 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to Convert Excel sheet file to .cvs format using VC++ Pin
David Crow3-Aug-07 3:48
David Crow3-Aug-07 3:48 
QuestionHow to extract taskbar button icon Pin
FlyingBear2-Aug-07 19:23
FlyingBear2-Aug-07 19:23 
AnswerRe: How to extract taskbar button icon Pin
Naveen2-Aug-07 20:09
Naveen2-Aug-07 20:09 
GeneralRe: How to extract taskbar button icon Pin
FlyingBear2-Aug-07 23:21
FlyingBear2-Aug-07 23:21 
Questionhelp me Pin
philiptabraham2-Aug-07 19:04
philiptabraham2-Aug-07 19:04 
AnswerRe: help me Pin
Anurag Gandhi2-Aug-07 19:23
professionalAnurag Gandhi2-Aug-07 19:23 
GeneralRe: help me Pin
philiptabraham2-Aug-07 19:36
philiptabraham2-Aug-07 19:36 
GeneralRe: help me Pin
philiptabraham2-Aug-07 19:51
philiptabraham2-Aug-07 19:51 
i was trying this code....
But for the select statement you need a table name. The excel sheet has multiple tables but does not have a name.So is there any programatic way of giving table name to the tables in the excel sheet...
or is there any other way of getting the data. i just want to fetch the data and manipulate on it.





void CReadExcelDlg::OnButton1()
{
CDatabase database;
CString sSql;
CString sItem1, sItem2;
CString sDriver;
CString sDsn;
CString sFile = "ReadExcel.xls"; // the file name. Could also be something
// like C:\\Sheets\\WhatDoIKnow.xls

// Clear the contents of the listbox
m_ctrlList.ResetContent();

// Retrieve the name of the Excel driver. This is
// necessary because Microsoft tends to use language
// specific names like "Microsoft Excel Driver (*.xls)" versus
// "Microsoft Excel Treiber (*.xls)"
sDriver = GetExcelDriver();
if (sDriver.IsEmpty())
{
// Blast! We didn´t find that driver!
AfxMessageBox("No Excel ODBC driver found");
return;
}

// Create a pseudo DSN including the name of the Driver and the Excel file
// so we don´t have to have an explicit DSN installed in our ODBC admin
sDsn.Format("ODBC;DRIVER={%s};DSN='';DBQ=%s", sDriver, sFile);

TRY
{
// Open the database using the former created pseudo DSN
database.Open(NULL, false, false, sDsn);

// Allocate the recordset
CRecordset recset(&database);

// Build the SQL string
// Remember to name a section of data in the Excel sheet using
// "Insert->Names" to be able to work with the data like you would
// with a table in a "real" database. There may be more than one table
// contained in a worksheet.
sSql = "SELECT field_1, field_2 "
"FROM demo_table "
"ORDER BY field_1";

// Execute that query (implicitly by opening the recordset)
recset.Open(CRecordset::forwardOnly, sSql, CRecordset::readOnly);

// Browse the result
while (!recset.IsEOF())
{
// Read the result line
recset.GetFieldValue("field_1", sItem1);
recset.GetFieldValue("field_2", sItem2);

// Insert result into the list
m_ctrlList.AddString(sItem1 + " --> "+sItem2);

// Skip to the next resultline
recset.MoveNext();
}

// Close the database
database.Close();

}
CATCH(CDBException, e)
{
// A database exception occured. Pop out the details...
AfxMessageBox("Database error: " + e->m_strError);
}
END_CATCH;
}


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

// Get the names of the installed drivers
// ("odbcinst.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;
}
GeneralRe: help me Pin
Anurag Gandhi2-Aug-07 21:02
professionalAnurag Gandhi2-Aug-07 21:02 
AnswerRe: help me Pin
Hamid_RT2-Aug-07 20:56
Hamid_RT2-Aug-07 20:56 
QuestionVector inside a structure Pin
vinodkoul2-Aug-07 18:46
vinodkoul2-Aug-07 18:46 
AnswerRe: Vector inside a structure Pin
Stephen Hewitt2-Aug-07 19:14
Stephen Hewitt2-Aug-07 19:14 
AnswerRe: Vector inside a structure Pin
cp98762-Aug-07 19:15
cp98762-Aug-07 19:15 
GeneralRe: Vector inside a structure Pin
vinodkoul2-Aug-07 20:12
vinodkoul2-Aug-07 20:12 
QuestionRe: Vector inside a structure Pin
vinodkoul2-Aug-07 20:43
vinodkoul2-Aug-07 20:43 
AnswerRe: Vector inside a structure Pin
cp98762-Aug-07 20:54
cp98762-Aug-07 20:54 
QuestionPrint value of key pressed...? Pin
deostroll2-Aug-07 18:22
deostroll2-Aug-07 18:22 
AnswerRe: Print value of key pressed...? Pin
bob169722-Aug-07 18:43
bob169722-Aug-07 18:43 
QuestionRe: Print value of key pressed...? Pin
deostroll2-Aug-07 18:59
deostroll2-Aug-07 18:59 
AnswerRe: Print value of key pressed...? Pin
David Crow3-Aug-07 3:52
David Crow3-Aug-07 3:52 
AnswerRe: Print value of key pressed...? Pin
bob169723-Aug-07 17:39
bob169723-Aug-07 17:39 
Questionaccess violation in int array Pin
George_George2-Aug-07 16:53
George_George2-Aug-07 16:53 
AnswerRe: access violation in int array Pin
Sameerkumar Namdeo2-Aug-07 17:17
Sameerkumar Namdeo2-Aug-07 17:17 
GeneralRe: access violation in int array Pin
George_George2-Aug-07 18:24
George_George2-Aug-07 18:24 
AnswerRe: access violation in int array Pin
JudyL_MD3-Aug-07 1:48
JudyL_MD3-Aug-07 1:48 

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.