...
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();
 | 
			
		||||
 
 | 
			
		||||
@@ -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