Home > Software engineering >  VS2010 in the preservation of EXCEL is save failed
VS2010 in the preservation of EXCEL is save failed

Time:09-27

 {
//TODO: add the command handler code
CDatabase database;
Cstrings sDriver=_T (" MICROSOFT EXCEL DRIVER (*. XLS) ");/Excel/install the driver
Cstrings sExcelFile;
//cstrings sPath;
Cstrings sSql;
Cstrings sFileName;

////the main program in path (.exe) directory, in sPath
//GetModuleFileName (NULL, sPath GetBufferSetLength (MAX_PATH + 1), MAX_PATH);
//sPath ReleaseBuffer ();
//int nPos.
//nPos=sPath ReverseFind (' \ \ ');
//sPath=sPath. Left (nPos + 1);
CFileDialog fDlg (FALSE, _T (" XLS "), NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T (" XLS File (*. XLS) | *. XLS | "));
If (fDlg DoModal ()==IDOK)
{
SFileName=fDlg. GetPathName ();
}
The else
{
return;
}
SExcelFile=sFileName;//to build Excel file
Try
{
//create access string
SSql. The Format (_T (" DRIVER={% s}; DSN=' '; FIRSTROWHASNAMES=1; READONLY=FALSE; CREATE_DB=\ \ "% s"; DBQ=% s "), sDriver, sExcelFile, sExcelFile);

//create the database (both Excel spreadsheet file)
//power program can run here, the next step will fail,
If (database. OpenEx (sSql CDatabase: : noOdbcDialog))
{
//create a table structure (name, age
SSql="create table Report (serial number char (50), the frame ID char (50), the data length char (10), data char (240))";
The database. The ExecuteSQL (sSql);
Int nItem=0;
Cstrings sNum, sID, sDataLen sData;
While (nItem & lt; M_Info. M_listData. GetItemCount ())
{
SNum=m_Info. M_listData. GetItemText (nItem, 0);
SID=m_Info. M_listData. GetItemText (nItem, 1);
SDataLen=m_Info. M_listData. GetItemText (nItem, 2);
SData=https://bbs.csdn.net/topics/m_Info.m_listData.GetItemText (nItem, 3);
//insert numerical
SSql="INSERT INTO the Report (serial number, the frame ID, data length, data) VALUES ('" + sNum + "', '" + sID +"', '" + sDataLen + "', '" + sData + ") ";
The database. The ExecuteSQL (sSql);
+ + nItem;
}
}
//close the database
The database. The Close ();
AfxMessageBox (_T (" Excel file save success!" ));
}
Catch _com_error * (e)
{
AfxMessageBox (e - & gt; ErrorMessage ());
}
}



The feeling is more than I such a beginner level, hope BBS great god,

CodePudding user response:

http://bbs.csdn.net/topics/392143402

CodePudding user response:

https://docs.microsoft.com/en-us/sql/odbc/microsoft/sqldriverconnect-excel-driver
  • Related