搞定车商方案表读取。
This commit is contained in:
@@ -1,30 +1,21 @@
|
||||
#include <libxl.h>
|
||||
#include <exception>
|
||||
#include "LoadFromExcel.h"
|
||||
#include <stdexcept>
|
||||
#include "LoadFromExcel.h"
|
||||
#include "../../excel/excel.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace libxl;
|
||||
|
||||
void SetKey( Book * pBook )
|
||||
{
|
||||
if ( pBook == nullptr )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
pBook->setKey( L"cpic", L"windows-202d21040bc4e70060bc6264a6ucu7i1" );
|
||||
}
|
||||
|
||||
/************************************************
|
||||
* \brief 从Excel文件读取车商方案表
|
||||
* \param filePath Excel文件路径
|
||||
* \param schemeMap 存放车商方案数据的map
|
||||
************************************************/
|
||||
void LoadCarDealerSchemeFromXlsx( const wstring & filePath,
|
||||
unsigned int sheetIndex,
|
||||
unsigned int firstRowIndex,
|
||||
map<wstring, CarDealerScheme> & schemeMap )
|
||||
void LoadCarDealerSchemeFromXlsx( const wstring & filePath,
|
||||
unsigned int sheetIndex,
|
||||
unsigned int startRowIndex,
|
||||
vector<CarDealerScheme> & schemeVector )
|
||||
{
|
||||
Book * pBook = xlCreateXMLBookW();
|
||||
Sheet * pSheet = nullptr;
|
||||
@@ -34,7 +25,7 @@ void LoadCarDealerSchemeFromXlsx( const wstring & filePath,
|
||||
throw runtime_error( "libxl库加载失败!" );
|
||||
}
|
||||
|
||||
SetKey( pBook );
|
||||
setKey( pBook );
|
||||
|
||||
if ( pBook->load( filePath.c_str() ) != true )
|
||||
{
|
||||
@@ -51,8 +42,43 @@ void LoadCarDealerSchemeFromXlsx( const wstring & filePath,
|
||||
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 );
|
||||
const wstring && manHourPrice = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 4, true );
|
||||
const wstring && partPrice = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 5, true );
|
||||
const wstring && claimSupport = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 6, true );
|
||||
const wstring && scheme = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 7, true );
|
||||
const wstring && isQualified = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex + 8, true );
|
||||
|
||||
CarDealerScheme carDealerScheme( theYear,
|
||||
theMonth,
|
||||
carDealerCode,
|
||||
manHourPrice,
|
||||
partPrice,
|
||||
claimSupport,
|
||||
scheme,
|
||||
isQualified );
|
||||
|
||||
schemeVector.push_back( carDealerScheme );
|
||||
|
||||
rowIndex++;
|
||||
}
|
||||
|
||||
pBook->release();
|
||||
}
|
||||
|
@@ -1,9 +1,11 @@
|
||||
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <exception>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "../../Datastructure/CarDealerScheme/CarDealerScheme.h"
|
||||
#include "../../Datastructure/CarDealerAchievement/CarDealerAchievement.h"
|
||||
|
||||
|
||||
void LoadCarDealerSchemeFromXlsx( const std::wstring & filePath,
|
||||
unsigned int sheetIndex,
|
||||
unsigned int startRowIndex,
|
||||
std::vector<CarDealerScheme> & schemeVector );
|
||||
|
@@ -59,14 +59,14 @@ public:
|
||||
}
|
||||
|
||||
CarDealerScheme( CarDealerScheme && other )
|
||||
: theYear( std::move(other.theYear) ),
|
||||
theMonth( std::move(other.theMonth) ),
|
||||
carDealerCode( std::move(other.carDealerCode) ),
|
||||
manHourPrice( std::move(other.manHourPrice) ),
|
||||
partPrice( std::move(other.partPrice) ),
|
||||
claimSupport( std::move(other.claimSupport) ),
|
||||
scheme( std::move(other.scheme) ),
|
||||
isQualified( std::move(other.isQualified) )
|
||||
: theYear( std::move( other.theYear ) ),
|
||||
theMonth( std::move( other.theMonth ) ),
|
||||
carDealerCode( std::move( other.carDealerCode ) ),
|
||||
manHourPrice( std::move( other.manHourPrice ) ),
|
||||
partPrice( std::move( other.partPrice ) ),
|
||||
claimSupport( std::move( other.claimSupport ) ),
|
||||
scheme( std::move( other.scheme ) ),
|
||||
isQualified( std::move( other.isQualified ) )
|
||||
{
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user