|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <QStringList>
|
|
|
|
|
#include "Defines.h"
|
|
|
|
|
|
|
|
|
|
#include "iFileEngine_global.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 文件类型
|
|
|
|
|
enum FileEngineType
|
|
|
|
|
{
|
|
|
|
|
FET_Text = 0, //文本
|
|
|
|
|
FET_Dat, //Dat
|
|
|
|
|
FET_Excel, //Excel
|
|
|
|
|
FET_Ini, //Ini
|
|
|
|
|
FET_SQLite, //Sqlite
|
|
|
|
|
FET_Clipboard, //Clipboard
|
|
|
|
|
FET_Unknown //Unknown
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// FileEngine
|
|
|
|
|
class I_FILE_ENGINE_EXPORT iFileEngine
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
iFileEngine();
|
|
|
|
|
~iFileEngine();
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
// 加载接口
|
|
|
|
|
virtual bool load(VVecVariant& vvecData, QString sFile);
|
|
|
|
|
|
|
|
|
|
// 设置头包含多少行数据
|
|
|
|
|
void setDataRowCountPreviewed(int n);
|
|
|
|
|
|
|
|
|
|
// 顶部文件说明信息
|
|
|
|
|
QString getHeaders();
|
|
|
|
|
|
|
|
|
|
// 顶部单位和标题
|
|
|
|
|
QStringList getTitles();
|
|
|
|
|
QStringList getUnits();
|
|
|
|
|
|
|
|
|
|
// 错误信息
|
|
|
|
|
QString getLastError();
|
|
|
|
|
|
|
|
|
|
// 是否采用编码转换
|
|
|
|
|
void setCodecUsingMode(bool bUse);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
// 初始化参数
|
|
|
|
|
virtual void init();
|
|
|
|
|
|
|
|
|
|
// 解析文件头
|
|
|
|
|
virtual bool tryParse(QString sFile);
|
|
|
|
|
|
|
|
|
|
// 利用倒回两行,try查找标题单位
|
|
|
|
|
virtual bool tryParseTitleUnit(QString s);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
QString m_sError; //存错误信息
|
|
|
|
|
QString m_sHeaders; //顶部文件说明信息
|
|
|
|
|
QStringList m_listTitles; //顶部单位和标题
|
|
|
|
|
QStringList m_listUnits;
|
|
|
|
|
|
|
|
|
|
int m_nLineIndexValue; //数据起始行
|
|
|
|
|
int m_nLineIndexTitle;
|
|
|
|
|
int m_nLineIndexUnit;
|
|
|
|
|
|
|
|
|
|
int m_nDataRowCountPreviewed;//头包含多少行数据,默认为2,外界可传入
|
|
|
|
|
int m_nDataLineTryMax; //在try时数据多少条即可认为是数据,默认为3
|
|
|
|
|
|
|
|
|
|
// 是否采用编码转换
|
|
|
|
|
bool m_bUsingCodecMode;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// iFileEngineUtils
|
|
|
|
|
class I_FILE_ENGINE_EXPORT iFileEngineUtils
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
// 统一加载接口
|
|
|
|
|
// 如果不传入 oType 则根据文件后缀,自动识别
|
|
|
|
|
static bool load(VVecVariant& vvecData,
|
|
|
|
|
QString& sHeaders,
|
|
|
|
|
QString sFile,
|
|
|
|
|
FileEngineType oType = FET_Unknown,
|
|
|
|
|
QString sExt = "",//如sheetName
|
|
|
|
|
QString* szError = NULL);
|
|
|
|
|
|
|
|
|
|
// 统一加载接口
|
|
|
|
|
// 如果不传入 oType 则根据文件后缀,自动识别
|
|
|
|
|
static bool loadEx(VVecVariant& vvecData,
|
|
|
|
|
QString& sHeaders,
|
|
|
|
|
QStringList& listTitles,
|
|
|
|
|
QStringList& listUnits,
|
|
|
|
|
QString sFile,
|
|
|
|
|
FileEngineType oType = FET_Unknown,
|
|
|
|
|
QString sExt = "",//如sheetName
|
|
|
|
|
bool bUseCodec = true, //启用Codec转换
|
|
|
|
|
QString* szError = NULL);
|
|
|
|
|
|
|
|
|
|
};
|