Exemple #1
0
void test1()
{
	QAxObject excel( "Excel.Application", 0);
	excel.setProperty("Visible", true);

	QAxObjectPtr workbooks(excel.querySubObject("Workbooks"));
	QAxObjectPtr workbook(workbooks->querySubObject("Add()"));
	QAxObjectPtr sheets(workbook->querySubObject("Worksheets"));
	sheets->dynamicCall("Add()");
	QAxObjectPtr sheet(sheets->querySubObject( "Item( int )", 1 ));
	// sheet->setProperty("Name","Nova Planilha");

	QAxObjectPtr range(sheet->querySubObject("Cells(int,int)",1,1));
	range->setProperty("Value", QVariant(1234));

	QImage image("c:/Users/jhlee/Dropbox/orgwiki/img/class01.png");
	QClipboard* clip = QApplication::clipboard();
	clip->setImage(image);
	QAxObjectPtr shapes(sheet->querySubObject("Shapes"));
	sheet->dynamicCall("Paste()");
	int shapeCount = shapes->property("Count").toInt();
	QAxObjectPtr shape(shapes->querySubObject(QString::fromLatin1("Item(%1)").arg(shapeCount).toAscii()));

	// shapes->dynamicCall("AddPicture( QString&, bool, bool, double, double, double, double","c:\\Users\\jhlee\\Dropbox\\orgwiki\\img\\class01.png",true,true,100,100,70,70);

	excel.setProperty("DisplayAlerts", false);
	workbook->dynamicCall("SaveAs(QString&)", "c:\\temp\\testexcel.xlsx");
	// //workbook->dynamicCall("Close()");
	// //excel.dynamicCall("Quit()");
	// workbook->dynamicCall("Close (Boolean)", true);
	excel.dynamicCall("Quit()");
}
Exemple #2
0
void D2Data::loadTypes(File* file)
{
  D2Excel excel(file);
  int invgfx[6] = {excel.colByName("InvGfx1"),
                   excel.colByName("InvGfx2"),
                   excel.colByName("InvGfx3"),
                   excel.colByName("InvGfx4"),
                   excel.colByName("InvGfx5"),
                   excel.colByName("InvGfx6")};
  for (int i = 0; i < excel.rows(); i++)
  {
    char const* name = excel.value(i, 0);
    char const* code = excel.value(i, 1);
    if (*name && *code)
    {
      D2ItemType& type = itemTypes.create(code);
      type.code = code;
      type.name = name;
      type.parent = &rootType;
      for (int j = 0; j < 6; j++)
      {
        char const* gfx = (invgfx[j] ? excel.value(i, invgfx[j]) : "");
        if (*gfx) type.invgfx.push(gfx);
      }
    }
  }
  for (int i = 0; i < excel.rows(); i++)
  {
    D2ItemType* type = itemTypes.getptr(excel.value(i, 1));
    D2ItemType* equiv1 = itemTypes.getptr(excel.value(i, 2));
    D2ItemType* equiv2 = itemTypes.getptr(excel.value(i, 3));
    if (type && equiv1)
    {
      equiv1->sub.push(type);
      type->parent = equiv1;
    }
    if (type && equiv2)
    {
      equiv2->sub.push(type);
      if (type->parent)
        type->parent2 = equiv2;
      else
        type->parent = equiv2;
    }
    if (type && !equiv1 && !equiv2)
      rootType.sub.push(type);
  }
  for (uint32 cur = itemTypes.enumStart(); cur; cur = itemTypes.enumNext(cur))
    itemTypes.enumGetValue(cur).sub.sort();
}
Exemple #3
0
int main(int argc, char** argv)
{
	QApplication excel(argc, argv);
	QCoreApplication::setOrganizationName("joonhwan");
	QCoreApplication::setOrganizationDomain("www.joonhwan.org");
	QCoreApplication::setApplicationName("QActiveXTester"); 

	// test1();
	// test2();
	// test3();
	test4();

	// return excel.exec();
	return 0;
}
Exemple #4
0
void D2Data::loadBase(File* file)
{
  D2Excel excel(file);
  int cCode = excel.colByName("code");
  int cNameStr = excel.colByName("namestr");
  int cInvWidth = excel.colByName("invwidth");
  int cInvHeight = excel.colByName("invheight");
  int cType = excel.colByName("type");
  int cInvTrans = excel.colByName("InvTrans");
  int cInvFile = excel.colByName("invfile");
  int cLevelReq = excel.colByName("levelreq");
  for (int i = 0; i < excel.rows(); i++)
  {
    char const* code = excel.value(i, cCode);
    char const* name = strings.byName(excel.value(i, cNameStr));
    if (*code && name)
    {
      while (true)
      {
        char const* endl = strchr(name, '\n');
        if (!endl) break;
        name = endl + 1;
      }
      D2BaseItem& base = baseItems.create(code);
      base.name = name;
      base.invwidth = atoi(excel.value(i, cInvWidth));
      base.invheight = atoi(excel.value(i, cInvHeight));
      base.invtrans = atoi(excel.value(i, cInvTrans));
      base.type = itemTypes.getptr(excel.value(i, cType));
      base.invfile = excel.value(i, cInvFile);
      base.levelreq = (cLevelReq ? atoi(excel.value(i, cLevelReq)) : 0);
      base.numGemMods = 0;
      baseMatch.add(base.name, &base);

      if (base.type) base.type->bases++;
    }
  }
}
Exemple #5
0
void Converter::convertSingleExcel(const std::string& fileName)
{
	tWorkbooksSp wbs = excel()->getWorkbooks();
	tWorkbookSp wb = wbs->open(toUtf16(getInputAbsPath(fileName)));
	if (!wb) {
		logError(logger(), "Error while opening excel file: " + fileName);
		return;
	}

	tWorksheetsSp wss = wb->worksheets();
	int numSheets = wss->getCount();
	for (int i = 1; i <= numSheets; ++i) {
		tWorksheetSp ws = wss->getItem(i);
		if (!ws) {
			std::cout << "no worksheet at index: " << i << std::endl;
		}
		std::cout << "Processing worksheet " << i << " / " << numSheets << std::endl;
		if (excelVisible_)
			ws->activate();
		tExcelRangeSp r = ws->usedRange();	
		//r = r->cells();
		int rows = r->numRows();
		int cols = r->numCols();
		int count = r->count();

		std::wstring wstr;
		std::wstring wstrUni;

		int total = rows * cols;
		int current = 0, lastDisplayed = 0;

		for (int j = 1; j <= count; ++j) {
			tExcelRangeSp cc = r->item(j);
			convertText(cc, wstr, wstrUni);

			current = (int)(100.0 * (double)(j) / (double)total);
			if (lastDisplayed < current) {
				lastDisplayed = current;
				std::cout << lastDisplayed << " % completed\r";
			}
		}

// 		while (count > 0) {
// 			std::cout << er->getIDispatch() << std::endl;
// 			wstr = er->getText();
// 			tFontSp font = er->getFont();
// 			std::cout << font->getName() << std::endl;
// 			convertText(font, wstr, wstrUni);
// 
// 			//std::wcout << wstr << std::endl;
// 			er = er->next();
// 			--count;
// 		}

	}

	string_t outputDir = getOutputAbsPath(fileName);
	Poco::File(outputDir).createDirectories();
	Poco::Path p(fileName);
	logInfo(logger(), "Saving worksheet...");
	std::string newName = outputDir + p.getBaseName() + " UNICODE." + p.getExtension();
	Poco::File pf(newName);
	if (pf.exists())
		pf.remove();
	wb->saveAs(newName);
	wb->close();
	logInfo(logger(), "Save was successful.");
}
Exemple #6
0
void Widget::set_ui()
{
    //ui property
    ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    ui->tableWidget->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    ui->tableWidget->horizontalHeader()->resizeSections(QHeaderView::Stretch);
    ui->tableWidget->verticalHeader()->resizeSections(QHeaderView::Stretch);
    ui->combGroup->setEditable(true);
    ui->combGroup->setLineEdit(ui->groupLine);
    ui->btnGroupChange->setVisible(false);
    QMenu *menuPutbtn = new QMenu(ui->pushButton_put);
    QMenu *menuPutbtnDelay = new QMenu(QStringLiteral("延时放料"),ui->pushButton_put);
    for(int i = 1;i<=3;i++)//TODO:setup the preDelay Time
    {
        QAction *action = new QAction(ui->pushButton_put);
        action->setText(QString(QStringLiteral("延时 %1 (%2)放料")).arg(QString::number(i*5).toUtf8(),QStringLiteral("分钟")));
        menuPutbtnDelay->addAction(action);
        connect(action,&QAction::triggered,[=]{
            ui->pushButton_put->setText(QStringLiteral("放料") + QString("(%1分钟)").arg(i*5));
            updateDlyTime(i*5);//更新全局变量-延时计时时间
            //operate it.
            qDebug()<<"delay.....";
            startPutOperate();
        });
    }
    menuPutbtnDelay->addAction(QStringLiteral("自定义放料时间"));
    connect(menuPutbtnDelay->actions().last(),&QAction::triggered,[=]{
        setupDelayPutWetTime();
        connect(this,&Widget::sendCustomDlyTime,[=](QDateTime dlytime){
//            QString time =dlytime.toString()-QDateTime::currentDateTime().toString()
//            ui->pushButton_put->setText(QStringLiteral("放料") + QString("(%1后开始)").arg());
            updateDlyTime(dlytime);//更新全局变量-延时计时时间
            startPutOperate();
        });
//        connect();//connect the sig to change the current delay time
    });
    menuPutbtn->addAction(QStringLiteral("直接放料(不延时)"));
    connect(menuPutbtn->actions().first(),&QAction::triggered,[=]{
        startPutOperate();
    });
    menuPutbtn->addMenu(menuPutbtnDelay);
    ui->pushButton_put->setMenu(menuPutbtn);

    ui->groupLine->setAlignment(Qt::AlignCenter);
    connect(ui->groupLine,&QLineEdit::textChanged,[=](const QString & text){//切换组号时触发信号-检测当前组号IP连接状态,连接正常则启用按钮;
        ui->grpb_selectgroup->setTitle(QStringLiteral("分组")+QString("%1").arg(text));
        //var _flagConnected is true;
//        bool _flagConnected = false;//NOTE:global var
//        //setting the ui widget to use
//        bool flag = true;
//        QSettings setting;
//        setting.beginGroup("GroupData");
//        flag = setting.value(QString("%1/States").arg(text)).toBool();
//        setting.endGroup();
//        if(flag){
//            ui->pushButton_getinfo->setEnabled(!flag);
//            ui->pushButton_close->setEnabled(flag);
//            ui->pushButton_weigh->setEnabled(!flag);
//            ui->pushButton_link->setEnabled(!flag);
//            ui->pushButton_put->setEnabled(!flag);
//        }
    });
    ui->groupLine->setText(QStringLiteral("1"));
    ui->pushButton_link->setEnabled(true);
    ui->pushButton_close->setEnabled(false);
    ui->pushButton_put->setEnabled(false);
    ui->pushButton_weigh->setEnabled(false);

    //TopWidget Btn next Group and PreGroup
    connect(ui->btnGroupNext,&QToolButton::clicked,[=]{
        if(ui->combGroup->currentText().toInt()<ui->combGroup->count()){
            ui->combGroup->setCurrentIndex(ui->combGroup->currentIndex()+1);
        }
    });
    connect(ui->btnGroupPre,&QToolButton::clicked,[=]{
        if(ui->combGroup->currentText().toInt()>1){
            ui->combGroup->setCurrentIndex(ui->combGroup->currentIndex()-1);
        }
    });

    connect(ui->combGroup,&QComboBox::currentTextChanged,[=](const QString & text){
        ui->states_group_IPSet->setText(ui->combGroup->itemData(ui->combGroup->currentIndex()).toString());
        //TODO:if data not handle...save or tips?
//        send_head p;
//        for(int i = 0;i<24;i++){
//            QString value = ui->tableWidget->item(i,1)->text();
//            p.data[i] = value.toFloat()*100;
//        }
//        _BarrelList.insert(ui->combGroup->currentText().toInt(),p);//TODO:not use??
//        bool flag_states =(_BarreStatus.find(ui->combGroup->currentText().toInt()).value().second);
//        sendHead pObject;
//        pObject.sendheadValue = p;
//        _BarreStatus.insert(ui->combGroup->currentText().toInt(),QPair<QPair<sendHead,sendHead>,bool>
//                            (QPair<sendHead,sendHead>(pObject,sendHead()),flag_states));

//        _BarreStatus.insert(ui->combGroup->currentText().toInt(),
//                            QPair<QPair<send_head,send_head>,bool>(QPair<send_head,send_head>(p,send_head()),false));
        QSettings setting;
        setting.beginGroup("GroupData");
        bool flag_ipstates = setting.value(QString("%1/States").arg(text)).toBool();
        setting.endGroup();
        ui->pushButton_link->setEnabled(flag_ipstates);
        ui->pushButton_close->setEnabled(!flag_ipstates);
        ui->pushButton_weigh->setEnabled(flag_ipstates);
        if(_BarreStatus.find(ui->combGroup->currentText().toInt()).value().second){
            ;
        }else{
            ui->pushButton_put->setEnabled(false);
        }
        setupTableItem();
        ui->pushButton_weigh->setEnabled(!_BarreStatus.find(ui->combGroup->currentText().toInt()).value().second);
    });

    connect(this,&Widget::updateGroupData,[=]{
        setupTableItem();//初始化表格為默認
        //更新Combobox數據
        ui->combGroup->clear();
        QSettings setting;
        setting.beginGroup("GroupData");
        for(int i = 0;i<setting.childGroups().count();i++){
            QString strip = setting.value(QString("%1/IpAdd").arg(setting.childGroups().at(i)),i>9?QString("192.168.1.1%1").arg(i):QString("192.168.1.10%1").arg(i)).toString();
            ui->combGroup->addItem(QString::number(i+1));
            ui->combGroup->setItemData(i,strip);
        }
        setting.endGroup();
    });

    connect(ui->btnImportExcel,&QToolButton::clicked,[=]{
//        setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
        activateWindow();
        QString filename = QFileDialog::getOpenFileName();
        ExcelEngine excel(filename);
        excel.ReadDataReplace(ui->tableWidget,1);

//        setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
    });

    //Table property setting
    ui->tableWidget->verticalHeader()->setVisible(false);
    ui->tableWidget->setItemDelegateForColumn(0,new ReadOnlyDelegate(this));
    ui->tableWidget->setItemDelegateForColumn(2,new ReadOnlyDelegate(this));

    setupTableItem();

    for(int i=0;i<24;i++)
    {
        err[i]=true;
    }
    flag=false;

    client_tcp=new QTcpSocket(this);
    if(connectDB()){
       this->setWindowTitle(QStringLiteral("连接数据库成功"));
    }else{
       QMessageBox::warning(this, "连接数据空失败", "请检查数据库文件", QMessageBox::Ok, QMessageBox::Ok);
    }

    //Tray
    system_tray = new QSystemTrayIcon();
    system_tray ->setToolTip(QApplication::applicationName());
    system_tray ->setIcon(QApplication::style()->standardIcon(QStyle::SP_VistaShield));
    QMenu *menu = new QMenu();
    menu->addAction(QStringLiteral("显示主界面(&s)"),this,SLOT(showNormal()));
    QAction *actionSetting = new QAction(this);
    actionSetting->setText(QStringLiteral("设置面板(&P)"));
    connect(actionSetting,&QAction::triggered,[=]{
        setupSettingForm();
    });
    menu->addAction(actionSetting);
    menu->addSeparator();
    QAction *actionclose = new QAction(this);
    actionclose->setText(QStringLiteral("退出(&x)"));
    connect(actionclose,&QAction::triggered,[=]{
        _flagCloseWin = true;
        close();
    });
    menu->addAction(actionclose);

    system_tray->setContextMenu(menu);
    system_tray->setVisible(true);
    system_tray->show();
    connect(system_tray ,&QSystemTrayIcon::activated,[=](QSystemTrayIcon::ActivationReason reason){
        switch(reason)
        {//点击托盘显示窗口
        case QSystemTrayIcon::Trigger:
        {
            showNormal();
            break;
        }
        case QSystemTrayIcon::DoubleClick://双击托盘显示窗口
        {
            showNormal();
            break;
        }
        default:
            break;
        }

    });

    connect(ui->tableWidget,SIGNAL(itemChanged(QTableWidgetItem*)),this,SLOT(Weigh_item_cheack(QTableWidgetItem*)));
    connect(ui->tableWidget,&QTableWidget::cellChanged,[=](int row,int column){
        if(column == 1){//只对第二列数据进行处理
            _BarreStatus.find(ui->combGroup->currentText().toInt()).value().first.first.sendheadValue.data[row] = ui->tableWidget->item(row,column)->text().toFloat() * 100;
            bool flag_states = _BarreStatus.find(ui->combGroup->currentText().toInt()).value().second;
            if(flag_states )//&& ui->pushButton_weigh->isEnabled())
                _BarreStatus.find(ui->combGroup->currentText().toInt()).value().second = false;
//            if(ui->tableWidget->item(row,column)->text().toInt() == 0){
//                ui->tableWidget->item(row,column)->setText("");
//            }
        }
    });

    //connect(client_tcp,SIGNAL(readyRead()),this,SLOT(display()));
    connect(client_tcp,SIGNAL(readyRead()),this,SLOT(recv_data()));
    connect(client_tcp,SIGNAL(connected()),this,SLOT(connect_Successful()));
    connect(client_tcp,SIGNAL(disconnected()),this,SLOT(connect_Close()));

    //connect slot and signal
    connect(ui->pushButton_link,&QPushButton::clicked,[=]{
        //test ->TODO:delete this line
        connect(this,SIGNAL(sendConnectSocketReturn(int,bool)),this,SLOT(finishedConnectSlot(int ,bool)));
        ui->pushButton_link->setEnabled(false);
//        ui->pushButton_put->setEnabled(true);//TODO:should check has data in table...
//        ui->pushButton_weigh->setEnabled(false);
        ui->pushButton_weigh->setEnabled(true);//TODO:test to change true.should be delete;
        emit sendConnectSocket(_GroupIpList);
        emit sendConnectSocketReturn(ui->combGroup->currentText().toInt(),true);
    });
Exemple #7
0
void D2Data::loadUnique()
{
  Dictionary<int> colorCodes;
  {
    D2Excel colors(TempFile(loader.load("data\\global\\excel\\colors.txt")));
    for (int i = 0; i < colors.rows(); i++)
      colorCodes.set(colors.value(i, 1), i);
  }

  for (int type = 2; type <= 6; type += 2)
  {
    D2Excel excel(TempFile(loader.load(type == 2 ? "data\\global\\excel\\SetItems.txt" : (
                                       type == 4 ? "data\\global\\excel\\UniqueItems.txt" :
                                                   "data\\global\\excel\\Runes.txt"))));
    int cEnabled = excel.colByName(type == 6 ? "complete" : "enabled");
    int cCode = excel.colByName(type == 2 ? "item" : "code");
    int cInvColor = excel.colByName("invtransform");
    int cInvFile = excel.colByName("invfile");
    int cProps = excel.colByName(type < 6 ? "prop1" : "T1Code1");
    for (int i = 0; i < excel.rows(); i++)
    {
      if (type == 2 ? *excel.value(i, cCode) : atoi(excel.value(i, cEnabled)))
      {
        D2UniqueItem* item = new D2UniqueItem;
        item->name = strings.byName(excel.value(i, 0));
        if (type != 6)
        {
          char const* invColor = excel.value(i, cInvColor);
          item->invcolor = (colorCodes.has(invColor) ? colorCodes.get(invColor) : -1);
          item->invfile = excel.value(i, cInvFile);
          item->base = baseItems.getptr(excel.value(i, cCode));
        }
        else
        {
          item->invcolor = -1;
          item->base = NULL;
        }
        item->type = type;

        for (int p = 0; p < (type < 6 ? 12 : 7); p++)
        {
          char const* propName = excel.value(i, cProps + p * 4);
          if (!*propName) continue;
          char const* par = excel.value(i, cProps + p * 4 + 1);
          int parI;
          if (String(par).isDigits())
            parI = atoi(par);
          else
            parI = statData->getSkill(par);
          statData->addPreset(item->preset, propName, parI,
             atoi(excel.value(i, cProps + p * 4 + 2)), atoi(excel.value(i, cProps + p * 4 + 3)));
        }

        uniqueItems.push() = item;
        uniqueMatch.add(item->name, item);
      }
    }
  }
  uniqueItems.sort(uniqueComp);
  uniqueMatch.build();
}