void CVcardView::OnExportVcf() { // TODO: Add your command handler code here CVcardDoc* pDoc = GetDocument(); //获取文档对象指针,通过该指针来访问文档类的成员 CString file_name = pDoc->file_path; //获取文件名 CStdioFile txt_file; //以文本模式打开txt文件,默认是以二进制模式打开 //以二进制打开读取时换行是0D 0A两个字符 //此时程序中的换行和文本中比较会出现问题,程序中的是0A //设置读取模式只能是CFile的派生类(CStdioFile)使用 //要不然设置成文本模式程序会崩溃 if (txt_file.Open(file_name, CStdioFile::modeRead|CStdioFile::typeText) == 0) { AfxMessageBox("打开文件失败"); return; } ////////////////////////////vcf文件固定格式////////////////////////////// const char* vcard_head = "BEGIN:VCARD\nVERSION:2.1\n"; const char* vcard_end = "END:VCARD\n"; const char* name_title = "N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:;"; const char* end_name = ";;;"; const char* f_name_title = "FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:"; const char* mobile_number_title = "TEL;CELL:"; const char* home_number_title = "TEL;HOME:"; ////////////////////////////////////////////////////////////////////////// char name[512] = {"\0"}; //姓名 char mobile_number[64] = {"\0"}; //移动电话 char home_number[64] = {"\0"}; //可以存移动短号 char* vcard_text = new char[MAX_SIZE]; // 一个vcard文本 char* line = new char[MAX_SIZE]; //文本中一行 memset(line, 0, MAX_SIZE); CFileDialog vcard_dlg(FALSE, "vcf", file_name); vcard_dlg.m_ofn.lpstrFilter = "vcf files(*.vcf)|*.vcf||"; vcard_dlg.m_ofn.lpstrTitle = "导出成vcf文件"; if (vcard_dlg.DoModal() == IDOK) { CFile vcf_file; if (vcf_file.Open(vcard_dlg.GetFileName(), CFile::modeWrite|CFile::modeCreate) == 0) { AfxMessageBox("转换失败"); return; } while (txt_file.ReadString(line, MAX_SIZE)) //读取文件每一行 { if (strlen(line) < 10) continue; if (!GetNameAndNumber(name, mobile_number, home_number, line)) continue; //把name转换成utf-8,然后使用=EE=FF=EE取16进制进行编码 GBToUTF8(name, name, strlen(name) * 3 / 2 + 1); UTFToHex(name); // 组成 一个vcard文本 sprintf(vcard_text, "%s%s%s%s\n%s%s\n%s%s\n%s%s\n%s", vcard_head, name_title, name, end_name, f_name_title, name, mobile_number_title, mobile_number, home_number_title, home_number, vcard_end); vcf_file.Write(vcard_text, strlen(vcard_text)); //转换后的记录写入文件 } delete[] line; delete[] vcard_text; txt_file.Close(); vcf_file.Close(); AfxMessageBox("转换成功"); } }
bool init_excel_file(const char* excel_name, std::vector<item_attire_data>& items) { char* names[] = {"ºï", "ÍÃ", "ÐÜ", "Áú"}; for(int i =0; i< sizeof(names)/sizeof(names[0]); i++) { std::map<int, CString> column_names; CSpreadSheet ss(excel_name, names[i]); for(int i = 1; i<= ss.GetTotalColumns(); i++) { CString name; ss.ReadCell(name, i, 1); column_names[i] = name; } for(int i = 2; i<= ss.GetTotalRows(); i++) { item_attire_data data; for(int j = 1; j< ss.GetTotalColumns(); j++) { CString value; ss.ReadCell(value, j, i); if( column_names[j] == "Item ID" && value != "") { data.id = atoi(value); continue; } //ss.ReadCell(value, "Item ID", i); if( column_names[j] == "Name" && value != "") { std::string utf_str = GBToUTF8(value.GetBuffer(0)); //strcpy(data.name, value.GetBuffer(0)); strcpy(data.name, utf_str.c_str()); continue; } //ss.ReadCell(value, "Name", i); if( column_names[j] == "DropLv" && value != "") { data.droplv = atoi(value); continue; } //ss.ReadCell(value, "DropLv", i); if( column_names[j] == "QualityLevel" && value != "") { data.quality_level = atoi(value); continue; } //ss.ReadCell(value, "QualityLevel", i); if( column_names[j] == "EquipPart" && value != "") { data.equip_part = atoi(value); continue; } //ss.ReadCell(value, "EquipPart", i); if( column_names[j] == "Price" && value != "") { data.price = atoi(value); continue; } //ss.ReadCell(value, "Price", i); if( column_names[j] == "SellPrice" && value != "") { data.sell_price = atoi(value); continue; } //ss.ReadCell(value, "SellPrice", i); if( column_names[j] == "RepairPrice" && value != "") { data.repair_price = atoi(value); continue; } //ss.ReadCell(value, "RepairPrice", i); if( column_names[j] == "UseLv" && value != "") { data.uselv = atoi(value); continue; } //ss.ReadCell(value, "UseLv", i); if( column_names[j] == "Strength" && value != "") { data.strength = atoi(value); continue; } //ss.ReadCell(value, "Strength", i); if( column_names[j] == "BodyQuality" && value != "") { data.body_quality = atoi(value); continue; } //ss.ReadCell(value, "BodyQuality", i); if( column_names[j] == "Stamina" && value != "") { data.stamina = atoi(value); continue; } //ss.ReadCell(value, "Stamina", i); if( column_names[j] == "Atk" && value != "") { strcpy(data.atk, value.GetBuffer(0)); continue; } //ss.ReadCell(value, "Atk", i); if( column_names[j] == "Def" && value != "") { data.def = atoi(value); continue; } //ss.ReadCell(value, "Def", i); if( column_names[j] == "Duration" && value != "") { data.duration = atoi(value); continue; } //ss.ReadCell(value, "Duration", i); if( column_names[j] == "Hit" && value != "") { data.hit = atoi(value); continue; } //ss.ReadCell(value, "Hit", i); if( column_names[j] == "Dodge" && value != "") { data.dodge = atoi(value); continue; } //ss.ReadCell(value, "Dodge", i); if( column_names[j] == "Crit" && value != "") { data.crit = atoi(value); continue; } //ss.ReadCell(value, "Crit", i); if( column_names[j] == "Hp" && value != "") { data.hp = atoi(value); continue; } //ss.ReadCell(value, "Hp", i); if( column_names[j] == "Mp" && value != "") { data.mp = atoi(value); continue; } //ss.ReadCell(value, "Mp", i); if( column_names[j] == "AddHp" && value != "") { data.add_hp = atoi(value); continue; } //ss.ReadCell(value, "AddHp", i); if( column_names[j] == "AddMp" && value != "") { data.add_mp = atoi(value); continue; } //ss.ReadCell(value, "AddMp", i); if( column_names[j] == "Slot" && value != "") { data.slot = atoi(value); continue; } //ss.ReadCell(value, "Slot", i); if( column_names[j] == "Tradability" && value != "") { data.trade_ability = atoi(value); continue; } //ss.ReadCell(value, "Tradability", i); if( column_names[j] == "VipTradability" && value != "") { data.vip_trade_ability = atoi(value); continue; } //ss.ReadCell(value, "VipTradability", i); if( column_names[j] == "Tradable" && value != "") { data.trade_able = atoi(value); continue; } //ss.ReadCell(value, "Tradable", i); if( column_names[j] == "SetID" && value != "") { data.setid = atoi(value); continue; } //ss.ReadCell(value, "SetID", i); if( column_names[j] == "DailyId" && value != "") { data.dailyid = atoi(value); continue; } //ss.ReadCell(value, "DailyId", i); if( column_names[j] == "ExploitValue" && value != "") { data.exploit_value = atoi(value); continue; } //ss.ReadCell(value, "ExploitValue", i); if( column_names[j] == "honorLevel" && value != "") { data.honor_level = atoi(value); continue; } //ss.ReadCell(value, "honorLevel", i); if( column_names[j] == "VipOnly" && value != "") { data.vip_only = atoi(value); continue; } //ss.ReadCell(value, "VipOnly", i); if( column_names[j] == "decompose" && value != "") { data.decompose = atoi(value); continue; } //ss.ReadCell(value, "decompose", i); if( column_names[j] == "Shop" && value != "") { data.shop = atoi(value); continue; } //ss.ReadCell(value, "Shop", i); if( column_names[j] == "UnStorage" && value != "") { data.un_storage = atoi(value); continue; } //ss.ReadCell(value, "UnStorage", i); if( column_names[j] == "resID" && value != "") { data.res_id = atoi(value); continue; } //ss.ReadCell(value, "resID", i); if( column_names[j] == "LifeTime" && value != "") { data.life_time = atoi(value); continue; } //ss.ReadCell(value, "LifeTime", i); if( column_names[j] == "descript" && value != "") { string utf_str = GBToUTF8( value.GetBuffer(0)); strcpy(data.descipt, utf_str.c_str()); continue; } //ss.ReadCell(value, "descript", i); continue; // }//for if(data.id == 0) { continue; } items.push_back(data); } } return true; }