最后一个表!

This commit is contained in:
Kane Wang 2020-03-18 18:24:18 +08:00
parent d6faa08e7a
commit 13309fcf74
6 changed files with 102 additions and 0 deletions

View File

@ -20,6 +20,7 @@
<ClCompile Include="..\..\..\source\data\AppParameters\AppParameters.cpp" />
<ClCompile Include="..\..\..\source\Data\DataManipulation\Excel\ExportToExcel.cpp" />
<ClCompile Include="..\..\..\source\Data\DataManipulation\Excel\LoadFromExcel.cpp" />
<ClCompile Include="..\..\..\source\data\DataManipulation\FromExcelToOracle\FromExcelToOracle.cpp" />
<ClCompile Include="..\..\..\source\Data\DataManipulation\oracle\ImportToOracle.cpp" />
<ClCompile Include="..\..\..\source\Data\Datastructure\CarDealerAchievement\CarDealerAchievement.cpp" />
<ClCompile Include="..\..\..\source\Data\Datastructure\CarDealerScheme\CarDealerScheme.cpp" />
@ -48,6 +49,7 @@
<ClInclude Include="..\..\..\source\data\AppParameters\AppParameters.h" />
<ClInclude Include="..\..\..\source\Data\DataManipulation\Excel\ExportToExcel.h" />
<ClInclude Include="..\..\..\source\Data\DataManipulation\Excel\LoadFromExcel.h" />
<ClInclude Include="..\..\..\source\data\DataManipulation\FromExcelToOracle\FromExcelToOracle.h" />
<ClInclude Include="..\..\..\source\Data\DataManipulation\oracle\ImportToOracle.h" />
<ClInclude Include="..\..\..\source\Data\Datastructure\CarDealerAchievement\CarDealerAchievement.h" />
<ClInclude Include="..\..\..\source\Data\Datastructure\CarDealerScheme\CarDealerScheme.h" />

View File

@ -83,6 +83,9 @@
<Filter Include="数据\全局对象">
<UniqueIdentifier>{7f951e1f-a198-4833-bbec-853de77c8cfe}</UniqueIdentifier>
</Filter>
<Filter Include="数据\数据管理\导入导出\直接导入导出">
<UniqueIdentifier>{ef490558-0c27-4a12-a626-583699d6a35f}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\source\main.cpp">
@ -133,6 +136,9 @@
<ClCompile Include="..\..\..\source\data\AppParameters\AppParameters.cpp">
<Filter>数据\全局对象</Filter>
</ClCompile>
<ClCompile Include="..\..\..\source\data\DataManipulation\FromExcelToOracle\FromExcelToOracle.cpp">
<Filter>数据\数据管理\导入导出\直接导入导出</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<QtRcc Include="..\..\..\source\resource.qrc">
@ -205,5 +211,8 @@
<ClInclude Include="..\..\..\source\data\AppParameters\AppParameters.h">
<Filter>数据\全局对象</Filter>
</ClInclude>
<ClInclude Include="..\..\..\source\data\DataManipulation\FromExcelToOracle\FromExcelToOracle.h">
<Filter>数据\数据管理\导入导出\直接导入导出</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -0,0 +1,80 @@
#include <map>
#include <stdexcept>
#include <exception>
#include <ocilib.hpp>
#include <libxl.h>
#include "FromExcelToOracle.h"
#include "../../excel/excel.h"
using namespace std;;
using namespace ocilib;
using namespace libxl;
void RepairMonitoringFromExcelToOracle( const std::wstring & filePath,
unsigned int sheetIndex,
unsigned int titleRowIndex,
unsigned int firstRowIndex,
const std::string & tnsName,
const std::string & userName,
const std::string & password )
{
//防御性验证
if ( filePath.empty() == true ||
tnsName.empty() == true ||
userName.empty() == true ||
password.empty() == true )
{
throw runtime_error( "参数错误!" );
}
//libxl对象
Book * pBook = xlCreateBookW();
Sheet * pSheet = nullptr;
map<int, wstring> titleMap; //存放标题行
unsigned int firstColumnIndex; //第一列
unsigned int lastColumnIndex; //最后一列
unsigned int firstRowIndex;
unsigned int lastRowIndex;
//ocilib对象
Connection * pConnection = nullptr;
Statement * pStatement = nullptr;
if ( pBook == nullptr )
{
throw runtime_error( "libxl初始化失败" );
}
if ( pBook->load( filePath.c_str() ) != true )
{
throw runtime_error( "打开excel文件失败" );
}
pSheet = pBook->getSheet( sheetIndex );
if ( pSheet == nullptr )
{
throw runtime_error( "读取sheet失败失败" );
}
firstColumnIndex = pSheet->firstCol();
lastColumnIndex = pSheet->lastCol();
firstRowIndex = pSheet->firstRow();
lastRowIndex = pSheet->lastRow();
unsigned int index = firstColumnIndex;
//保存标题
while ( index <= lastColumnIndex )
{
wstring && title = ReadCellStringFromXlsx( pBook, sheetIndex, titleRowIndex, index, false );
titleMap.insert( pair<int, wstring>( index, title ) );
++index;
}
//逐行保存数据
}

View File

@ -0,0 +1,11 @@
#pragma once
#include <iostream>
void RepairMonitoringFromExcelToOracle( const std::wstring & filePath,
unsigned int sheetIndex,
unsigned int titleRowIndex,
unsigned int firstRowIndex,
const std::string & tnsName,
const std::string & userName,
const std::string & password );

Binary file not shown.

Binary file not shown.