...
This commit is contained in:
@@ -66,6 +66,14 @@ void LoadCarDealerSchemeFromXlsx( const wstring & filePath,
|
||||
const wstring && scheme = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 7, true );
|
||||
const wstring && isQualified = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 8, true );
|
||||
|
||||
//空行跳过
|
||||
if (carDealerCode.empty() == true)
|
||||
{
|
||||
rowIndex++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
CarDealerScheme carDealerScheme( theYear,
|
||||
theMonth,
|
||||
carDealerCode,
|
||||
@@ -82,3 +90,182 @@ void LoadCarDealerSchemeFromXlsx( const wstring & filePath,
|
||||
|
||||
pBook->release();
|
||||
}
|
||||
|
||||
void LoadCarDealerAchievementFromXlsx( const std::wstring & filePath,
|
||||
unsigned sheetIndex,
|
||||
unsigned startRowIndex,
|
||||
std::vector<CarDealerAchievement> & achievementVector )
|
||||
{
|
||||
Book * pBook = xlCreateXMLBookW();
|
||||
Sheet * pSheet = nullptr;
|
||||
|
||||
if ( pBook == nullptr )
|
||||
{
|
||||
throw runtime_error( "libxl库加载失败!" );
|
||||
}
|
||||
|
||||
setKey( pBook );
|
||||
|
||||
if ( pBook->load( filePath.c_str() ) != true )
|
||||
{
|
||||
string errorMessage = "打开文件失败!";
|
||||
errorMessage.append( pBook->errorMessage() );
|
||||
|
||||
throw runtime_error( errorMessage );
|
||||
}
|
||||
|
||||
pSheet = pBook->getSheet( sheetIndex );
|
||||
|
||||
if ( pSheet == nullptr )
|
||||
{
|
||||
string errorMessage = "读取sheet失败!";
|
||||
errorMessage.append( pBook->errorMessage() );
|
||||
|
||||
pBook->release();
|
||||
|
||||
throw runtime_error( errorMessage );
|
||||
}
|
||||
|
||||
int lastRowIndex = pSheet->lastRow();
|
||||
int firstRowIndex = pSheet->firstRow();
|
||||
int firstColumnIndex = pSheet->firstCol();
|
||||
int rowIndex = firstRowIndex + startRowIndex;
|
||||
|
||||
while ( rowIndex <= lastRowIndex )
|
||||
{
|
||||
int colunmIndex = firstRowIndex;
|
||||
|
||||
const wstring && theYear = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex, true );
|
||||
const wstring && theMonth = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 1, true );
|
||||
const wstring && carDealerCode = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 2, true );
|
||||
const wstring && carDealerName = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 3, true );
|
||||
long double checkedAchievement = 0;
|
||||
int policyAmount = 0;
|
||||
int cpicAmount = 0;
|
||||
int piccAmount = 0;
|
||||
int pinganAmount = 0;
|
||||
int othersAmount = 0;
|
||||
|
||||
//空行跳过
|
||||
if ( carDealerCode.empty() == true )
|
||||
{
|
||||
rowIndex++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
//每个字段都要先判断数据类型再读写,防止填写表格的人填错内容。
|
||||
CellType type = pSheet->cellType( rowIndex, firstColumnIndex + 4 );
|
||||
char errorMessage[1000];
|
||||
|
||||
//产值
|
||||
if ( type == CELLTYPE_NUMBER )
|
||||
{
|
||||
checkedAchievement = pSheet->readNum( rowIndex, firstColumnIndex + 4 );
|
||||
}
|
||||
else
|
||||
{
|
||||
pBook->release();
|
||||
|
||||
sprintf( errorMessage, "第%d行第%d列,格式错误,不是数字类型!", rowIndex, firstColumnIndex + 4 );
|
||||
|
||||
throw runtime_error( errorMessage );
|
||||
}
|
||||
|
||||
//签单数量
|
||||
type = pSheet->cellType( rowIndex, firstColumnIndex + 5 );
|
||||
|
||||
if ( type == CELLTYPE_NUMBER )
|
||||
{
|
||||
policyAmount = static_cast<int>(pSheet->readNum( rowIndex, firstColumnIndex + 5 ));
|
||||
}
|
||||
else
|
||||
{
|
||||
pBook->release();
|
||||
|
||||
sprintf( errorMessage, "第%d行第%d列,格式错误,不是数字类型!", rowIndex, firstColumnIndex + 5 );
|
||||
|
||||
throw runtime_error( errorMessage );
|
||||
}
|
||||
|
||||
//太平洋保险新车签单台次
|
||||
type = pSheet->cellType( rowIndex, firstColumnIndex + 6 );
|
||||
|
||||
if ( type == CELLTYPE_NUMBER )
|
||||
{
|
||||
cpicAmount = static_cast<int>(pSheet->readNum( rowIndex, firstColumnIndex + 6 ));
|
||||
}
|
||||
else
|
||||
{
|
||||
pBook->release();
|
||||
|
||||
sprintf( errorMessage, "第%d行第%d列,格式错误,不是数字类型!", rowIndex, firstColumnIndex + 6 );
|
||||
|
||||
throw runtime_error( errorMessage );
|
||||
}
|
||||
|
||||
//中国人保新车签单台次
|
||||
type = pSheet->cellType( rowIndex, firstColumnIndex + 7 );
|
||||
|
||||
if ( type == CELLTYPE_NUMBER )
|
||||
{
|
||||
piccAmount = static_cast<int>(pSheet->readNum( rowIndex, firstColumnIndex + 7 ));
|
||||
}
|
||||
else
|
||||
{
|
||||
pBook->release();
|
||||
|
||||
sprintf( errorMessage, "第%d行第%d列,格式错误,不是数字类型!", rowIndex, firstColumnIndex + 7 );
|
||||
|
||||
throw runtime_error( errorMessage );
|
||||
}
|
||||
|
||||
//中国平安新车签单台次
|
||||
type = pSheet->cellType( rowIndex, firstColumnIndex + 8 );
|
||||
|
||||
if ( type == CELLTYPE_NUMBER )
|
||||
{
|
||||
pinganAmount = static_cast<int>(pSheet->readNum( rowIndex, firstColumnIndex + 8 ));
|
||||
}
|
||||
else
|
||||
{
|
||||
pBook->release();
|
||||
|
||||
sprintf( errorMessage, "第%d行第%d列,格式错误,不是数字类型!", rowIndex, firstColumnIndex + 8 );
|
||||
|
||||
throw runtime_error( errorMessage );
|
||||
}
|
||||
|
||||
//其他保险公司新车签单台次
|
||||
type = pSheet->cellType( rowIndex, firstColumnIndex + 9 );
|
||||
|
||||
if ( type == CELLTYPE_NUMBER )
|
||||
{
|
||||
othersAmount = static_cast<int>(pSheet->readNum( rowIndex, firstColumnIndex + 9 ));
|
||||
}
|
||||
else
|
||||
{
|
||||
pBook->release();
|
||||
|
||||
sprintf( errorMessage, "第%d行第%d列,格式错误,不是数字类型!", rowIndex, firstColumnIndex + 9 );
|
||||
|
||||
throw runtime_error( errorMessage );
|
||||
}
|
||||
|
||||
CarDealerAchievement achievement( theYear,
|
||||
theMonth,
|
||||
carDealerCode,
|
||||
checkedAchievement,
|
||||
policyAmount,
|
||||
cpicAmount,
|
||||
piccAmount,
|
||||
pinganAmount,
|
||||
othersAmount );
|
||||
|
||||
achievementVector.push_back( achievement );
|
||||
|
||||
rowIndex++;
|
||||
}
|
||||
|
||||
pBook->release();
|
||||
}
|
||||
|
@@ -9,3 +9,10 @@ void LoadCarDealerSchemeFromXlsx( const std::wstring & filePath,
|
||||
unsigned int sheetIndex,
|
||||
unsigned int startRowIndex,
|
||||
std::vector<CarDealerScheme> & schemeVector );
|
||||
|
||||
void LoadCarDealerAchievementFromXlsx( const std::wstring & filePath,
|
||||
unsigned int sheetIndex,
|
||||
unsigned int startRowIndex,
|
||||
std::vector<CarDealerAchievement> & achievementVector );
|
||||
|
||||
//void LoadRepairOrderFromXlsx();
|
||||
|
Reference in New Issue
Block a user