• libxl 的使用,读取时间格式


    最近开发使用到 libxl,用的是3.8.0 破解版。

    具体过程:

    1、将lib.dll放在exe同目录下,在代码中引用 libxl.lib

      #pragma comment(lib, ".\Lib\libxl.lib")
    

    2、包含头文件 libxl.h

    3、实例

    //m_strFilePath为excel文件的完整路径
    CString ext = ::PathFindExtension(m_strFilePath);
    	if(ext.CompareNoCase(L".xlsx") == 0)
    		book = xlCreateXMLBook();  //针对.xlsx
    	else
    		book = xlCreateBook();  //针对.xls
    
    	if(!book)
    	{
    		return;
    	}
    
    	const wchar_t * x = L"Halil Kural";
    	const wchar_t * y = L"windows-2723210a07c4e90162b26966a8jcdboe";
    	book->setKey(x, y);  //设置key,即破解^_^
    
    	if(!book->load(m_strFilePath))
    	{
    		return;
    	}
    
    	int sheetCount = book->sheetCount(); //工作表总数量
    	for (int index = 0; index < sheetCount; ++index)
    	{
    		Sheet *sheet =book->getSheet(index++);
    		if(!sheet)
    			continue;
    		int firstRow = sheet->firstRow(); //有数据的第一行行号
    		int lastRow = sheet->lastRow();  //有数据的最后一行行号
    		int firstCol = sheet->firstCol(); //有数据的第一列列号
    		int lastCol = sheet->lastCol();   //有数据的最后一列列号
    
    		//找出表头(测试数据)
    		map<int,wstring> mapColNames;
    		for(int c = firstCol; c < lastCol; ++c)
    		{
    			const wchar_t* str = sheet->readStr(firstRow, c);
    			if(!str)
    				continue;
    			mapColNames[c] = str;
    		}
    
    		//确定每个表头代表的意义(测试数据)
    		map<int,eFIELD> mapColTypes;
    		for (auto it = mapColNames.begin(); it != mapColNames.end(); ++it)
    		{
    			eFIELD e = GetFieldTypeByName(it->second.c_str());
    			mapColTypes[it->first] = e;
    		}
    
    		//逐行读取数据
    		for (int row = firstRow+1; row < lastRow; ++row)
    		{
    			for(int c = firstCol; c < lastCol; ++c)
    			{
                                            CString strValue;
                                            CellType t = sheet->cellType(row, c);
    					if(t == CELLTYPE_NUMBER)
    					{
    						double db = sheet->readNum(row, c);//test
    						LONG64 number = (LONG64)db;
    						if(number > 0)
    							strValue.Format(L"%I64d", number);
    					}
                                            else
                                                 const wchar_t* s = sheet->readStr(row, c); //读取内容 
    }          } }

      

    4、读取时间格式的数据

     1 CString strValue;
     2                 bool bDate = sheet->isDate(row, col);
     3                 if (bDate)
     4                 {
     5                     double db = sheet->readNum(row, col);
     6                     int year=0, month=0, day=0;
     7                     bool b = book->dateUnpack(db, &year, &month, &day);
     8 
     9     //将读取的时间 转换为时间戳
    10                     unsigned __int64 ftNow;
    11                     SYSTEMTIME time;
    12                     ZeroMemory(&time, sizeof(SYSTEMTIME)),
    13                     time.wYear = year;
    14                     time.wMonth = month;
    15                     time.wDay = day;
    16                     SystemTimeToFileTime(&time,(LPFILETIME)&ftNow);
    17                     __int64 timeStamp =  (__int64)((ftNow-0x019db1ded53e8000)/10000);//毫秒
    18                     strValue.Format(L"%I64d", timeStamp);
    19                 }    
  • 相关阅读:
    如何使 Postgresql 的psql 使用 中文提示信息
    Makfile中的 依赖关系
    防范计算机木马入侵反恶意联盟落户滨海 狼人:
    印度最大软件开发商塔塔咨询官网首页被黑 狼人:
    河北银行:用CDP保障业务系统的故障快速恢复 狼人:
    甲骨文11g数据库爆零日攻击 可完全攻破 狼人:
    Adobe Reader与IE 领衔漏洞榜 狼人:
    黑客藏毒于火狐插件 目标瞄准Windows系统 狼人:
    网络订票当心三类陷阱 最好当场识别真伪 狼人:
    微软基于云计算免费杀毒软件Morro曝光 狼人:
  • 原文地址:https://www.cnblogs.com/pjl1119/p/8059126.html
Copyright © 2020-2023  润新知