diff --git a/code/cpp/car_dealer_util/source/Data/excel/excel.h b/code/cpp/car_dealer_util/source/Data/excel/excel.h index 7b43ec0..b7bbf38 100644 --- a/code/cpp/car_dealer_util/source/Data/excel/excel.h +++ b/code/cpp/car_dealer_util/source/Data/excel/excel.h @@ -29,7 +29,8 @@ std::wstring ReadCellStringFromXlsx( libxl::IBookT * pBook, * \param sheetName * \return ************************************************/ -libxl::Sheet * getXlsxSheetByName( libxl::IBookT * pBook, const std::wstring & sheetName ); +libxl::Sheet * getXlsxSheetByName( libxl::IBookT * pBook, + const std::wstring & sheetName ); /************************************************ * \brief 核对excel表格的内容,根据pszCaptionFormat参数提供的表头数组来核对 @@ -45,4 +46,3 @@ bool checkExcelFileFormat( libxl::Book * pBook, int captionRowIndex, const wchar_t * pszCaptionFormat[], int captionCount ); - diff --git a/code/cpp/car_dealer_util/source/util/excel/excel_util.cpp b/code/cpp/car_dealer_util/source/util/excel/excel_util.cpp new file mode 100644 index 0000000..17a6076 --- /dev/null +++ b/code/cpp/car_dealer_util/source/util/excel/excel_util.cpp @@ -0,0 +1,43 @@ +#include +#include +#include "excel_util.h" + +using namespace libxl; +using namespace std; + +bool checkExcelFileFormat( Book * pBook, + int sheetIndex, + int captionRowIndex, + const wchar_t * pszCaptionFormat[], + int captionCount ) +{ + if ( pBook == nullptr ) + { + throw logic_error( "Excel文件指针为空!" ); + } + + if ( sheetIndex < 0 || captionRowIndex < 0 ) + { + throw logic_error( "标题行参数错误!" ); + } + + Sheet * pSheet = pBook->getSheet( sheetIndex ); + int captionIndex = 0; + bool isEqual = true; + + while ( captionIndex < captionCount ) + { + const wchar_t * pwszCaption = pSheet->readStr( captionRowIndex, captionIndex ); + + if ( wcscmp( pwszCaption, pszCaptionFormat[captionIndex] ) != 0 ) + { + isEqual = false; + + break; + } + + captionIndex++; + } + + return isEqual; +} diff --git a/code/cpp/car_dealer_util/source/util/excel/excel_util.h b/code/cpp/car_dealer_util/source/util/excel/excel_util.h new file mode 100644 index 0000000..35e5024 --- /dev/null +++ b/code/cpp/car_dealer_util/source/util/excel/excel_util.h @@ -0,0 +1,26 @@ +#pragma once + +#include + + +/************************************************ +* \brief 核对excel表格的内容,根据pszCaptionFormat参数提供的表头数组来核对 +* \param pBook excel文件指针 +* \param sheetIndex 要核对的sheet索引 +* \param captionRowIndex 标题行索引 +* \param pszCaptionFormat 包含标题内容的字符串数组 +* \param captionCount 标题数量 +* \return +************************************************/ +bool checkExcelFileFormat( libxl::Book * pBook, + int sheetIndex, + int captionRowIndex, + const wchar_t * pszCaptionFormat[], + int captionCount ); + +/************************************************ +* \brief 通过名称获取sheet +* \param sheetName +* \return +************************************************/ +libxl::Sheet* getXlsxSheetByName(libxl::IBookT* pBook, const std::wstring& sheetName);