下面这段代码可以实现往excel表中写入数据,但每次写完重新调用写入新的数据之后,之前的会被覆盖
下面这段代码可以实现往excel表中写入数据,但每次写完重新调用写入新的数据之后,之前的会被覆盖,谁能告诉我该怎么改可以使新的数据加在后面而非覆盖CDatabasedat...
下面这段代码可以实现往excel表中写入数据,但每次写完重新调用写入新的数据之后,之前的会被覆盖,谁能告诉我该怎么改可以使新的数据加在后面而非覆盖
CDatabase database; // Excel安装驱动
CString sDriver = "MICROSOFT EXCEL DRIVER (*.XLS)"; // 要建立的Excel文件
CString sExcelFile = "..\\看板一B线.xls";
CString sSql;
DeleteFile(sExcelFile);
TRY
{
sSql.Format("DRIVER={%s};DSN='';FIRSTROWHASNAMES=1;READONLY=FALSE;CREATE_DB=\"%s\";DBQ=%s", sDriver, sExcelFile, sExcelFile); // 创建Excel文件
if( database.OpenEx(sSql,CDatabase::noOdbcDialog) )
{ sSql = "CREATE TABLE data (规格B1 TEXT,规格B2 TEXT,批次B1 TEXT,批次B2 TEXT, 计划产量B NUMBER,到达时间 TEXT)";
database.ExecuteSQL(sSql); //插入数据
int proB;
CString styleB1;
CString styleB2;
CString piciB1;
CString piciB2;
CTime time = CTime::GetCurrentTime();
CString m_strTime = time.Format("%Y-%m-%d %H:%M:%S");
::GetPrivateProfileString("看板1","规格B1","",styleB1.GetBuffer(4),4,".\\Init.ini");styleB1.ReleaseBuffer();
::GetPrivateProfileString("看板1","规格B2","",styleB2.GetBuffer(4),4,".\\Init.ini"); styleB2.ReleaseBuffer();
::GetPrivateProfileString("看板1","批次B1","",piciB1.GetBuffer(4),4,".\\Init.ini");piciB1.ReleaseBuffer();
::GetPrivateProfileString("看板1","批次B2","",piciB2.GetBuffer(4),4,".\\Init.ini");piciB2.ReleaseBuffer();
proB= ::GetPrivateProfileInt("看板1","计划产量B",1,".\\Init.ini");
sSql.Format("INSERT INTO data (规格B1,规格B2,批次B1,批次B2, 计划产量B,到达时间)VALUES ('%s','%s','%s','%s',%d,'%s')",styleB1,styleB2,piciB1,piciB2,proB,m_strTime);
database.ExecuteSQL(sSql); } // 关闭数据库
database.Close();
} 展开
CDatabase database; // Excel安装驱动
CString sDriver = "MICROSOFT EXCEL DRIVER (*.XLS)"; // 要建立的Excel文件
CString sExcelFile = "..\\看板一B线.xls";
CString sSql;
DeleteFile(sExcelFile);
TRY
{
sSql.Format("DRIVER={%s};DSN='';FIRSTROWHASNAMES=1;READONLY=FALSE;CREATE_DB=\"%s\";DBQ=%s", sDriver, sExcelFile, sExcelFile); // 创建Excel文件
if( database.OpenEx(sSql,CDatabase::noOdbcDialog) )
{ sSql = "CREATE TABLE data (规格B1 TEXT,规格B2 TEXT,批次B1 TEXT,批次B2 TEXT, 计划产量B NUMBER,到达时间 TEXT)";
database.ExecuteSQL(sSql); //插入数据
int proB;
CString styleB1;
CString styleB2;
CString piciB1;
CString piciB2;
CTime time = CTime::GetCurrentTime();
CString m_strTime = time.Format("%Y-%m-%d %H:%M:%S");
::GetPrivateProfileString("看板1","规格B1","",styleB1.GetBuffer(4),4,".\\Init.ini");styleB1.ReleaseBuffer();
::GetPrivateProfileString("看板1","规格B2","",styleB2.GetBuffer(4),4,".\\Init.ini"); styleB2.ReleaseBuffer();
::GetPrivateProfileString("看板1","批次B1","",piciB1.GetBuffer(4),4,".\\Init.ini");piciB1.ReleaseBuffer();
::GetPrivateProfileString("看板1","批次B2","",piciB2.GetBuffer(4),4,".\\Init.ini");piciB2.ReleaseBuffer();
proB= ::GetPrivateProfileInt("看板1","计划产量B",1,".\\Init.ini");
sSql.Format("INSERT INTO data (规格B1,规格B2,批次B1,批次B2, 计划产量B,到达时间)VALUES ('%s','%s','%s','%s',%d,'%s')",styleB1,styleB2,piciB1,piciB2,proB,m_strTime);
database.ExecuteSQL(sSql); } // 关闭数据库
database.Close();
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询