Compare commits

...

3 Commits

Author SHA1 Message Date
Kane Wang 5765a4b411 修改导入转介绍推荐信息表的导入函数,以适应用户。 2021-07-05 09:33:43 +08:00
Kane Wang 6406fe1784 ... 2021-06-15 17:41:20 +08:00
Kane Wang dc162b3180 做了一点点重构 2021-06-15 11:42:42 +08:00
5 changed files with 142 additions and 20 deletions

View File

@ -1,4 +1,4 @@
#include <libxl.h>
#include <libxl.h>
#include <stdexcept>
#include "LoadFromExcel.h"
#include "../../excel/excel.h"
@ -76,10 +76,14 @@ const wchar_t * pwszRepairRecommandationCaption[] = {
L"报案号",
L"推荐车商代码",
L"推荐车商名称",
L"机构",
L"出险日期",
L"车牌号",
L"品牌名称",
L"短信类型",
L"接收人"
L"手机号"
L"短信内容"
L"发送时间",
L"数据来源",
};
@ -784,18 +788,18 @@ void LoadRepairRecommandationFromXlsx( const std::wstring &
//起始列索引
int colunmIndex = pSheet->firstCol();
wstring branchName = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
wstring orderNo = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
wstring orderType = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
wstring notifyNo = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
wstring RecommandCarDealerCode = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
wstring RecommandCarDealerName = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
wstring damageDate = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
wstring plateNumber = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
wstring brandName = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
wstring messageType = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
wstring messageSendingDate = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
wstring dataSource = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex++, true );
wstring branchName = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex, true );
wstring orderNo = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex+1, true );
wstring orderType = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex+2, true );
wstring notifyNo = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex+3, true );
wstring RecommandCarDealerCode = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex+4, true );
wstring RecommandCarDealerName = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex+5, true );
wstring damageDate = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex+7, true );
wstring plateNumber = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex+8, true );
wstring brandName = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex+9, true );
wstring messageType = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex+10, true );
wstring messageSendingDate = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex+14, true );
wstring dataSource = ReadCellStringFromXlsx( pBook, sheetIndex, rowIndex, colunmIndex+15, true );
//空行跳过
if ( notifyNo.empty() == true )
@ -1072,7 +1076,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 +1107,4 @@ bool checkExcelFileFormat( Book * pBook, int sheetIndex, int captionRowIndex, co
}
return isEqual;
}
}*/

View File

@ -163,3 +163,41 @@ libxl::Sheet * getXlsxSheetByName( libxl::IBookT<wchar_t> * 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;
}

View File

@ -1,6 +1,4 @@
#pragma once
#ifndef EXCEL_H_
#define EXCEL_H_
#include <libxl.h>
@ -31,7 +29,20 @@ 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 );
#endif
/************************************************
* \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 );

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);