#pragma warning (disable: 4996) #pragma warning (disable: 4819) #pragma warning (disable: 4995) #include #include "epm_handler_common.h" #include #include #include #include #include #include #include #include "ps/ps.h"; #include "ps/vrule.h" #include "sstream" #include #include "epm/epm.h" #include "sa/sa.h" #include "libxl.h" #include #include "epm/signoff.h" #include #include #include #include #include "ae/dataset.h" #include #include #include #include #include #include #include #include #include #include // #include "hx_custom.h" // #include "jk_custom.h" #include "util.h" void get_current_time(char *date_time) { time_t the_time; struct tm *time_ptr; char *time_format = "%Y-%m-%d %H-%M-%S "; the_time = time((time_t *)0); time_ptr = localtime(&the_time); strftime(date_time, 128, time_format, time_ptr); } // 把char *转换为TCHAR *或WCHAR * TCHAR convertTemp3[256] = { 0 }; TCHAR convertTemp4[256] = { 0 }; bool convertBufferSwitch2(false); TCHAR* Char2Tchar(const char* str, int len) { #ifdef _UNICODE TCHAR* temp = convertBufferSwitch2 ? convertTemp3 : convertTemp4; convertBufferSwitch2 = !convertBufferSwitch2; memset(temp, 0, sizeof(convertTemp3)); MultiByteToWideChar(CP_UTF8, 0, str, len, temp, 256); return temp; #else return str; #endif } int create_dataset(char *type_name, const char *name, tag_t excelTag) { // cout<<"添加命名引用------------------"<setKey(L"Halil Kural", L"windows-2723210a07c4e90162b26966a8jcdboe");//如果购买了该库,则设置相应的key,若没有购买,则不用这行 // book->setKey(L"TommoT", L"windows-2421220b07c2e10a6eb96768a2p7r6gc");//新版 int n_refs = 0; tag_t* refs = NULL; ifail = AE_ask_all_dataset_named_refs(excelTag, "excel", &n_refs, &refs); if (ifail != ITK_ok) { /* your error logic here */ } char current_date_time_str[128 + 1] = { "\0" }; get_current_time(current_date_time_str); string time_now = current_date_time_str; string sGuid = GenerateGuid(); string datasetName = time_now; datasetName = datasetName.append(sGuid); datasetName = datasetName.append(".xls"); time_now = getenv("temp"); time_now = time_now.append("\\").append(datasetName); cout << "文件路径----------" << time_now << endl; cout << "-------1----------" << endl; ifail = AE_export_named_ref(excelTag, "excel", time_now.c_str()); cout << "--------2---------" << endl; if (ifail != ITK_ok) { /* your error logic here */ } //检查是否存在单元格名称为“xxxx” wstringstream excel_path; // excel_path<<"C:\\TEMP\\export_text.xls"; excel_path << time_now.c_str(); cout << "--------3---------" << endl; libxl::Sheet* sheet = NULL; cout << "---------4--------" << endl; if (book->load(excel_path.str().c_str())) { sheet = book->getSheet(0);//获得第1个sheet页 } cout << "--------5---------" << endl; //写到表格中 TCHAR array2[100]; cout << "---------6--------" << endl; cout << "---------page--------" <writeStr(21, 6, array2); MultiByteToWideChar(CP_ACP, 0, zt2_DesignTime, -1, array2, 100); sheet->writeStr(22, 6, array2); MultiByteToWideChar(CP_ACP, 0, zt2_Proofread, -1, array2, 100); sheet->writeStr(21, 9, array2); MultiByteToWideChar(CP_ACP, 0, zt2_ProofreadTime, -1, array2, 100); sheet->writeStr(22, 9, array2); MultiByteToWideChar(CP_ACP, 0, zt2_Normalization, -1, array2, 100); sheet->writeStr(21, 10, array2); MultiByteToWideChar(CP_ACP, 0, zt2_NormalizationTime, -1, array2, 100); sheet->writeStr(22, 10, array2); MultiByteToWideChar(CP_ACP, 0, zt2_Review, -1, array2, 100); sheet->writeStr(21, 12, array2); MultiByteToWideChar(CP_ACP, 0, zt2_ReviewTime, -1, array2, 100); sheet->writeStr(22, 12, array2); MultiByteToWideChar(CP_ACP, 0, zt2_Approve, -1, array2, 100); sheet->writeStr(21, 14, array2); MultiByteToWideChar(CP_ACP, 0, zt2_ApproveTime, -1, array2, 100); sheet->writeStr(22, 14, array2); } cout << "-------7----------" << endl; for (int i = 0; i0--------" << endl; MultiByteToWideChar(CP_ACP, 0, zt2_Design, -1, array2, 100); sheet->writeStr(i * 23 + 21, 6, array2); MultiByteToWideChar(CP_ACP, 0, zt2_DesignTime, -1, array2, 100); sheet->writeStr(i * 23 + 22, 6, array2); MultiByteToWideChar(CP_ACP, 0, zt2_Proofread, -1, array2, 100); sheet->writeStr(i * 23 + 21, 9, array2); MultiByteToWideChar(CP_ACP, 0, zt2_ProofreadTime, -1, array2, 100); sheet->writeStr(i * 23 + 22, 9, array2); MultiByteToWideChar(CP_ACP, 0, zt2_Normalization, -1, array2, 100); sheet->writeStr(i * 23 + 21, 10, array2); MultiByteToWideChar(CP_ACP, 0, zt2_NormalizationTime, -1, array2, 100); sheet->writeStr(i * 23 + 22, 10, array2); MultiByteToWideChar(CP_ACP, 0, zt2_Review, -1, array2, 100); sheet->writeStr(i * 23 + 21, 12, array2); MultiByteToWideChar(CP_ACP, 0, zt2_ReviewTime, -1, array2, 100); sheet->writeStr(i * 23 + 22, 12, array2); MultiByteToWideChar(CP_ACP, 0, zt2_Approve, -1, array2, 100); sheet->writeStr(i * 23 + 21, 14, array2); MultiByteToWideChar(CP_ACP, 0, zt2_ApproveTime, -1, array2, 100); sheet->writeStr(i * 23 + 22, 14, array2); } cout << "---------8--------" << endl; if (book->save(excel_path.str().c_str()))//保存到example.xls { //..... } else { std::cout << book->errorMessage() << std::endl; } book->release();//释放对象!!!! //创建数据集,挂到版本的规范关系下 cout << "---------9--------" << endl; create_dataset("MSExcel", datasetName.c_str(), excelTag);//数据集类型(object_type),数据集名称,版本 return 0; } wstring StringToWString(const string s) { setlocale(LC_ALL, "chs"); const char* _Source = s.c_str(); size_t _Dsize = s.size() + 1; wchar_t *_Dest = new wchar_t[_Dsize]; wmemset(_Dest, 0, _Dsize); mbstowcs(_Dest, _Source, _Dsize); wstring result = _Dest; delete[]_Dest; setlocale(LC_ALL, "C"); return result; } wchar_t* c2w(const char *str) { int length = strlen(str) + 1; wchar_t *t = (wchar_t*)malloc(sizeof(wchar_t)*length); memset(t, 0, length*sizeof(wchar_t)); MultiByteToWideChar(CP_ACP, 0, str, strlen(str), t, length); return t; } //读取excel单元格内容 string get_excel_data(libxl::Sheet *sheet, int row, int col) { string result; double temp; try { libxl::CellType cell_type = sheet->cellType(row, col); switch (cell_type) { case libxl::CELLTYPE_STRING: result = WStringToString(sheet->readStr(row, col)); break; case libxl::CELLTYPE_BLANK: result = ""; break; case libxl::CELLTYPE_EMPTY: result = ""; break; case libxl::CELLTYPE_NUMBER: temp = sheet->readNum(row, col); result = temp == (int)temp ? to_string((int)temp) : to_string(temp); break; case libxl::CELLTYPE_BOOLEAN: result = to_string(sheet->readBool(row, col)); break; case libxl::CELLTYPE_ERROR: result = ""; break; } } catch (exception e) { // LERROR<<"col num"<setKey(L"Halil Kural", L"windows-2723210a07c4e90162b26966a8jcdboe");//如果购买了该库,则设置相应的key,若没有购买,则不用这行 // book->setKey(L"TommoT", L"windows-2421220b07c2e10a6eb96768a2p7r6gc");//新版 int n_refs = 0; tag_t* refs = NULL; ifail = AE_ask_all_dataset_named_refs(excelTag, "excel", &n_refs, &refs); if (ifail != ITK_ok) { /* your error logic here */ } char current_date_time_str[128 + 1] = { "\0" }; get_current_time(current_date_time_str); string time_now = current_date_time_str; string sGuid = GenerateGuid(); string datasetName = time_now; datasetName = datasetName.append(sGuid); datasetName = datasetName.append(".xls"); time_now = getenv("temp"); time_now = time_now.append("\\").append(datasetName); cout << "文件路径----------" << time_now << endl; cout << "-------1----------" << endl; ifail = AE_export_named_ref(excelTag, "excel", time_now.c_str()); cout << "--------2---------" << endl; if (ifail != ITK_ok) { /* your error logic here */ } //检查是否存在单元格名称为“xxxx” wstringstream excel_path; // excel_path<<"C:\\TEMP\\export_text.xls"; excel_path << time_now.c_str(); cout << "--------3---------" << endl; libxl::Sheet* sheet = NULL; cout << "---------4--------" << endl; if (book->load(excel_path.str().c_str())) { sheet = book->getSheet(0);//获得第1个sheet页 cout << "--------读取到excel---------" << endl; if (sheet) { cout << "--------读取到sheet0---------" << endl; } else { cout << "--------未读取到sheet0---------" << endl; } } else { cout << "--------未读取到excel--------" << endl; } cout << "--------5---------" << endl; //写到表格中 TCHAR array2[100]; cout << "---------6--------" << endl; if (page == 0) { cout << "---------page=0--------" << endl; //编制 MultiByteToWideChar(CP_ACP, 0, zt2_Design, -1, array2, 100); ITKCALL(sheet->writeStr(23, 9, array2)); MultiByteToWideChar(CP_ACP, 0, zt2_DesignTime, -1, array2, 100); ITKCALL(sheet->writeStr(24, 9, array2)); //校对 MultiByteToWideChar(CP_ACP, 0, zt2_Proofread, -1, array2, 100); ITKCALL(sheet->writeStr(23, 10, array2)); MultiByteToWideChar(CP_ACP, 0, zt2_ProofreadTime, -1, array2, 100); ITKCALL(sheet->writeStr(24, 10, array2)); //工艺 MultiByteToWideChar(CP_ACP, 0, zt2_Technology, -1, array2, 100); ITKCALL(sheet->writeStr(23, 12, array2)); MultiByteToWideChar(CP_ACP, 0, zt2_TechnologyTime, -1, array2, 100); ITKCALL(sheet->writeStr(24, 12, array2)); //审定 MultiByteToWideChar(CP_ACP, 0, zt2_Review, -1, array2, 100); ITKCALL(sheet->writeStr(23, 14, array2)); MultiByteToWideChar(CP_ACP, 0, zt2_ReviewTime, -1, array2, 100); ITKCALL(sheet->writeStr(24, 14, array2)); } cout << "-------7----------" << endl; int rowNum = sheet->lastRow(); int colNum = sheet->lastCol(); cout << "lastRow:" << rowNum << endl; cout << "lastCol:" << colNum << endl; for (int i = 0; i0--------" << endl; MultiByteToWideChar(CP_ACP, 0, "编制测试", -1, array2, 100); sheet->writeStr(i * 24 + 23, 9, array2); MultiByteToWideChar(CP_ACP, 0, zt2_DesignTime, -1, array2, 100); sheet->writeStr(i * 24 + 24, 9, array2); MultiByteToWideChar(CP_ACP, 0, "校对测试", -1, array2, 100); sheet->writeStr(i * 24 + 23, 10, array2); MultiByteToWideChar(CP_ACP, 0, zt2_ProofreadTime, -1, array2, 100); sheet->writeStr(i * 24 + 24, 10, array2); MultiByteToWideChar(CP_ACP, 0, "工艺测试", -1, array2, 100); sheet->writeStr(i * 24 + 24, 12, array2); MultiByteToWideChar(CP_ACP, 0, zt2_NormalizationTime, -1, array2, 100); sheet->writeStr(i * 24 + 24, 12, array2); MultiByteToWideChar(CP_ACP, 0, "审定测试", -1, array2, 100); sheet->writeStr(i * 24 + 23, 14, array2); MultiByteToWideChar(CP_ACP, 0, zt2_ReviewTime, -1, array2, 100); sheet->writeStr(i * 24 + 24, 14, array2); } cout << "---------8--------" << endl; if (book->save(excel_path.str().c_str()))//保存到example.xls { //..... } else { std::cout << book->errorMessage() << std::endl; } book->release();//释放对象!!!! //创建数据集,挂到版本的规范关系下 cout << "---------9--------" << endl; create_dataset("MSExcel", datasetName.c_str(), excelTag);//数据集类型(object_type),数据集名称,版本 cout << "writeToExcel2 end" << endl; return 0; } int chintSignChange(tag_t task) { cout << "chintSignChange start" << endl; //20200113 POM_AM__set_application_bypass(true); EPM_decision_t decision = EPM_go; int ifail = ITK_ok, arg_cnt = 0, i = 0, att_cnt = 0; //获取根流程节点 int reference_count = 0; tag_t * reference_attachment = NULLTAG; map rev_map; char *zt2_Design = NULL; char *zt2_DesignTime = NULL; char *zt2_Proofread = NULL; char *zt2_ProofreadTime = NULL; char *zt2_Normalization = NULL; char *zt2_NormalizationTime = NULL; char *zt2_Review = NULL; char *zt2_ReviewTime = NULL; char *zt2_Approve = NULL; char *zt2_ApproveTime = NULL; char *zt2_Technology = NULL; char *zt2_TechnologyTime = NULL; int eCount = 0; tag_t *eTag = NULLTAG; // vector.clear();//清空所有元素 //循环目标对象 tag_t targetTag = task; //如果是版本类型的就查找上层 char * object_type = NULL; ITKCALL(ifail = AOM_ask_value_string(targetTag, "object_type", &object_type)); cout << i << "--object_type:" << object_type << endl; if (strstr(object_type, "ZT2_Change") != NULL) { //获取对象的上签名属性 AOM_ask_value_string(targetTag, "zt2_Design", &zt2_Design); AOM_ask_value_string(targetTag, "zt2_DesignTime", &zt2_DesignTime); AOM_ask_value_string(targetTag, "zt2_Proofread", &zt2_Proofread); AOM_ask_value_string(targetTag, "zt2_ProofreadTime", &zt2_ProofreadTime); AOM_ask_value_string(targetTag, "zt2_Normalization", &zt2_Normalization); AOM_ask_value_string(targetTag, "zt2_NormalizationTime", &zt2_NormalizationTime); AOM_ask_value_string(targetTag, "zt2_Review", &zt2_Review); AOM_ask_value_string(targetTag, "zt2_ReviewTime", &zt2_ReviewTime); AOM_ask_value_string(targetTag, "zt2_Approve", &zt2_Approve); AOM_ask_value_string(targetTag, "zt2_ApproveTime", &zt2_ApproveTime); //获取对象的数据集 AOM_ask_value_tags(targetTag, "IMAN_reference", &eCount, &eTag); for (int j = 0; j0) { page = delivery + 1; } else { page = delivery; } writeToExcel(page, eTag[j], zt2_Design, zt2_DesignTime, zt2_Proofread, zt2_ProofreadTime, zt2_Normalization, zt2_NormalizationTime, zt2_Review, zt2_ReviewTime, zt2_Approve, zt2_ApproveTime); if (values != NULL) { for (int t = 0; t