From 162311be680b94a0dcd5250acbf36aead6350cb1 Mon Sep 17 00:00:00 2001 From: wumu <mayi@mayi.com> Date: 星期三, 30 十月 2024 23:50:34 +0800 Subject: [PATCH] 1030 --- internal_system_v1/exporttofile.cpp | 205 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 203 insertions(+), 2 deletions(-) diff --git a/internal_system_v1/exporttofile.cpp b/internal_system_v1/exporttofile.cpp index 7e56b0f..b4b9a46 100644 --- a/internal_system_v1/exporttofile.cpp +++ b/internal_system_v1/exporttofile.cpp @@ -1,5 +1,10 @@ 锘�#include "exporttofile.h" +#include <QFileDialog> +#include <QDebug> +#include <QAxObject> +#include <QFile> +#pragma execution_character_set("utf-8") ExportToFile::ExportToFile(QObject *parent) : QObject(parent) { @@ -7,15 +12,211 @@ int ExportToFile::saveToExcelFromComInfo(ComInfo &info) { + // 璇诲彇褰撳墠鐩綍涓嬬殑妯℃澘鏂囦欢锛岀劧鍚庡線閲屽啓鏁版嵁锛屼慨鏀逛繚瀛� + +// QString savePath = QFileDialog::getExistingDirectory(nullptr,"閫夋嫨鏂囦欢澶�",QDir::currentPath()); +// qDebug()<<"savepath:"<<savePath; + + QString demoPath = QDir::currentPath()+"/Data/闄勪欢2_鍐呭缁�01琛╛鍗曚綅鍙婂唴閮ㄥ璁℃満鏋勫熀鏈儏鍐佃〃-1.301鐗坃demo.xls"; + QDir dir(demoPath); + if(!dir.exists()){ + demoPath = QDir::currentPath()+"/release/Data/闄勪欢2_鍐呭缁�01琛╛鍗曚綅鍙婂唴閮ㄥ璁℃満鏋勫熀鏈儏鍐佃〃-1.301鐗坃demo.xls"; + } + + QString savePath = QFileDialog::getSaveFileName(nullptr,"淇濆瓨鏂囦欢",QDir::currentPath()+"/鍐呭缁�01琛�.xls","Excel File(*.xls,*.xlsx)"); + qDebug()<<"savepath:"<<savePath <<endl << "demoPath:"<<demoPath; + + + + if(savePath.size() > 0){ + QAxObject excel("ket.Application"); + if(!excel.setControl("ket" + ".Application")){ // windows鍐呮牳 + excel.setControl("Excel.Application"); // wps鍐呮牳 + } + + excel.setProperty("Visible",false); + excel.setProperty("DisplayAlerts",false); + QAxObject * wbs = excel.querySubObject("WorkBooks"); + qDebug()<<"wbs:"<<wbs->className(); + QAxObject * wb = wbs->querySubObject("Open(QString&)",demoPath); + qDebug()<<"wb open ok"; + QAxObject * shs = wb->querySubObject("WorkSheets"); // WorkSheets 涔熷彲浠� + // 鑾峰彇鍏蜂綋琛ㄦ牸锛岃鍒� + QAxObject * sheet = shs->querySubObject("Item(int)", 1); // 绗竴涓〃 + QAxObject *usedRange = sheet->querySubObject("UsedRange"); + int rows = usedRange->querySubObject("Rows")->property("Count").toInt(); + int columns = usedRange->querySubObject("Columns")->property("Count").toInt(); + qDebug()<<"r--c:"<<rows<<columns; + + // 淇敼鏌愪釜鍊� + //sheet->querySubObject("Cells(int,int)", 1, 10)->dynamicCall("SetValue(const QString&)","1000200300"); +// QAxObject *cell1 = sheet->querySubObject("Range(QVariant, QVariant)", "D10"); +// qDebug()<<"B3鍘熸暟鎹細"<<cell1->dynamicCall("Value2()").toString(); +// /* ---- 淇敼鍗曚釜鍗曞厓鏍间腑鐨勬暟鎹� ---- */ +// cell1->setProperty("Value2", "21321321312"); +// qDebug()<<"B3淇敼鍚庣殑鏁版嵁锛�"<<cell1->dynamicCall("Value2()").toString(); + +// QAxObject *cell2 = sheet->querySubObject("Range(QVariant, QVariant)", "G63"); +// qDebug()<<"B3鍘熸暟鎹細"<<cell2->dynamicCall("Value2()").toString(); +// /* ---- 淇敼鍗曚釜鍗曞厓鏍间腑鐨勬暟鎹� ---- */ +// cell2->setProperty("Value2", "10"); +// qDebug()<<"G63淇敼鍚庣殑鏁版嵁锛�"<<cell2->dynamicCall("Value2()").toString(); + +// QAxObject *cell3 = sheet->querySubObject("Range(QVariant, QVariant)", "E57"); +// qDebug()<<"B3鍘熸暟鎹細"<<cell3->dynamicCall("Value2()").toString(); +// /* ---- 淇敼鍗曚釜鍗曞厓鏍间腑鐨勬暟鎹� ---- */ +// cell3->setProperty("Value2", "4 鍏朵粬"); +// qDebug()<<"E57淇敼鍚庣殑鏁版嵁锛�"<<cell3->dynamicCall("Value2()").toString(); + + // 渚濇璧嬪�� + // 鍩烘湰鎯呭喌 + sheet->querySubObject("Range(QVariant, QVariant)", "D10")->setProperty("Value2", info.creditCode); // 缁熶竴淇$敤浠g爜 + qDebug()<<1; + sheet->querySubObject("Range(QVariant, QVariant)", "I10")->setProperty("Value2", QString::fromLocal8Bit(info.name)); // 鍗曚綅鍚嶇О + qDebug()<<2; + sheet->querySubObject("Range(QVariant, QVariant)", "D13")->setProperty("Value2", QString::fromLocal8Bit(info.comType)); // 鏈烘瀯绫诲瀷 + qDebug()<<3; + sheet->querySubObject("Range(QVariant, QVariant)", "C19")->setProperty("Value2", QString::fromLocal8Bit(info.business)); // 涓氬姟娲诲姩 + qDebug()<<4; + sheet->querySubObject("Range(QVariant, QVariant)", "E20")->setProperty("Value2", info.businessCode); // 琛屼笟浠g爜 + qDebug()<<5; + sheet->querySubObject("Range(QVariant, QVariant)", "B22")->setProperty("Value2", QString::fromLocal8Bit(info.addr)); // 娉ㄥ唽鍦板強鍖哄垝 + qDebug()<<6; + sheet->querySubObject("Range(QVariant, QVariant)", "C25")->setProperty("Value2", info.areaCode); // 鍖哄煙浠g爜 + qDebug()<<7; + sheet->querySubObject("Range(QVariant, QVariant)", "G25")->setProperty("Value2", info.townCode); // 鍩庝埂浠g爜 + qDebug()<<8; + sheet->querySubObject("Range(QVariant, QVariant)", "C26")->setProperty("Value2", QString::fromLocal8Bit(info.scale)); // 鍗曚綅瑙勬ā + qDebug()<<9; + sheet->querySubObject("Range(QVariant, QVariant)", "G27")->setProperty("Value2", info.people); // 浠庝笟浜哄憳鏁伴噺 + qDebug()<<10; + sheet->querySubObject("Range(QVariant, QVariant)", "E28")->setProperty("Value2", QString::fromLocal8Bit(info.representative)); // 娉曚汉 + qDebug()<<11; + sheet->querySubObject("Range(QVariant, QVariant)", "I28")->setProperty("Value2", QString::fromLocal8Bit(info.standardType)); // 鎵ц浼氳鏍囧噯 + qDebug()<<12; + sheet->querySubObject("Range(QVariant, QVariant)", "C32")->setProperty("Value2", info.trunkCode); // 闀块�斿尯鍙� + qDebug()<<13; + sheet->querySubObject("Range(QVariant, QVariant)", "C33")->setProperty("Value2", info.fixedTel); // 鍥哄畾鐢佃瘽 + qDebug()<<14; + sheet->querySubObject("Range(QVariant, QVariant)", "C34")->setProperty("Value2", info.postCode); // 閭斂缂栫爜 + qDebug()<<15; + sheet->querySubObject("Range(QVariant, QVariant)", "F31")->setProperty("Value2", info.email); // 鐢靛瓙閭 + qDebug()<<16; + sheet->querySubObject("Range(QVariant, QVariant)", "F33")->setProperty("Value2", info.webSite); // 缃戝潃 + qDebug()<<17; + + // 浜� 鍗曚綅缁勭粐缁撴瀯鎯呭喌 + sheet->querySubObject("Range(QVariant, QVariant)", "E36")->setProperty("Value2", QString::fromLocal8Bit(info.hasUpLegal)); // 鏄惁鏈変笂涓�绾ф硶浜� + qDebug()<<18; + sheet->querySubObject("Range(QVariant, QVariant)", "H37")->setProperty("Value2", QString::fromLocal8Bit(info.upCreditCode)); // 涓婁竴绾х粺涓�绀句細淇$敤浠g爜 + qDebug()<<19; + sheet->querySubObject("Range(QVariant, QVariant)", "H38")->setProperty("Value2", QString::fromLocal8Bit(info.oldCreditCode)); // 鍘熺粍缁囨満鏋勪唬鐮� + qDebug()<<20; + sheet->querySubObject("Range(QVariant, QVariant)", "H39")->setProperty("Value2", QString::fromLocal8Bit(info.upName)); // 涓婁竴绾у崟浣嶅悕绉� + qDebug()<<21; + + // 涓� 鎬诲璁″笀涓庡唴閮ㄥ璁℃満鏋勫熀鏈儏鍐� + sheet->querySubObject("Range(QVariant, QVariant)", "E41")->setProperty("Value2", QString::fromLocal8Bit(info.hasChiefDesigner)); // 鏄惁璁剧疆鎬诲璁″笀 + qDebug()<<22; + sheet->querySubObject("Range(QVariant, QVariant)", "E42")->setProperty("Value2", QString::fromLocal8Bit(info.ChiefDesignerLevel)); // 鎬诲璁″笀鑱屼綅灞傜骇 + qDebug()<<23; + sheet->querySubObject("Range(QVariant, QVariant)", "E45")->setProperty("Value2", QString::fromLocal8Bit(info.employmentMode)); // 鎬诲浠昏亴鏂瑰紡 + qDebug()<<24; + sheet->querySubObject("Range(QVariant, QVariant)", "E48")->setProperty("Value2", QString::fromLocal8Bit(info.hasSetIntervalAudit)); // 鏄惁璁剧疆鍐呭鏈烘瀯 + qDebug()<<25; + sheet->querySubObject("Range(QVariant, QVariant)", "E49")->setProperty("Value2", QString::fromLocal8Bit(info.internalName)); // 鍐呭鏈烘瀯鍚嶇О + qDebug()<<26; + sheet->querySubObject("Range(QVariant, QVariant)", "E50")->setProperty("Value2", QString::fromLocal8Bit(info.leadingOrganization)); // 棰嗗鏈烘瀯 + qDebug()<<27; + sheet->querySubObject("Range(QVariant, QVariant)", "E54")->setProperty("Value2", QString::fromLocal8Bit(info.hasSetSeparateIA)); // 鏄惁鐙珛璁剧疆鍐呭鏈烘瀯 + qDebug()<<28; + sheet->querySubObject("Range(QVariant, QVariant)", "E56")->setProperty("Value2", info.financeDepartment); // 璐㈠姟閮ㄩ棬 + qDebug()<<29; + sheet->querySubObject("Range(QVariant, QVariant)", "E56")->setProperty("Value2", info.legalDepartment); // 娉曞姟閮ㄩ棬 + qDebug()<<30; + sheet->querySubObject("Range(QVariant, QVariant)", "E56")->setProperty("Value2", info.internalConDepart); // 鍐呴儴鎺у埗閮ㄩ棬 + qDebug()<<31; + sheet->querySubObject("Range(QVariant, QVariant)", "E56")->setProperty("Value2", info.disceplineInDepart); // 绾閮ㄩ棬 + qDebug()<<32; + sheet->querySubObject("Range(QVariant, QVariant)", "E56")->setProperty("Value2", info.otherDepart); // 鍏朵粬閮ㄩ棬 + qDebug()<<33; + sheet->querySubObject("Range(QVariant, QVariant)", "E57")->setProperty("Value2", QString::fromLocal8Bit(info.intavalAuditLeval)); // 鍐呭灞傜骇 + qDebug()<<34; + + // 鍥� 鍐呴儴瀹¤浜哄憳閰嶅鍩烘湰鎯呭喌 + sheet->querySubObject("Range(QVariant, QVariant)", "E61")->setProperty("Value2", info.organazationNum); // 缂栧埗鏁伴噺 + qDebug()<<35; + sheet->querySubObject("Range(QVariant, QVariant)", "G61")->setProperty("Value2", info.realNum); // 瀹炴湁浜哄憳鏁� + qDebug()<<36; + sheet->querySubObject("Range(QVariant, QVariant)", "I61")->setProperty("Value2", info.professionalNum); // 涓撹亴浜哄憳鏁伴噺 + qDebug()<<37; + sheet->querySubObject("Range(QVariant, QVariant)", "G62")->setProperty("Value2", info.CIANum); // 鎷ユ湁CIA浜烘暟 + qDebug()<<38; + sheet->querySubObject("Range(QVariant, QVariant)", "G63")->setProperty("Value2", info.masterNum); // 纭曞+瀛﹀巻浠ヤ笂浜烘暟 + qDebug()<<39; + sheet->querySubObject("Range(QVariant, QVariant)", "G64")->setProperty("Value2", info.undergraduatesNum); // 鏈浜烘暟 + qDebug()<<40; + sheet->querySubObject("Range(QVariant, QVariant)", "G65")->setProperty("Value2", info.juniorNum); // 涓撶鍙婁互涓嬩汉鏁� + qDebug()<<41; + sheet->querySubObject("Range(QVariant, QVariant)", "G66")->setProperty("Value2", info.seniorNum); // 楂樼骇鑱岀О浜烘暟 + qDebug()<<42; + sheet->querySubObject("Range(QVariant, QVariant)", "G67")->setProperty("Value2", info.intermediateNum); // 涓骇鑱岀О浜烘暟 + qDebug()<<43; + sheet->querySubObject("Range(QVariant, QVariant)", "G68")->setProperty("Value2", info.primaryNum); // 鍒濈骇鑱岀О浜烘暟 + qDebug()<<44; + sheet->querySubObject("Range(QVariant, QVariant)", "G69")->setProperty("Value2", info.noTitleNum); // 鏃犺亴绉颁汉鏁� + qDebug()<<45; + sheet->querySubObject("Range(QVariant, QVariant)", "G70")->setProperty("Value2", info.upFiftyOldNum); // 50宀佷互涓婁汉鏁� + qDebug()<<46; + sheet->querySubObject("Range(QVariant, QVariant)", "G71")->setProperty("Value2", info.upThirtyOldNum); // 30-50宀佷汉鏁� + qDebug()<<47; + sheet->querySubObject("Range(QVariant, QVariant)", "G72")->setProperty("Value2", info.downThirtyOldNum); // 30宀佷互涓嬩汉鏁� + qDebug()<<48; + sheet->querySubObject("Range(QVariant, QVariant)", "G73")->setProperty("Value2", info.auditNum); // 瀹¤鏁伴噺 + qDebug()<<49; + sheet->querySubObject("Range(QVariant, QVariant)", "G74")->setProperty("Value2", info.accountingNum); // 浼氳鏁伴噺 + qDebug()<<50; + sheet->querySubObject("Range(QVariant, QVariant)", "G75")->setProperty("Value2", info.economyNum); // 缁忔祹鏁伴噺 + qDebug()<<51; + sheet->querySubObject("Range(QVariant, QVariant)", "G76")->setProperty("Value2", info.lawNum); // 娉曞緥鏁伴噺 + qDebug()<<52; + sheet->querySubObject("Range(QVariant, QVariant)", "G77")->setProperty("Value2", info.managerNum); // 绠$悊鏁伴噺 + qDebug()<<53; + sheet->querySubObject("Range(QVariant, QVariant)", "G78")->setProperty("Value2", info.itNum); // 淇℃伅鎶�鏈暟閲� + qDebug()<<54; + sheet->querySubObject("Range(QVariant, QVariant)", "G79")->setProperty("Value2", info.engineeringNum); // 宸ョ▼鏁伴噺 + qDebug()<<55; + sheet->querySubObject("Range(QVariant, QVariant)", "G80")->setProperty("Value2", info.otherNum); // 鍏朵粬鏁伴噺 + qDebug()<<56; + + // 鍚庨潰鐨�4涓俊鎭� + sheet->querySubObject("Range(QVariant, QVariant)", "B82")->setProperty("Value2", QString::fromLocal8Bit(info.statisticalConOfficer)); // 缁熻璐熻矗浜� + qDebug()<<57; + sheet->querySubObject("Range(QVariant, QVariant)", "E82")->setProperty("Value2", QString::fromLocal8Bit(info.personFilling)); // 濉〃浜� + qDebug()<<58; + sheet->querySubObject("Range(QVariant, QVariant)", "B83")->setProperty("Value2", QString::fromLocal8Bit(info.officerTel)); // 鑱旂郴鐢佃瘽 + qDebug()<<59; + sheet->querySubObject("Range(QVariant, QVariant)", "E83")->setProperty("Value2", QString::fromLocal8Bit(info.fillingDateTime)); // 濉姤鏃ユ湡 + qDebug()<<60; + + // 瀹屼簨浜嗭紝缁撴潫锛屼繚瀛樻垨鑰呴��鍑� + wb->dynamicCall("SaveAs(const QString&)",QDir::toNativeSeparators(savePath)); + wbs->dynamicCall("Close()"); + excel.dynamicCall("Quit(void)"); + + + } + return 0; } int ExportToFile::saveToExcelFromThreeMergePro() { - + return 0; } int ExportToFile::saveToExcelFromNeiShenZonghe() { - + return 0; } -- Gitblit v1.8.0