This commit is contained in:
Kane Wang 2021-06-15 17:41:20 +08:00
parent dc162b3180
commit 6406fe1784
3 changed files with 71 additions and 2 deletions

View File

@ -29,7 +29,8 @@ std::wstring ReadCellStringFromXlsx( libxl::IBookT<wchar_t> * pBook,
* \param sheetName
* \return
************************************************/
libxl::Sheet * getXlsxSheetByName( libxl::IBookT<wchar_t> * pBook, const std::wstring & sheetName );
libxl::Sheet * getXlsxSheetByName( libxl::IBookT<wchar_t> * 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 );

View File

@ -0,0 +1,43 @@
#include <stdexcept>
#include <cwchar>
#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;
}

View File

@ -0,0 +1,26 @@
#pragma once
#include <libxl.h>
/************************************************
* \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<wchar_t>* pBook, const std::wstring& sheetName);