This commit is contained in:
Kane Wang 2020-05-13 21:24:02 +08:00
parent 9cfdd61539
commit 76704f699d
2 changed files with 31 additions and 32 deletions

View File

@ -20,17 +20,17 @@ void RepairMonitoringFromExcelToOracle( const std::wstring & filePath,
const std::string & password ) const std::string & password )
{ {
//防御性验证 //防御性验证
if (filePath.empty() == true || if ( filePath.empty() == true ||
tnsName.empty() == true || tnsName.empty() == true ||
userName.empty() == true || userName.empty() == true ||
password.empty() == true) password.empty() == true )
{ {
throw runtime_error("参数错误!"); throw runtime_error( "参数错误!" );
} }
//libxl对象 //libxl对象
Book* pBook = xlCreateBookW(); Book * pBook = xlCreateBookW();
Sheet* pSheet = nullptr; Sheet * pSheet = nullptr;
map<int, wstring> titleMap; //存放标题行 map<int, wstring> titleMap; //存放标题行
unsigned int firstColumnIndex; //第一列 unsigned int firstColumnIndex; //第一列
unsigned int lastColumnIndex; //最后一列 unsigned int lastColumnIndex; //最后一列
@ -38,24 +38,24 @@ void RepairMonitoringFromExcelToOracle( const std::wstring & filePath,
unsigned int lastRowIndex; unsigned int lastRowIndex;
//ocilib对象 //ocilib对象
Connection* pConnection = nullptr; Connection * pConnection = nullptr;
Statement* pStatement = nullptr; Statement * pStatement = nullptr;
if (pBook == nullptr) if ( pBook == nullptr )
{ {
throw runtime_error("libxl初始化失败"); throw runtime_error( "libxl初始化失败" );
} }
if (pBook->load(filePath.c_str()) != true) if ( pBook->load( filePath.c_str() ) != true )
{ {
throw runtime_error("打开excel文件失败"); throw runtime_error( "打开excel文件失败" );
} }
pSheet = pBook->getSheet(sheetIndex); pSheet = pBook->getSheet( sheetIndex );
if (pSheet == nullptr) if ( pSheet == nullptr )
{ {
throw runtime_error("读取sheet失败失败"); throw runtime_error( "读取sheet失败失败" );
} }
firstColumnIndex = pSheet->firstCol(); firstColumnIndex = pSheet->firstCol();
@ -67,42 +67,40 @@ void RepairMonitoringFromExcelToOracle( const std::wstring & filePath,
unsigned int rowIndex = firstRowIndex; unsigned int rowIndex = firstRowIndex;
//保存标题 //保存标题
if (hasTitleRow) if ( hasTitleRow )
{ {
while (colIndex <= lastColumnIndex) while ( colIndex <= lastColumnIndex )
{ {
wstring&& title = ReadCellStringFromXlsx(pBook, sheetIndex, firstRowIndex, colIndex, false); wstring && title = ReadCellStringFromXlsx( pBook, sheetIndex, firstRowIndex, colIndex, false );
titleMap.insert(pair<int, wstring>(colIndex, title)); titleMap.insert( pair<int, wstring>( colIndex, title ) );
++colIndex; ++colIndex;
} }
} }
//逐行保存数据 //逐行保存数据
while (colIndex <= lastColumnIndex) while ( colIndex <= lastColumnIndex )
{ {
wstring&& title = ReadCellStringFromXlsx(pBook, sheetIndex, firstRowIndex, colIndex, false); wstring && title = ReadCellStringFromXlsx( pBook, sheetIndex, firstRowIndex, colIndex, false );
titleMap.insert(pair<int, wstring>(colIndex, title)); titleMap.insert( pair<int, wstring>( colIndex, title ) );
++colIndex; ++colIndex;
} }
//逐行保存数据 //逐行保存数据
for (rowIndex = firstRowIndex; rowIndex >= lastRowIndex; rowIndex++) for ( rowIndex = firstRowIndex; rowIndex >= lastRowIndex; rowIndex++ )
{ {
//如果是标题行,就跳过 //如果是标题行,就跳过
if (rowIndex == firstRowIndex) if ( rowIndex == firstRowIndex )
{ {
continue; continue;
} }
//逐列绑定sql语句 //逐列绑定sql语句
for (colIndex = firstColumnIndex; colIndex <= lastColumnIndex; colIndex++) for ( colIndex = firstColumnIndex; colIndex <= lastColumnIndex; colIndex++ )
{ {
} }
} }
} }

View File

@ -1,4 +1,4 @@
#include "QCarDealerSchemaWidget.h" #include "QCarDealerSchemaWidget.h"
QCarDealerSchemaWidget::QCarDealerSchemaWidget(QWidget *parent) QCarDealerSchemaWidget::QCarDealerSchemaWidget(QWidget *parent)
: QWidget(parent) : QWidget(parent)
@ -8,4 +8,5 @@ QCarDealerSchemaWidget::QCarDealerSchemaWidget(QWidget *parent)
QCarDealerSchemaWidget::~QCarDealerSchemaWidget() QCarDealerSchemaWidget::~QCarDealerSchemaWidget()
{ {
} }