| | |
| | | wb.Dump(path); |
| | | } |
| | | |
| | | void ExcelUtil::read(string path) |
| | | std::list<ExcelGPCodeInfo> ExcelUtil::readGPCodes(string path) |
| | | { |
| | | |
| | | xlsWorkBook* pWB = NULL; |
| | | |
| | | // 工作表 |
| | | xlsWorkSheet* pWS = NULL; |
| | | // 单元格 |
| | | xlsCell* cell = NULL; |
| | | |
| | | |
| | | int sheetIndex; |
| | | int sheetIndex=0; |
| | | int row, col; |
| | | |
| | | // 打开文件 |
| | | pWB = xls_open(path.c_str(), "UTF-8"); |
| | | pWB = xls_open(path.c_str(), "GBK"); |
| | | if (!pWB) { |
| | | throw string("Open File Error!"); |
| | | } |
| | | // 解析xls文件,这个不要忘了 |
| | | xls_parseWorkBook(pWB); |
| | | |
| | | fprintf(stderr, "Sheet count:%d\n", pWB->sheets.count); |
| | | |
| | | pWS = xls_getWorkSheet(pWB, 0); |
| | | // 解析工作表 |
| | | xls_parseWorkSheet(pWS); |
| | | fprintf(stderr, "Sheet %d name: %s\n", sheetIndex, (char*)pWB->sheets.sheet[sheetIndex].name); |
| | | |
| | | fprintf(stderr, "Sheet Data:\n"); |
| | | // 单元格 |
| | | xlsCell* cell = NULL; |
| | | // 每行 |
| | | for (row = 0; row < pWS->rows.lastrow; ++row) { |
| | | cell = xls_cell(pWS, row, 1); |
| | | std::list<ExcelGPCodeInfo> codes; |
| | | for (row = 0; row <= pWS->rows.lastrow; ++row) { |
| | | ExcelGPCodeInfo info; |
| | | cell = xls_cell(pWS, row, 0); |
| | | if (cell && cell->str) { |
| | | fprintf(stderr, "%s", (char*)cell->str); |
| | | info.zyltgb = std::string((char*)cell->str); |
| | | |
| | | } |
| | | cell = xls_cell(pWS, row, 1); |
| | | if (cell && cell->str) { |
| | | fprintf(stderr, " %s\n", (char*)cell->str); |
| | | info.code = std::string((char*)cell->str); |
| | | } |
| | | codes.push_back(info); |
| | | } |
| | | |
| | | return codes; |
| | | } |
| | | |
| | |
| | | #include <afxstr.h> |
| | | #include <xls.h> |
| | | |
| | | struct ExcelGPCodeInfo |
| | | { |
| | | string zyltgb; |
| | | string code; |
| | | |
| | | }; |
| | | |
| | | class ExcelUtil |
| | | { |
| | | public: |
| | | static void save(list<TradeData> data, string path); |
| | | |
| | | static void read(string path); |
| | | static std::list<ExcelGPCodeInfo> readGPCodes(string path); |
| | | |
| | | }; |
| | | |
| | |
| | | return 0; |
| | | } |
| | | |
| | | |
| | | CString GUITool::selectExcel() { |
| | | |
| | | TCHAR szBuffer[MAX_PATH] = { 0 }; |
| | | OPENFILENAME ofn = { 0 }; |
| | | ofn.lStructSize = sizeof(ofn); |
| | | ofn.lpstrFilter = _T("All\0*.xls");//要选择的文件后缀 |
| | | ofn.nFilterIndex = 1; |
| | | ofn.lpstrFile = szBuffer;//存放文件的缓冲区 |
| | | ofn.nMaxFile = sizeof(szBuffer) / sizeof(*szBuffer); |
| | | ofn.nFilterIndex = 0; |
| | | ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; |
| | | BOOL bSel = GetOpenFileName(&ofn); |
| | | if (bSel) { |
| | | return szBuffer; |
| | | } |
| | | |
| | | |
| | | return 0; |
| | | } |
| | | |
| | | std::list<CString> GUITool::selectMulImages() { |
| | | std::list<CString> paths; |
| | | TCHAR szBuffer[MAX_PATH] = { 0 }; |
| | |
| | | |
| | | static CString selectImage(); |
| | | |
| | | static CString selectExcel(); |
| | | |
| | | static std::list<CString> selectMulImages(); |
| | | |
| | | }; |
| | |
| | | // Excel上传股票代码 |
| | | void CappDlg::OnBnClickedButtonUploadExcelCode() |
| | | { |
| | | CString cpath = GUITool::selectImage(); |
| | | std:string path = Tool::cstring2String(cpath); |
| | | CString cpath = GUITool::selectExcel(); |
| | | std:string path = Tool::cstring2String(cpath); |
| | | if (path.length() > 0) |
| | | { |
| | | ExcelUtil::read(path); |
| | | std::list<IndustryData> fresult; |
| | | list<ExcelGPCodeInfo> codesList = ExcelUtil::readGPCodes(path); |
| | | list<ExcelGPCodeInfo>::iterator ele; |
| | | for (ele = codesList.begin();ele != codesList.end();++ele) { |
| | | ExcelGPCodeInfo info= *ele; |
| | | IndustryData finfo; |
| | | if (info.code.length()>0) |
| | | { |
| | | |
| | | finfo.code = info.code.replace(0, 2, ""); |
| | | if (info.zyltgb.find("亿",0) > 0) { |
| | | finfo.zyltMoneyUnit = MONEY_UNIT_Y; |
| | | string zyltgb = info.zyltgb; |
| | | finfo.zyltMoney = zyltgb.substr(0, zyltgb.length()-2); |
| | | } |
| | | else if (info.zyltgb.find("万",0) > 0) { |
| | | finfo.zyltMoneyUnit = MONEY_UNIT_W; |
| | | string zyltgb = info.zyltgb; |
| | | finfo.zyltMoney = zyltgb.substr(0, zyltgb.length() - 2); |
| | | } |
| | | else { |
| | | finfo.zyltMoneyUnit = MONEY_UNIT_NO; |
| | | finfo.zyltMoney = info.zyltgb; |
| | | } |
| | | fresult.push_back(finfo); |
| | | } |
| | | } |
| | | codesDataDlog::codeData = fresult; |
| | | codesDataDlog::upload = TRUE; |
| | | codesDataDlog dlg; |
| | | dlg.DoModal(); |
| | | } |
| | | |
| | | |
| | |
| | | typedef uint32_t DWORD_UA; |
| | | #else |
| | | |
| | | |
| | | #ifdef _WIN32 |
| | | typedef __declspec(align(1)) uint16_t WORD_UA; |
| | | typedef __declspec(align(1)) uint32_t DWORD_UA; |
| | | #else |
| | | typedef uint16_t WORD_UA __attribute__((aligned(1))); // 2 bytes |
| | | typedef uint32_t DWORD_UA __attribute__((aligned(1))); // 4 bytes |
| | | typedef uint16_t WORD_UA __attribute__ ((aligned (1))); // 2 bytes |
| | | typedef uint32_t DWORD_UA __attribute__ ((aligned (1))); // 4 bytes |
| | | #endif |
| | | |
| | | #endif |
| | | #endif |