From dc162b3180b8ce4337a07d92a02492375bfdedc0 Mon Sep 17 00:00:00 2001 From: Kane Wang Date: Tue, 15 Jun 2021 11:42:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=81=9A=E4=BA=86=E4=B8=80=E7=82=B9=E7=82=B9?= =?UTF-8?q?=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataManipulation/Excel/LoadFromExcel.cpp | 6 +-- .../source/Data/excel/excel.cpp | 38 +++++++++++++++++++ .../car_dealer_util/source/Data/excel/excel.h | 17 +++++++-- 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/code/cpp/car_dealer_util/source/Data/DataManipulation/Excel/LoadFromExcel.cpp b/code/cpp/car_dealer_util/source/Data/DataManipulation/Excel/LoadFromExcel.cpp index 849f4b5..31cb405 100644 --- a/code/cpp/car_dealer_util/source/Data/DataManipulation/Excel/LoadFromExcel.cpp +++ b/code/cpp/car_dealer_util/source/Data/DataManipulation/Excel/LoadFromExcel.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include "LoadFromExcel.h" #include "../../excel/excel.h" @@ -1072,7 +1072,7 @@ void LoadNewRepairMonitorReportFromXlsx( const std::wstring & * \param pszCaptionFormat * \return ************************************************/ -bool checkExcelFileFormat( Book * pBook, int sheetIndex, int captionRowIndex, const wchar_t * pszCaptionFormat[], int captionCount ) +/*bool checkExcelFileFormat( Book * pBook, int sheetIndex, int captionRowIndex, const wchar_t * pszCaptionFormat[], int captionCount ) { if ( pBook == nullptr ) { @@ -1103,4 +1103,4 @@ bool checkExcelFileFormat( Book * pBook, int sheetIndex, int captionRowIndex, co } return isEqual; -} +}*/ diff --git a/code/cpp/car_dealer_util/source/Data/excel/excel.cpp b/code/cpp/car_dealer_util/source/Data/excel/excel.cpp index 7f5ff3c..3247a7a 100644 --- a/code/cpp/car_dealer_util/source/Data/excel/excel.cpp +++ b/code/cpp/car_dealer_util/source/Data/excel/excel.cpp @@ -163,3 +163,41 @@ libxl::Sheet * getXlsxSheetByName( libxl::IBookT * pBook, const std::ws return pSheet; } + + +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; +} \ No newline at end of file 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 971dd72..7b43ec0 100644 --- a/code/cpp/car_dealer_util/source/Data/excel/excel.h +++ b/code/cpp/car_dealer_util/source/Data/excel/excel.h @@ -1,6 +1,4 @@ #pragma once -#ifndef EXCEL_H_ -#define EXCEL_H_ #include @@ -33,5 +31,18 @@ std::wstring ReadCellStringFromXlsx( libxl::IBookT * pBook, ************************************************/ libxl::Sheet * getXlsxSheetByName( libxl::IBookT * pBook, const std::wstring & sheetName ); +/************************************************ +* \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 ); -#endif