...
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
<ClCompile Include="..\..\..\source\Data\DataManipulation\Excel\LoadFromExcel.cpp" />
|
||||
<ClCompile Include="..\..\..\source\Data\Datastructure\CarDealerAchievement\CarDealerAchievement.cpp" />
|
||||
<ClCompile Include="..\..\..\source\Data\Datastructure\CarDealerScheme\CarDealerScheme.cpp" />
|
||||
<ClCompile Include="..\..\..\source\data\Datastructure\RepairOrder\RepairOrder.cpp" />
|
||||
<ClCompile Include="..\..\..\source\data\excel\excel.cpp" />
|
||||
<ClCompile Include="..\..\..\source\main.cpp" />
|
||||
<ClCompile Include="..\..\..\source\test\test.cpp" />
|
||||
@@ -40,6 +41,7 @@
|
||||
<ClInclude Include="..\..\..\source\Data\DataManipulation\Excel\LoadFromExcel.h" />
|
||||
<ClInclude Include="..\..\..\source\Data\Datastructure\CarDealerAchievement\CarDealerAchievement.h" />
|
||||
<ClInclude Include="..\..\..\source\Data\Datastructure\CarDealerScheme\CarDealerScheme.h" />
|
||||
<ClInclude Include="..\..\..\source\data\Datastructure\RepairOrder\RepairOrder.h" />
|
||||
<ClInclude Include="..\..\..\source\data\excel\excel.h" />
|
||||
<ClInclude Include="..\..\..\source\test\test.h" />
|
||||
</ItemGroup>
|
||||
|
@@ -56,6 +56,9 @@
|
||||
<Filter Include="excel">
|
||||
<UniqueIdentifier>{61d5dd61-6b1f-4507-bb22-4ce463ad5b85}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="数据\数据结构\送返修工单">
|
||||
<UniqueIdentifier>{985188c7-d233-46c8-bc1f-f7079c27bb2e}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\..\source\main.cpp">
|
||||
@@ -82,6 +85,9 @@
|
||||
<ClCompile Include="..\..\..\source\data\excel\excel.cpp">
|
||||
<Filter>excel</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\source\data\Datastructure\RepairOrder\RepairOrder.cpp">
|
||||
<Filter>数据\数据结构\送返修工单</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<QtRcc Include="..\..\..\source\resource.qrc">
|
||||
@@ -127,5 +133,8 @@
|
||||
<ClInclude Include="..\..\..\source\data\excel\excel.h">
|
||||
<Filter>excel</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\source\data\Datastructure\RepairOrder\RepairOrder.h">
|
||||
<Filter>数据\数据结构\送返修工单</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
@@ -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();
|
||||
|
@@ -0,0 +1,2 @@
|
||||
|
||||
#include "RepairOrder.h"
|
@@ -0,0 +1,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
class RepairOrder
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
};
|
@@ -4,6 +4,10 @@
|
||||
|
||||
#include <libxl.h>
|
||||
|
||||
/************************************************
|
||||
* \brief 注册libxl产品
|
||||
* \param pBook
|
||||
************************************************/
|
||||
void setKey( libxl::Book * pBook );
|
||||
|
||||
/************************************************
|
||||
@@ -12,6 +16,7 @@ void setKey( libxl::Book * pBook );
|
||||
* \param sheetIndex sheet的索引值
|
||||
* \param rowIndex 行号
|
||||
* \param colIndex 列号
|
||||
* \param isInteger 单元格为数字类型时,选择是输出整形还是浮点型字符串
|
||||
* \return 返回的字符串
|
||||
************************************************/
|
||||
std::wstring ReadCellStringFromXlsx( libxl::IBookT<wchar_t> * pBook,
|
||||
|
@@ -1,5 +1,4 @@
|
||||
|
||||
#include <vector>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "test.h"
|
||||
#include "../data/DataManipulation/Excel/LoadFromExcel.h"
|
||||
@@ -15,10 +14,13 @@ void test()
|
||||
|
||||
void excelTest()
|
||||
{
|
||||
vector<CarDealerScheme> schemeVector;
|
||||
wstring filePath = L"D:/develop/projects_win/2019/car_dealer_util/数据/PC端导入模板(管理员版).xlsx";
|
||||
vector<CarDealerScheme> schemeVector;
|
||||
vector<CarDealerAchievement> achievementsVector;
|
||||
|
||||
LoadCarDealerSchemeFromXlsx(filePath, 0, 1, schemeVector);
|
||||
wstring filePath = L"D:/develop/projects_win/2019/car_dealer_util/数据/PC端导入模板(客户经理版).xlsx";
|
||||
|
||||
//LoadCarDealerSchemeFromXlsx(filePath, 0, 1, schemeVector);
|
||||
LoadCarDealerAchievementFromXlsx( filePath, 0, 1, achievementsVector );
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user