...
This commit is contained in:
		@@ -11,26 +11,26 @@ 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 )
 | 
			
		||||
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 )
 | 
			
		||||
	if (filePath.empty() == true ||
 | 
			
		||||
		tnsName.empty() == true ||
 | 
			
		||||
		userName.empty() == true ||
 | 
			
		||||
		password.empty() == true)
 | 
			
		||||
	{
 | 
			
		||||
		throw runtime_error( "参数错误!" );
 | 
			
		||||
		throw runtime_error("参数错误!");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	//libxl对象
 | 
			
		||||
	Book *            pBook  = xlCreateBookW();
 | 
			
		||||
	Sheet *           pSheet = nullptr;
 | 
			
		||||
	Book* pBook = xlCreateBookW();
 | 
			
		||||
	Sheet* pSheet = nullptr;
 | 
			
		||||
	map<int, wstring> titleMap;         //存放标题行
 | 
			
		||||
	unsigned int      firstColumnIndex; //第一列
 | 
			
		||||
	unsigned int      lastColumnIndex;  //最后一列
 | 
			
		||||
@@ -38,43 +38,58 @@ void RepairMonitoringFromExcelToOracle( const std::wstring & filePath,
 | 
			
		||||
	unsigned int      lastRowIndex;
 | 
			
		||||
 | 
			
		||||
	//ocilib对象
 | 
			
		||||
	Connection * pConnection = nullptr;
 | 
			
		||||
	Statement *  pStatement  = nullptr;
 | 
			
		||||
	Connection* pConnection = 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();
 | 
			
		||||
	lastColumnIndex  = pSheet->lastCol();
 | 
			
		||||
	firstRowIndex    = pSheet->firstRow();
 | 
			
		||||
	lastRowIndex     = pSheet->lastRow();
 | 
			
		||||
	lastColumnIndex = pSheet->lastCol();
 | 
			
		||||
	firstRowIndex = pSheet->firstRow();
 | 
			
		||||
	lastRowIndex = pSheet->lastRow();
 | 
			
		||||
 | 
			
		||||
	unsigned int index = firstColumnIndex;
 | 
			
		||||
	unsigned int colIndex = firstColumnIndex;
 | 
			
		||||
	unsigned int rowIndex = firstRowIndex;
 | 
			
		||||
 | 
			
		||||
	//保存标题
 | 
			
		||||
	while ( index <= lastColumnIndex )
 | 
			
		||||
	while (colIndex <= lastColumnIndex)
 | 
			
		||||
	{
 | 
			
		||||
		wstring && title = ReadCellStringFromXlsx( pBook, sheetIndex, titleRowIndex, index, false );
 | 
			
		||||
		wstring&& title = ReadCellStringFromXlsx(pBook, sheetIndex, titleRowIndex, colIndex, false);
 | 
			
		||||
 | 
			
		||||
		titleMap.insert( pair<int, wstring>( index, title ) );
 | 
			
		||||
		titleMap.insert(pair<int, wstring>(colIndex, title));
 | 
			
		||||
 | 
			
		||||
		++index;
 | 
			
		||||
		++colIndex;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	//逐行保存数据
 | 
			
		||||
	for (rowIndex = firstRowIndex; rowIndex >= lastRowIndex; rowIndex++)
 | 
			
		||||
	{
 | 
			
		||||
		//如果是标题行,就跳过
 | 
			
		||||
		if (rowIndex == titleRowIndex)
 | 
			
		||||
		{
 | 
			
		||||
			continue;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//逐列绑定sql语句
 | 
			
		||||
		for (colIndex = firstColumnIndex; colIndex <= lastColumnIndex; colIndex++)
 | 
			
		||||
		{
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user