(*this, strSheetName); 118 if (!sheet) return 0; 119 sheet->m_nFlag = CODBCExcelSheet::Add; 120 sheet->m_ColHeaders.Copy(ColHeaders); 121 m_Sheets.insert(make_pair(strSheetName, sheet)); 122 } 123 else 124 { 125 sheet->m_dwRows = 0; 126 sheet->m_nFlag = CODBCExcelSheet::Update; 127 sheet->m_ColHeaders.RemoveAll(); 128 sheet->m_ColHeaders.Copy(ColHeaders); 129 } 130 sheet->m_dwCols = ColHeaders.GetCount(); 131 return sheet; 132} 133 134void CODBCExcel::DeleteWorkSheet(const CString& strSheetName) 135{ 136 map::iterator iter = m_Sheets.find(strSheetName); 137 if (iter != m_Sheets.end()) 138 { 139 iter->second->m_nFlag = CODBCExcelSheet::Delete; 140 iter->second->ResetCells(); 141 } 142 else 143 { 144 CString strSQL; 145 strSQL.Format (_T("DROP TABLE [%s$A1:IV65536]"), strSheetName); 146 try 147 { 148 m_db.ExecuteSQL(strSQL); 149 } 150 catch (CDBException* e) 151 { 152 return ; 153 } 154 } 155} 156 157////////////////////////////////////////////////////////////////////////// 158CODBCExcelSheet::CODBCExcelSheet(CODBCExcel& Excel, const CString& strName): 159m_strName(strName), 160m_Excel(Excel), 161m_recordset(&Excel.m_db) 162{ 163 m_dwCols = m_dwRows = 0; 164} 165 166bool CODBCExcelSheet::Init() 167{ 168 DWORD dwCol; 169 m_ColHeaders.RemoveAll(); 170 for (dwCol = 0; dwCol < m_recordset.m_nResultCols; ++dwCol) 171 { 172 m_recordset.m_rgODBCFieldInfos[dwCol].m_strName.Trim(); 173 m_ColHeaders.Add(m_recordset.m_rgODBCFieldInfos[dwCol].m_strName); 174 } 175 m_dwCols = m_recordset.m_nResultCols; 176 m_nFlag = CODBCExcelSheet::Exist; 177 CString strText; 178 for (DWORD dwRow = 0;!m_recordset.IsEOF();) 179 { 180 try 181 { 182 CDBVariant dbVal; 183 for (dwCol = 0; dwCol < m_recordset.m_nResultCols; ++dwCol) 184 { 185 m_recordset.GetFieldValue(dwCol, dbVal); 186 Cell(dwRow, dwCol)->Set(dbVal); 187 /*m_recordset.GetFieldValue(dwCol, strText); 188 Cell(dwRow, dwCol)->Set(strText); */ 189 } 190 ++dwRow; m_recordset.MoveNext(); 191 } 192 catch (CDBException* e) 193 { 194 m_recordset.Close(); 195 return false; 196 } 197 } 198 m_recordset.Close(); 199 UpdateRowCount(); 200 return true; 201} 202 203void CODBCExcelSheet::UpdateRowCount() 204{ 205 for (;!m_Cells.empty();) 206 { 207 vector& vecCol = m_Cells.back(); 208 vector::iterator iter; 209 for (iter = vecCol.begin(); iter != vecCol.end(); ++iter) 210 { 211 if (!(*iter).m_strVal.IsEmpty()) break; 212 } 213 if (iter == vecCol.end()) 214 { 215 m_Cells.pop_back(); 216 } 217 else 218 { 219 break; 220 } 221 } 222 m_dwRows = m_Cells.size(); 223} 224 225bool CODBCExcelSheet::Save() 226{ 227 CString strSQL; 228 switch(m_nFlag) 229 { 230 case Update: 231 { 232 strSQL.Format(_T("DROP TABLE [%s$A1:IV65536]"), m_strName); 233 try 234 { 235 m_Excel.m_db.ExecuteSQL(strSQL); 236 } 237 catch (CDBException* e) 238 |