Example #1
2
void __fastcall IniTestAcadWindow(Variant Acad) {
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
/*
	int i, v;
    try {
	    v = Acad.OlePropertyGet("HWND");
    } catch (...) {
        v = 0;
    }
    if (v == 0) {
		v = Acad.OlePropertyGet("HWND32");
	}
    AcadClassHWND = (HWND)v;
	AcadClassName = new char[10000];
	::GetClassNameA(AcadClassHWND, AcadClassName, 10000);
*/
	int i, h1, h2, hh;
	char buf[100];

    try {
	    h1 = Acad.OlePropertyGet("HWND");
    } catch (...) {
        h1 = 0;
    }
    try {
	    h2 = Acad.OlePropertyGet("HWND32");
    } catch (...) {
        h2 = 0;
    }

	AcadClassHWND = (HWND)(h1 == 0 ? h2 : h1);
	AcadClassName = new char[10000];
    memset(AcadClassName, 0, 10000);
	strcpy(AcadClassName, "???");
	::GetClassNameA(AcadClassHWND, AcadClassName, 10000);

	//wsprintf(buf, "h1=%08X h2=%08X %s", h1, h2, AcadClassName);
    // Application->MessageBox(buf, "info", 0);

}
Example #2
0
void TForm1::ReadMonthSum(Variant &vSheet, double &sum)
{
	UnicodeString strPageName = vSheet.OlePropertyGet("Name");
	int nRowsCount = vSheet.OlePropertyGet("Cells").OlePropertyGet("Rows").OlePropertyGet("Count");
	int nLastRow = vSheet.OlePropertyGet("Cells", nRowsCount, 4).OlePropertyGet("End", xlUp).OlePropertyGet("Row");

	Log->Lines->Add(" * Поиск и суммирования сум по дням " + strPageName + " (строк: " + IntToStr(nLastRow-1) + ")");
	ProgressBar1->Max = nLastRow;
	ProgressBar1->Min = 0;
	int nFound = 0;
	for (int i = 0; i < nLastRow; i++) {
		ProgressBar1->Position = i;
		Application->ProcessMessages();

		exlMonth mon;
		mon.Month = strPageName;
		mon.Name = vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",i+1,3).OlePropertyGet("Value");
		if (mon.Name.Trim().IsEmpty()) {
			mon.Price = vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",i+1,4).OlePropertyGet("Value");
			int nWeight = vSheet.
				OlePropertyGet("Cells").
				OlePropertyGet("Item",i+1,4).
				OlePropertyGet("Borders", xlEdgeLeft).
				OlePropertyGet("Weight");
			if (mon.Price != 0 && nWeight == xlMedium) {
				Log->Lines->Add("\tСумма: " + mon.Name + ": " + FloatToStr(mon.Price));
				sum += mon.Price;
			}
		}
	}

	ProgressBar1->Position = 0;
	Log->Lines->Add(" * Найдено: " + IntToStr(nFound) + ", общая сумма: " + FloatToStr(sum));
}
Example #3
0
void TForm1::ReadMonth(Variant &vSheet, std::vector<exlMonth> &month)
{
	UnicodeString strPageName = vSheet.OlePropertyGet("Name");
	int nRowsCount = vSheet.OlePropertyGet("Cells").OlePropertyGet("Rows").OlePropertyGet("Count");
	int nLastRow = vSheet.OlePropertyGet("Cells", nRowsCount, 3).OlePropertyGet("End", xlUp).OlePropertyGet("Row");

	lblStatus->Caption = "Загрузка данных с листа " + strPageName;
	Log->Lines->Add(" * Произвожу загрузку данных с листа " + strPageName + " (строк: " + IntToStr(nLastRow-1) + ")");
	ProgressBar1->Max = nLastRow;
	ProgressBar1->Min = 0;
	int nFound = 0;
	for (int i = 0; i < nLastRow; i++) {
		ProgressBar1->Position = i;
		Application->ProcessMessages();

		exlMonth mon;
		mon.Month = strPageName;
		mon.Name = vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",i+1,3).OlePropertyGet("Value");
		if (!mon.Name.Trim().IsEmpty()) {
			mon.Price = vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",i+1,4).OlePropertyGet("Value");
			if (mon.Price != 0) {
				nFound++;
				month.push_back(mon);
			} else {
				Log->Lines->Add("\tЧто то не то: " + mon.Name + " : " + FloatToStr(mon.Price));
			}
		}
	}
	ProgressBar1->Position = 0;
	Log->Lines->Add(" * Найдено записей: " + IntToStr(nFound) + "");
	lblStatus->Caption = "";
}
Example #4
0
void __fastcall TForm1::actSortClassificationsExecute(TObject *Sender)
{
	if(!MakeBackup()) {
		Log->Lines->Add("Ошибка: Не удалось создать резервную копию файла");
		return;
	}

	Variant app = Variant::CreateObject("Excel.Application");
	app.OlePropertySet("Visible", true);
	Variant excel = app.OlePropertyGet("Workbooks").OleFunction("Open", WideString(m_strFileName.c_str()));
	Variant vSheets = excel.OlePropertyGet("Worksheets");

	Variant vSheet = vSheets.OlePropertyGet("Item",m_nPageClassification);
	UnicodeString strPageName = vSheet.OlePropertyGet("Name");
	if (strPageName.UpperCase() != UnicodeString("классификации").UpperCase()) {
	   app.OleProcedure("Quit");
	   Log->Lines->Add("Ошибка: Не верное имя страницы");
	   MessageBox (Handle, UnicodeString(L"Не верное имя страницы").c_str(), L"prompt", MB_OK);
	   return;
	};
	std::vector<exlClass> classes;
	ReadClassifications(vSheet, classes);
	WriteClassifications(vSheet, classes);


	Log->Lines->Add("Сохраняю файл...");
	try {
		app.OlePropertySet("DisplayAlerts",false);
		excel.OleProcedure("SaveAs", WideString(m_strFileName.c_str()));
		Log->Lines->Add("Классификации отсортированы!");
	} catch (...) {
		Log->Lines->Add("Ошибка: Пожалуйста закройте все открытые копии файла и повторите операцию");
	}
	app.OleProcedure("Quit");
}
//---------------------------------------------------------------------------
// Возвращает значение атрибута по имени
AnsiString __fastcall MSXMLWorks::GetAttributeValue(Variant Node, AnsiString AttributeName)
{
    Variant attribute = Node.OlePropertyGet("attributes").OleFunction("getNamedItem", AttributeName);
    if (!attribute.IsEmpty())
        return attribute.OlePropertyGet("text");
    else
        return "";

    // Второй способ
    //return Node.OleFunction("GetAttribute", StringToOleStr(AttributeName));
}
Example #6
0
void __fastcall TForm1::actViewClassificationsExecute(TObject *Sender)
{
	Variant app = Variant::CreateObject("Excel.Application");
	Variant excel = app.OlePropertyGet("Workbooks").OleFunction("Open", WideString(m_strFileName.c_str()));
	Variant vSheets = excel.OlePropertyGet("Worksheets");
	Variant vSheet = vSheets.OlePropertyGet("Item",m_nPageClassification);
	UnicodeString strPageName = vSheet.OlePropertyGet("Name");
	if (strPageName.UpperCase() != UnicodeString("классификации").UpperCase()) {
	   app.OleProcedure("Quit");
	   MessageBox (Handle, UnicodeString(L"Не верное имя страницы").c_str(), L"prompt", MB_OK);
	   return;
	};

	std::vector<exlClass> classes;
	ReadClassifications(vSheet, classes);
	app.OleProcedure("Quit");

	/*RichEdit1->Lines->Clear();
	RichEdit1->Lines->Add("Уровень TreeView1->Selected->Level: "+IntToStr(TreeView1->Selected->Level));
	int n = TreeView1->Selected->AbsoluteIndex;
	RichEdit1->Lines->Add("Асболютный номер TreeView1->Selected->AbsoluteIndex: "+IntToStr(n));
	RichEdit1->Lines->Add("Текст из выбранного узла: "+TreeView1->Selected->Text);*/
	FormSelectClass->ComboBox1->Items->Clear();
	FormClassEditor->TreeView1->Items->Clear();
	std::map<UnicodeString, TTreeNode *> nodeclasses;
	for (unsigned int i = 0; i < classes.size(); i++) {
		if (nodeclasses.count(classes[i].Class) == 0) {
			TTreeNode *parentNode = FormClassEditor->TreeView1->Items->Add(NULL, classes[i].Class);
			nodeclasses[classes[i].Class] = parentNode;
			parentNode->ImageIndex = 0;
			parentNode->SelectedIndex = 0;
			FormSelectClass->ComboBox1->Items->Add(classes[i].Class);
		}
		TTreeNode *pParentNode = nodeclasses[classes[i].Class];
		TTreeNode *pChildNode = FormClassEditor->TreeView1->Items->AddChild(pParentNode, classes[i].Name);
		pChildNode->ImageIndex = 1;
		pChildNode->Data = new exlClass(classes[i]);
		pChildNode->SelectedIndex = 1;
	}


//	TTreeNode *Node1 = FormClassEditor->TreeView1->Items->Add(NULL, "Root");
//	Node1->ImageIndex = 0;
//	FormClassEditor->TreeView1->Items->AddChild(Node1, "Root1");



/*	int n = TreeView1->Selected->AbsoluteIndex;
	TTreeNode *Node1 = TreeView1->Items->Item[n];
	TreeView1->Items->AddChild(Node1,"ChildNode");*/
//	Node1->Selected=true;
    ProgressBar1->Position = 0;
	FormClassEditor->ShowModal();
}
Example #7
0
//---------------------------------------------------------------------------
void __fastcall TForm2::CppWebBrowser2DocumentComplete(TObject *Sender,
      LPDISPATCH pDisp, Variant *URL)
{
    Variant vObj = CppWebBrowser2->OleObject;
 
    Variant vBody;
    String strDocCompatMode = vObj.OlePropertyGet("document").OlePropertyGet("compatMode");
 
    if (SameText(strDocCompatMode, "CSS1Compat"))
        vBody = vObj.OlePropertyGet("Document").OlePropertyGet("documentElement");
    else
        vBody = vObj.OlePropertyGet("Document").OlePropertyGet("body");
 
    vBody.OlePropertyGet("style").OlePropertySet("overflow", "hidden");         
}
Example #8
0
void TForm1::ReadClassifications(Variant &vSheet, std::vector<exlClass> &classes)
{
	int nRowsCount = vSheet.OlePropertyGet("Cells").OlePropertyGet("Rows").OlePropertyGet("Count");
	int nLastRow1 = vSheet.OlePropertyGet("Cells", nRowsCount, 1).OlePropertyGet("End", xlUp).OlePropertyGet("Row");
	int nLastRow2 = vSheet.OlePropertyGet("Cells", nRowsCount, 2).OlePropertyGet("End", xlUp).OlePropertyGet("Row");
	int nLastRow3 = vSheet.OlePropertyGet("Cells", nRowsCount, 3).OlePropertyGet("End", xlUp).OlePropertyGet("Row");
	int nLastRow4 = vSheet.OlePropertyGet("Cells", nRowsCount, 4).OlePropertyGet("End", xlUp).OlePropertyGet("Row");

	int nLastRow = 0;
	nLastRow = std::max(nLastRow, nLastRow1);
	nLastRow = std::max(nLastRow, nLastRow2);
	nLastRow = std::max(nLastRow, nLastRow3);
	nLastRow = std::max(nLastRow, nLastRow4);
	lblStatus->Caption = "Считываю классификации...";
	Log->Lines->Add("Считываю классификации  всего строк: " + IntToStr(nLastRow-1));
	ProgressBar1->Max = nLastRow;
	ProgressBar1->Min = 0;
	for (int i = 1; i < nLastRow; i++) {
		ProgressBar1->Position = i;
		Application->ProcessMessages();

		exlClass cl;
		cl.Name = vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",i+1,1).OlePropertyGet("Value");
		cl.Class = vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",i+1,2).OlePropertyGet("Value");
		cl.Comment = vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",i+1,3).OlePropertyGet("Value");
		cl.Monthes = vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",i+1,4).OlePropertyGet("Value");

		if (!cl.Name.Trim().IsEmpty()) {
			if (cl.Class.Trim().IsEmpty()) {
			  cl.Class = m_sUnknownClass;
			}
			bool bFound = false;
			for (int s = 0; s < classes.size(); s++) {
				if (classes[s].Name.UpperCase() == cl.Name.UpperCase()) {
					bFound = true;
				}
			}
			if (!bFound) {
				classes.push_back(cl);
			} else {
				Log->Lines->Add("При считывании найден дубликат - проигнорирован: [" + cl.Name + "]");
            }
		}
	}
	lblStatus->Caption = "Готово";
}
//---------------------------------------------------------------------------
void OfficeStrDel(AnsiString Office, Variant app, Variant Document, int Str, int Cnt)
// удалить строки
{
 try
    {
     if (Office=="OO")
      {
      }
     if (Office=="MSO")
      {
       //     Selection.MoveDown Unit:=wdLine, Count:=16
       //     Selection.Delete Unit:=wdCharacter, Count:=1
        Variant this_selection;
        this_selection = app.OlePropertyGet("Selection") ;
        this_selection.OleFunction("MoveDown", 5, Str);
        this_selection.OleFunction("Delete", 1, Cnt);
      }
    }
  catch (Exception &E)
    {
     ShowMessage("Ошибка при удалении строк " + E.Message);
    }
}
//---------------------------------------------------------------------------
void OfficeFindReplace(AnsiString Office, Variant app, Variant Document, AnsiString sFind, AnsiString sReplace)
{
//найти и заменить с параметрами
  try
    {
     if (Office=="OO")
      {
      /*
       //найти и заменить без параметров
       Variant FindParam = Document.OleFunction("createSearchDescriptor");
       FindParam.OlePropertySet("SearchString", sFind);
       FindParam.OlePropertySet("ReplaceString", sReplace);
       Document.OleFunction("ReplaceAll", FindParam);
       */
       Variant ServiceManager;
       ServiceManager = Variant::CreateObject("com.sun.star.ServiceManager");

       Variant MyStruct3 = ServiceManager.OleFunction("Bridge_GetStruct", "com.sun.star.beans.PropertyValue");
       MyStruct3.OlePropertySet("name",        "SearchItem.StyleFamily");
       MyStruct3.OlePropertySet("value",        2);
       Variant MyStruct4 = ServiceManager.OleFunction("Bridge_GetStruct", "com.sun.star.beans.PropertyValue");
       MyStruct4.OlePropertySet("name",        "SearchItem.CellType");
       MyStruct4.OlePropertySet("value",        0);
       Variant MyStruct5 = ServiceManager.OleFunction("Bridge_GetStruct", "com.sun.star.beans.PropertyValue");
       MyStruct5.OlePropertySet("name",        "SearchItem.RowDirection");
       MyStruct5.OlePropertySet("value",        true);
       Variant MyStruct6 = ServiceManager.OleFunction("Bridge_GetStruct", "com.sun.star.beans.PropertyValue");
       MyStruct6.OlePropertySet("name",        "SearchItem.AllTables");
       MyStruct6.OlePropertySet("value",        false);
       Variant MyStruct7 = ServiceManager.OleFunction("Bridge_GetStruct", "com.sun.star.beans.PropertyValue");
       MyStruct7.OlePropertySet("name",        "SearchItem.Backward");
       MyStruct7.OlePropertySet("value",        false);
       Variant MyStruct8 = ServiceManager.OleFunction("Bridge_GetStruct", "com.sun.star.beans.PropertyValue");
       MyStruct8.OlePropertySet("name",        "SearchItem.Pattern");
       MyStruct8.OlePropertySet("value",        false);
       Variant MyStruct9 = ServiceManager.OleFunction("Bridge_GetStruct", "com.sun.star.beans.PropertyValue");
       MyStruct9.OlePropertySet("name",        "SearchItem.Content");
       MyStruct9.OlePropertySet("value",        false);
       Variant MyStruct10 = ServiceManager.OleFunction("Bridge_GetStruct", "com.sun.star.beans.PropertyValue");
       MyStruct10.OlePropertySet("name",        "SearchItem.AsianOptions");
       MyStruct10.OlePropertySet("value",        false);
       Variant MyStruct11 = ServiceManager.OleFunction("Bridge_GetStruct", "com.sun.star.beans.PropertyValue");
       MyStruct11.OlePropertySet("name",        "SearchItem.AlgorithmType");
       MyStruct11.OlePropertySet("value",        0);

       Variant MyStruct2 = ServiceManager.OleFunction("Bridge_GetStruct", "com.sun.star.beans.PropertyValue");
       MyStruct2.OlePropertySet("name",       "SearchItem.SearchFlags");
       MyStruct2.OlePropertySet("value",      65552); // флаг 65536 - часть или все слово
       Variant MyStruct = ServiceManager.OleFunction("Bridge_GetStruct", "com.sun.star.beans.PropertyValue");
       MyStruct.OlePropertySet("name",        "SearchItem.SearchString");
       MyStruct.OlePropertySet("value",       sFind);
       Variant MyStruct1 = ServiceManager.OleFunction("Bridge_GetStruct", "com.sun.star.beans.PropertyValue");
       MyStruct1.OlePropertySet("name",       "SearchItem.ReplaceString");
       MyStruct1.OlePropertySet("value",      sReplace);

       Variant MyStruct12 = ServiceManager.OleFunction("Bridge_GetStruct", "com.sun.star.beans.PropertyValue");
       MyStruct12.OlePropertySet("name",        "SearchItem.Locale");
       MyStruct12.OlePropertySet("value",        255);
       Variant MyStruct13 = ServiceManager.OleFunction("Bridge_GetStruct", "com.sun.star.beans.PropertyValue");
       MyStruct13.OlePropertySet("name",        "SearchItem.ChangedChars");
       MyStruct13.OlePropertySet("value",        2);
       Variant MyStruct14 = ServiceManager.OleFunction("Bridge_GetStruct", "com.sun.star.beans.PropertyValue");
       MyStruct14.OlePropertySet("name",        "SearchItem.DeletedChars");
       MyStruct14.OlePropertySet("value",        2);
       Variant MyStruct15 = ServiceManager.OleFunction("Bridge_GetStruct", "com.sun.star.beans.PropertyValue");
       MyStruct15.OlePropertySet("name",        "SearchItem.InsertedChars");
       MyStruct15.OlePropertySet("value",        2);
       Variant MyStruct16 = ServiceManager.OleFunction("Bridge_GetStruct", "com.sun.star.beans.PropertyValue");
       MyStruct16.OlePropertySet("name",        "SearchItem.TransliterateFlags");
       MyStruct16.OlePropertySet("value",        1024);
       Variant MyStruct17 = ServiceManager.OleFunction("Bridge_GetStruct", "com.sun.star.beans.PropertyValue");
       MyStruct17.OlePropertySet("name",        "SearchItem.Command");
       MyStruct17.OlePropertySet("value",        3);
       Variant MyStruct18 = ServiceManager.OleFunction("Bridge_GetStruct", "com.sun.star.beans.PropertyValue");
       MyStruct18.OlePropertySet("name",        "Quiet");
       MyStruct18.OlePropertySet("value",        true);

       int Bounds[2] = {0,18}; // на 18 шт
       Variant SearchParam = VarArrayCreate(Bounds, 1, varVariant);

       SearchParam.PutElement(MyStruct3, 3);
       SearchParam.PutElement(MyStruct4, 4);
       SearchParam.PutElement(MyStruct5, 5);
       SearchParam.PutElement(MyStruct6, 6);
       SearchParam.PutElement(MyStruct7, 7);
       SearchParam.PutElement(MyStruct8, 8);
       SearchParam.PutElement(MyStruct9, 9);
       SearchParam.PutElement(MyStruct10, 10);
       SearchParam.PutElement(MyStruct11, 11);

       SearchParam.PutElement(MyStruct, 0);
       SearchParam.PutElement(MyStruct1, 1);
       SearchParam.PutElement(MyStruct2, 2);

       SearchParam.PutElement(MyStruct12, 12);
       SearchParam.PutElement(MyStruct13, 13);
       SearchParam.PutElement(MyStruct14, 14);
       SearchParam.PutElement(MyStruct15, 15);
       SearchParam.PutElement(MyStruct16, 16);
       SearchParam.PutElement(MyStruct17, 17);
       SearchParam.PutElement(MyStruct18, 18);


       Variant Dispatcher, Frame, CurrentController;
	   CurrentController = Document.OleFunction("getCurrentController");
       Frame = CurrentController.OleFunction("getFrame");
	   Dispatcher= ServiceManager.OleFunction("createInstance", "com.sun.star.frame.DispatchHelper");
       Dispatcher.OleFunction("executeDispatch", Frame, ".uno:ExecuteSearch", "", 0, SearchParam);
      }
	 if (Office=="MSO")
      {
		Variant this_selection, this_find;
		this_selection = app.OlePropertyGet("Selection") ;
	   //	this_selection.OleFunction("GoTo", 4294967295, 0, 0, Document);
		this_find = this_selection.OlePropertyGet("Find") ;
        //---Запуск обработки
		this_find.OleProcedure ("Execute",
		/* FindText          */      sFind.c_str(),
		/* MatchCase         */      false,
		/* MatchWholeWord    */      false, //  false - часть или все слово
        /* MatchWildcards    */      false,
        /* MatchSoundsLike   */      false,
        /* MatchAllWordForms */      false,
        /* Forward           */      true,
        /* Wrap              */      1,
        /* Format            */      false,
		/* ReplaceWith       */      sReplace.c_str(),
        /* Replace           */      2
		);
      }
    }
  catch (Exception &E)
    {
	 ShowMessage("Ошибка при поиске и замене " + E.Message);
    }
}
Example #11
0
void __fastcall TExportToXlsThread::Execute()
{
	//---- Place thread code here ----
	ExitBTN->Enabled = false;
	ExportQuery->Open();

	Variant ExcelApp;
	try
	{
		ExcelApp = CreateOleObject("Excel.Application");
	}
	catch(...)
	{
		MessageBox(SDIAppForm->Handle, "错误:您的系统中可能没有安装Excel!", "Error in launch Excel!", MB_OK|MB_ICONERROR);
		ExportQuery->Close();
		ExportBTN->Enabled = false;
		ExitBTN->Enabled = true;
		return;
	}

	if(!ExportQuery->IsEmpty())
	{
//		MessageBox(this->Handle, DTX.t_str(), "Data", MB_OK);  有这行就会变成乱码,真奇怪!
		String DTX = "";
		String path = GlobalPath;
		String Templatepath;
		//部门信息导出
		if("Section" == TableName)
		{
			ExportQuery->First();
			int allrecord = ExportQuery->RecordCount;
			for(int i = 0; i < 65530; i++)
			{
				DTX += ExportQuery->FieldByName("DM")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("BUMEN")->AsAnsiString.Trim();
				DTX += "\n";
				ExportProgress->Position = i*100/allrecord;
				ExportQuery->Next();
				if(ExportQuery->Eof)
					break;
			}
			Templatepath = path + "\\ExportTemplate\\SectionTemplate.xlt";
	   //		MessageBox(SDIAppForm->Handle, Templatepath.t_str(), "out", MB_OK);

			ExcelApp.OlePropertyGet("workbooks").OleFunction("Open", Templatepath.t_str());
		}

		//班级信息导出
		if("Class" == TableName)
		{
			ExportQuery->First();
			int allrecord = ExportQuery->RecordCount;
			for(int i = 0; i < 65530; i++)
			{
				DTX += ExportQuery->FieldByName("DM")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("BUMEN")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("BANBIE")->AsAnsiString.Trim();
				DTX += "\n";
				ExportProgress->Position = i*100/allrecord;
				ExportQuery->Next();
				if(ExportQuery->Eof)
					break;
			}
			Templatepath = path + "\\ExportTemplate\\ClassTemplate.xlt";
			ExcelApp.OlePropertyGet("workbooks").OleFunction("Open", Templatepath.t_str());
		}

		//组别信息导出
		if("Group" == TableName)
		{
			ExportQuery->First();
			int allrecord = ExportQuery->RecordCount;
			for(int i = 0; i < 65530; i++)
			{
				DTX += ExportQuery->FieldByName("DM")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("BUMEN")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("BANBIE")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("ZUBIE")->AsAnsiString.Trim();
				DTX += "\n";
				ExportProgress->Position = i*100/allrecord;
				ExportQuery->Next();
				if(ExportQuery->Eof)
					break;
			}
			Templatepath = path + "\\ExportTemplate\\GroupTemplate.xlt";
			ExcelApp.OlePropertyGet("workbooks").OleFunction("Open", Templatepath.t_str());
		}

		//卡片信息导出
		if("Card" == TableName)
		{
			ExportQuery->First();
			int allrecord = ExportQuery->RecordCount;
			for(int i = 0; i < 65530; i++)
			{
				DTX += ExportQuery->FieldByName("BH")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("KH")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("BKH")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("XM")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("XB")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("SFZH")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("BM")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("BZ")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("ZB")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("ZW")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("JB")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("RQ")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("TKRQ")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("YJ")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("TYJ")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("ZT")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("GRMM")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("SF_YE")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("SFYEDT")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("SYCS")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("FKSK")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("SF_FL")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("GLF")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("FKJE")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("TKJE")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("SF_KL")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("USERNAME")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("PKEY")->AsAnsiString.Trim();
				DTX += "\n";
				ExportProgress->Position = i*100/allrecord;
				ExportQuery->Next();
				if(ExportQuery->Eof)
					break;
			}
			Templatepath = path + "\\ExportTemplate\\CardTemplate.xlt";
			ExcelApp.OlePropertyGet("workbooks").OleFunction("Open", Templatepath.t_str());
		}

		//存取款信息导出
		if("CK" == TableName)
		{
			ExportQuery->First();
			int allrecord = ExportQuery->RecordCount;
			for(int i = 0; i < 65530; i++)
			{
				DTX += ExportQuery->FieldByName("bh")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("kh")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("sf_ye")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("sf_fl")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("ckxj")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("glf")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("ckje")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("sycs")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("sfrq")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("jyno")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("gzzid")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("sflx")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("CZY")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("pkey")->AsAnsiString.Trim();
				DTX += "\n";
				ExportProgress->Position = i*100/allrecord;
				ExportQuery->Next();
				if(ExportQuery->Eof)
					break;
			}
			Templatepath = path + "\\ExportTemplate\\CKTemplate.xlt";
			ExcelApp.OlePropertyGet("workbooks").OleFunction("Open", Templatepath.t_str());
		}

		//挂失信息导出
		if("GS" == TableName)
		{
			ExportQuery->First();
			int allrecord = ExportQuery->RecordCount;
			for(int i = 0; i < 65530; i++)
			{
				DTX += ExportQuery->FieldByName("BH")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("KH")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("GSRQ")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("USERNAME")->AsAnsiString.Trim();
				DTX += "\n";
				ExportProgress->Position = i*100/allrecord;
				ExportQuery->Next();
				if(ExportQuery->Eof)
					break;
			}
			Templatepath = path + "\\ExportTemplate\\GSTemplate.xlt";
			ExcelApp.OlePropertyGet("workbooks").OleFunction("Open", Templatepath.t_str());
		}

		//费率信息导出
		if("FL" == TableName)
		{
			ExportQuery->First();
			int allrecord = ExportQuery->RecordCount;
			for(int i = 0; i < 65530; i++)
			{
				DTX += ExportQuery->FieldByName("DM")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("FL")->AsAnsiString.Trim();
				DTX += "\n";
				ExportProgress->Position = i*100/allrecord;
				ExportQuery->Next();
				if(ExportQuery->Eof)
					break;
			}
			Templatepath = path + "\\ExportTemplate\\SFFLTemplate.xlt";
			ExcelApp.OlePropertyGet("workbooks").OleFunction("Open", Templatepath.t_str());
		}

		//Pos参数信息导出
		if("POSPARAM" == TableName)
		{
			ExportQuery->First();
			int allrecord = ExportQuery->RecordCount;
			for(int i = 0; i < 65530; i++)
			{
				DTX += ExportQuery->FieldByName("JH")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("STID")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("STNAME")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("GZZID")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("GZZMC")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("CONNECT")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("SFJPORT")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("MAXXF")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("PASSWORD")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("SFJLX")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("JX")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("MAXZZZE")->AsAnsiString.Trim();
				DTX += "\n";
				ExportProgress->Position = i*100/allrecord;
				ExportQuery->Next();
				if(ExportQuery->Eof)
					break;
			}
			Templatepath = path + "\\ExportTemplate\\PosParTemplate.xlt";
			ExcelApp.OlePropertyGet("workbooks").OleFunction("Open", Templatepath.t_str());
		}

		//工作站信息导出
		if("Station" == TableName)
		{
			ExportQuery->First();
			int allrecord = ExportQuery->RecordCount;
			for(int i = 0; i < 65530; i++)
			{
				DTX += ExportQuery->FieldByName("GZZID")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("GZZMC")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("SY")->AsAnsiString.Trim();
				DTX += "\n";
				ExportProgress->Position = i*100/allrecord;
				ExportQuery->Next();
				if(ExportQuery->Eof)
					break;
			}
			Templatepath = path + "\\ExportTemplate\\StationTemplate.xlt";
			ExcelApp.OlePropertyGet("workbooks").OleFunction("Open", Templatepath.t_str());
		}

		//食堂信息导出
		if("ST" == TableName)
		{
			ExportQuery->First();
			int allrecord = ExportQuery->RecordCount;
			for(int i = 0; i < 65530; i++)
			{
				DTX += ExportQuery->FieldByName("STID")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("STNAME")->AsAnsiString.Trim();
				DTX += "\n";
				ExportProgress->Position = i*100/allrecord;
				ExportQuery->Next();
				if(ExportQuery->Eof)
					break;
			}
			Templatepath = path + "\\ExportTemplate\\STNameTemplate.xlt";
			ExcelApp.OlePropertyGet("workbooks").OleFunction("Open", Templatepath.t_str());
		}

		//系统设置信息导出
		if("XTSET" == TableName)
		{
			ExportQuery->First();
			int allrecord = ExportQuery->RecordCount;
			for(int i = 0; i < 65530; i++)
			{
				DTX += ExportQuery->FieldByName("SYSID")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("INITDATE")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("INIT")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("ICTYPE")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("FKYJ")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("TKYJ")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("DWMC")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("DWMM")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("MAXKH")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("BFPATH")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("BFRQ")->AsAnsiString.Trim();
				DTX += "\n";
				ExportProgress->Position = i*100/allrecord;
				ExportQuery->Next();
				if(ExportQuery->Eof)
					break;
			}
			Templatepath = path + "\\ExportTemplate\\SysSetTemplate.xlt";
			ExcelApp.OlePropertyGet("workbooks").OleFunction("Open", Templatepath.t_str());
		}

		//系统用户信息导出
		if("SYSUSER" == TableName)
		{
			ExportQuery->First();
			int allrecord = ExportQuery->RecordCount;
			for(int i = 0; i < 65530; i++)
			{
				DTX += ExportQuery->FieldByName("USERID")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("USERNAME")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("PASSWORD")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("GROUPID")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("GROUPNAME")->AsAnsiString.Trim();
				DTX += "\n";
				ExportProgress->Position = i*100/allrecord;
				ExportQuery->Next();
				if(ExportQuery->Eof)
					break;
			}
			Templatepath = path + "\\ExportTemplate\\SysUserTemplate.xlt";
			ExcelApp.OlePropertyGet("workbooks").OleFunction("Open", Templatepath.t_str());
		}

		//消费明细信息导出
		if("MX" == TableName)
		{
			ExportQuery->First();
			int allrecord = ExportQuery->RecordCount;
			for(int i = 0; i < 65530; i++)
			{
				DTX += ExportQuery->FieldByName("BH")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("KH")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("SF_YE")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("SFJE")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("SYCS")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("SFRQ")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("JYNO")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("GZZID")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("SFLX")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("CZY")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("SCRQ")->AsAnsiString.Trim();
				DTX += "\n";
				ExportProgress->Position = i*100/allrecord;
				ExportQuery->Next();
				if(ExportQuery->Eof)
					break;
			}
			Templatepath = path + "\\ExportTemplate\\MXTemplate.xlt";
			ExcelApp.OlePropertyGet("workbooks").OleFunction("Open", Templatepath.t_str());
		}

        //错误信息导出
		if("ERRDATA" == TableName)
		{
			ExportQuery->First();
			int allrecord = ExportQuery->RecordCount;
			for(int i = 0; i < 65530; i++)
			{
				DTX += ExportQuery->FieldByName("BH")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("KH")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("SF_YE")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("SFJE")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("SYCS")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("SFRQ")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("JYNO")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("GZZID")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("SFLX")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("ERRMSG")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("SCRQ")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("PKEY")->AsAnsiString.Trim();
				DTX += "\n";
				ExportProgress->Position = i*100/allrecord;
				ExportQuery->Next();
				if(ExportQuery->Eof)
					break;
			}
			Templatepath = path + "\\ExportTemplate\\ERRDATATemplate.xlt";
			ExcelApp.OlePropertyGet("workbooks").OleFunction("Open", Templatepath.t_str());
        }

        //级别补贴信息导出
        if("BTJB" == TableName)
        {
        	ExportQuery->First();
			int allrecord = ExportQuery->RecordCount;
			for(int i = 0; i < 65530; i++)
			{
            	DTX += ExportQuery->FieldByName("BH")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("KH")->AsAnsiString.Trim();
				DTX += "\t";
                DTX += ExportQuery->FieldByName("Bonus")->AsAnsiString.Trim();
				DTX += "\t";
                DTX += ExportQuery->FieldByName("CreateDate")->AsAnsiString.Trim();
				DTX += "\t";
                DTX += ExportQuery->FieldByName("UserName")->AsAnsiString.Trim();
				DTX += "\t";
                DTX += ExportQuery->FieldByName("DownDate")->AsAnsiString.Trim();
				DTX += "\n";
            	ExportProgress->Position = i*100/allrecord;
				ExportQuery->Next();
				if(ExportQuery->Eof)
                	break;
            }
            Templatepath = path + "\\ExportXLSTemplate\\BTJBTemplate.xlt";
			ExcelApp.OlePropertyGet("workbooks").OleFunction("Open", Templatepath.t_str());
        }

        //消费次数补贴信息导出
        if("BTCS" == TableName)
        {
        	ExportQuery->First();
			int allrecord = ExportQuery->RecordCount;
			for(int i = 0; i < 65530; i++)
			{
            	DTX += ExportQuery->FieldByName("BH")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("KH")->AsAnsiString.Trim();
				DTX += "\t";
                DTX += ExportQuery->FieldByName("Bonus")->AsAnsiString.Trim();
				DTX += "\t";
                DTX += ExportQuery->FieldByName("ZW")->AsAnsiString.Trim();
				DTX += "\t";
				DTX += ExportQuery->FieldByName("CreateDate")->AsAnsiString.Trim();
				DTX += "\t";
                DTX += ExportQuery->FieldByName("February")->AsAnsiString.Trim();
				DTX += "\t";
                DTX += ExportQuery->FieldByName("March")->AsAnsiString.Trim();
				DTX += "\t";
                DTX += ExportQuery->FieldByName("April")->AsAnsiString.Trim();
				DTX += "\t";
                DTX += ExportQuery->FieldByName("May")->AsAnsiString.Trim();
				DTX += "\t";
                DTX += ExportQuery->FieldByName("June")->AsAnsiString.Trim();
				DTX += "\t";
                DTX += ExportQuery->FieldByName("July")->AsAnsiString.Trim();
				DTX += "\t";
                DTX += ExportQuery->FieldByName("August")->AsAnsiString.Trim();
				DTX += "\t";
                DTX += ExportQuery->FieldByName("September")->AsAnsiString.Trim();
				DTX += "\t";
                DTX += ExportQuery->FieldByName("October")->AsAnsiString.Trim();
				DTX += "\t";
                DTX += ExportQuery->FieldByName("November")->AsAnsiString.Trim();
				DTX += "\t";
                DTX += ExportQuery->FieldByName("December")->AsAnsiString.Trim();
				DTX += "\t";
                DTX += ExportQuery->FieldByName("UserName")->AsAnsiString.Trim();
				DTX += "\t";
                DTX += ExportQuery->FieldByName("DownDate")->AsAnsiString.Trim();
				DTX += "\n";
            	ExportProgress->Position = i*100/allrecord;
				ExportQuery->Next();
				if(ExportQuery->Eof)
                	break;
            }
            Templatepath = path + "\\ExportXLSTemplate\\BTCSTemplate.xlt";
			ExcelApp.OlePropertyGet("workbooks").OleFunction("Open", Templatepath.t_str());
        }

		Variant WB = ExcelApp.OlePropertyGet("ActiveWorkBook");

		Variant ST = WB.OlePropertyGet("Sheets", 1);

		Variant RE = ST.OlePropertyGet("Range", "A2").OleFunction("Select");

		Clipboard()->Clear();
		Clipboard()->SetTextBuf(DTX.c_str());
		ST.OleFunction("Paste");
		Clipboard()->Clear();

		ExcelApp.OlePropertyGet("Columns").OleFunction("AutoFit");

		WB.OleFunction("SaveAs", ExportFileName.t_str());

		ExcelApp.OleFunction("Quit");

		ExcelApp = Unassigned;

		ExportQuery->Close();

        ExportProgress->Position = 100;
		MessageBox(SDIAppForm->Handle, "数据已完成导出!", "Successfully!", MB_OK|MB_ICONINFORMATION);
		ExportProgress->Position = 0;
		ExportBTN->Enabled = false;
		ExitBTN->Enabled = true;
		return;
	}
	else
	{
		MessageBox(SDIAppForm->Handle, "错误:没有符合查询条件的资料!", "Error in Query!", MB_OK|MB_ICONERROR);
		ExcelApp.OleFunction("Quit");
		ExcelApp = Unassigned;
		ExportQuery->Close();
		ExportBTN->Enabled = false;
		ExitBTN->Enabled = true;
		return;
	}
}
Example #12
0
void TForm1::WriteClassifications(Variant &vSheet, std::vector<exlClass> &classes)
{
	lblStatus->Caption = "Приступаю к сортировке классификаций...";
	Log->Lines->Add("Приступаю к сортировке классификаций...");
	int nReplaced = 1;

	while(nReplaced > 0) {
		nReplaced = 0;
		for (unsigned int i = 0; i < classes.size()-1; i++) {
		   if (classes[i].Name.UpperCase() > classes[i+1].Name.UpperCase()) {
			   exlClass cl = classes[i];
			   classes[i] = classes[i+1];
			   classes[i+1] = cl;
			   nReplaced++;
		   }
		}
	}
	Log->Lines->Add("Отсортировано!");

	int nRowsCount = vSheet.OlePropertyGet("Cells").OlePropertyGet("Rows").OlePropertyGet("Count");
	int nLastRow1 = vSheet.OlePropertyGet("Cells", nRowsCount, 1).OlePropertyGet("End", xlUp).OlePropertyGet("Row");
	int nLastRow2 = vSheet.OlePropertyGet("Cells", nRowsCount, 2).OlePropertyGet("End", xlUp).OlePropertyGet("Row");
	int nLastRow3 = vSheet.OlePropertyGet("Cells", nRowsCount, 3).OlePropertyGet("End", xlUp).OlePropertyGet("Row");
	int nLastRow4 = vSheet.OlePropertyGet("Cells", nRowsCount, 4).OlePropertyGet("End", xlUp).OlePropertyGet("Row");

	int nLastRow = 0;
	nLastRow = std::max(nLastRow, nLastRow1);
	nLastRow = std::max(nLastRow, nLastRow2);
	nLastRow = std::max(nLastRow, nLastRow3);
	nLastRow = std::max(nLastRow, nLastRow4);

	lblStatus->Caption = "Произвожу очистку классификаций в файле...";
	Log->Lines->Add("Произвожу очистку классификаций в файле");
	ProgressBar1->Max = nLastRow;
	ProgressBar1->Min = 0;
	for (int i = 1; i < nLastRow; i++) {
		ProgressBar1->Position = i;
		Application->ProcessMessages();
		vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",i+1,1).OlePropertySet("Value", WideString(""));
		vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",i+1,2).OlePropertySet("Value", WideString(""));
		vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",i+1,3).OlePropertySet("Value", WideString(""));
		vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",i+1,4).OlePropertySet("Value", WideString(""));
	}
	lblStatus->Caption = "Приступаю к записи классификаций в файл...";
	Log->Lines->Add("Приступаю к записи в файл " + IntToStr((int)classes.size()));
	ProgressBar1->Max = classes.size();
	ProgressBar1->Min = 0;
	vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",1,1).OlePropertySet("Value", WideString("Наименование"));
	vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",1,2).OlePropertySet("Value", WideString("Класс"));
	vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",1,3).OlePropertySet("Value", WideString("Комментарий"));
	vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",1,4).OlePropertySet("Value", WideString("Месяца"));
	for (unsigned int i = 0; i < classes.size(); i++) {
		exlClass cl = classes[i];
		ProgressBar1->Position = i;
		vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",i+2,1).OlePropertySet("Value", WideString(cl.Name));
		vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",i+2,2).OlePropertySet("Value", WideString(cl.Class));
		vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",i+2,3).OlePropertySet("Value", WideString(cl.Comment));
		vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",i+2,4).OlePropertySet("Value", WideString(cl.Monthes));
	}
	lblStatus->Caption = "";
}
Example #13
0
//---------------------------------------------------------------------------
void __fastcall TBTMXExportThread::Execute()
{
	//---- Place thread code here ----
    ValidExportBTN->Enabled = false;
    ValidPreviewBTN->Enabled = false;

	Variant ExcelApp;
	try
	{
		ExcelApp = CreateOleObject("Excel.Application");
	}
	catch(...)
	{
		MessageBox(SDIAppForm->Handle, "错误:您的系统中可能没有安装Excel!", "Error in launch Excel!", MB_OK|MB_ICONERROR);
		ValidExportBTN->Enabled = true;
		ValidPreviewBTN->Enabled = true;
		return;
	}

    String DTX = "";
//    ValidADOQuery->Open();
    ValidADOQuery->First();

    int allcount = ValidADOQuery->RecordCount;
    int currentcount = 0;
    Validprogress->Position = 0;

    while(!ValidADOQuery->Eof)
    {
        Validprogress->Position = currentcount*100/allcount;
        currentcount++;

		DTX += ValidADOQuery->FieldByName("BH")->AsAnsiString.Trim();
        DTX += "\t";
		DTX += ValidADOQuery->FieldByName("KH")->AsAnsiString.Trim();
        DTX += "\t";
		DTX += ValidADOQuery->FieldByName("SF_YE")->AsAnsiString.Trim();
        DTX += "\t";
		DTX += ValidADOQuery->FieldByName("SFJE")->AsAnsiString.Trim();
        DTX += "\t";
		DTX += ValidADOQuery->FieldByName("SYCS")->AsAnsiString.Trim();
        DTX += "\t";
		DTX += ValidADOQuery->FieldByName("SFRQ")->AsAnsiString.Trim();
        DTX += "\t";
		DTX += ValidADOQuery->FieldByName("JYNO")->AsAnsiString.Trim();
        DTX += "\t";
//        DTX += ValidADOQuery->FieldByName("GZZID")->AsAnsiString;
//        DTX += "\t";
		DTX += ValidADOQuery->FieldByName("SFLX")->AsAnsiString.Trim();
        DTX += "\t";
		DTX += ValidADOQuery->FieldByName("CZY")->AsAnsiString.Trim();
        DTX += "\t";
		DTX += ValidADOQuery->FieldByName("SCRQ")->AsAnsiString.Trim();
        DTX += "\n";
        ValidADOQuery->Next();
    }

    String TempPath = GlobalPath;

    TempPath += "\\ExportTemplate\\BTMXTemplate.xlt";

    ExcelApp.OlePropertyGet("workbooks").OleFunction("Open", TempPath.t_str());

	Variant WB = ExcelApp.OlePropertyGet("ActiveWorkBook");

    Variant ST = WB.OlePropertyGet("Sheets", 1);

    ST.OlePropertyGet("Cells",2,2).OlePropertySet("Value", ValidBeginTimeStr.t_str());
    ST.OlePropertyGet("Cells",2,7).OlePropertySet("Value", ValidEndTimeStr.t_str());
    ST.OlePropertyGet("Cells",3,2).OlePropertySet("Value", ValidKHStr.t_str());
    ST.OlePropertyGet("Cells",3,7).OlePropertySet("Value", ValidBHStr.t_str());
    ST.OlePropertyGet("Cells",4,2).OlePropertySet("Value", ValidJHStr.t_str());
    ST.OlePropertyGet("Cells",4,7).OlePropertySet("Value", ValidDDStr.t_str());

    Variant RE = ST.OlePropertyGet("Range", "A7").OleFunction("Select");
   	Clipboard()->Clear();
    Clipboard()->SetTextBuf(DTX.c_str());
    ST.OleFunction("Paste");
    Clipboard()->Clear();

    ExcelApp.OlePropertyGet("Columns").OleFunction("AutoFit");

    WB.OleFunction("SaveAs", Validfilename.t_str());

    ExcelApp.OleFunction("Quit");

    ExcelApp = Unassigned;

    ValidADOQuery->Close();
    Validprogress->Position = 100;
    ValidExportBTN->Enabled = true;
    ValidPreviewBTN->Enabled = true;
	MessageBox(SDIAppForm->Handle, "数据导出完毕!", "Successfully!", MB_OK|MB_ICONINFORMATION);
}
//---------------------------------------------------------------------------
void __fastcall TStopConsumeExportThread::Execute()
{
	//---- Place thread code here ----
    ValidEXBTN->Enabled = false;
    ValidPreBTN->Enabled = false;
    ValidEBTN->Enabled = false;

    Variant ExcelApp;
	try
	{
		ExcelApp = CreateOleObject("Excel.Application");
	}
	catch(...)
	{
		MessageBox(StopConsumeShowFRM->Handle, "错误:您的系统中可能没有安装Excel!", "Error in launch Excel!", MB_OK|MB_ICONERROR);
        ValidEXBTN->Enabled = true;
        ValidPreBTN->Enabled = true;
        ValidEBTN->Enabled = true;
		return;
	}

    ValidQuery->Open();
    String DTX = "";
    String path = GlobalPath;
    String Templatepath;
    ValidQuery->First();
    int allrecord = ValidQuery->RecordCount;
    for(int i = 0; i <65531; i++)
    {
        DTX += ValidQuery->FieldByName("KH")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("BH")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("XM")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("SF_YE")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("XB")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("BM")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("BZ")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("ZB")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("ZW")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("ZT")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("RQ")->AsAnsiString.Trim();
        DTX += "\n";
        Validprogress->Position = i*100/allrecord;
        ValidQuery->Next();
        if(ValidQuery->Eof)
            break;
    }

    Templatepath = path + "\\ExportXLSTemplate\\STTemplate.xlt";
    ExcelApp.OlePropertyGet("workbooks").OleFunction("Open", Templatepath.t_str());
    Variant WB = ExcelApp.OlePropertyGet("ActiveWorkBook");
    Variant ST = WB.OlePropertyGet("Sheets", 1);

    //设置报头信息
    String tmpoutstr = "";
    ST.OlePropertyGet("Cells",2,2).OlePropertySet("Value", Validcheckstr.t_str());
    ST.OlePropertyGet("Cells",2,8).OlePropertySet("Value", ValidCZYstr.t_str());

    Variant RE = ST.OlePropertyGet("Range", "A5").OleFunction("Select");
    Clipboard()->Clear();
    Clipboard()->SetTextBuf(DTX.c_str());
    ST.OleFunction("Paste");
    Clipboard()->Clear();

    ExcelApp.OlePropertyGet("Columns").OleFunction("AutoFit");
    WB.OleFunction("SaveAs", Validsavepath.t_str());
    ExcelApp.OleFunction("Quit");
    ExcelApp = Unassigned;
    Validprogress->Position = 100;
    MessageBox(StopConsumeShowFRM->Handle, "数据已完成导出!", "Successfully!", MB_OK|MB_ICONINFORMATION);

    ValidEXBTN->Enabled = true;
    ValidPreBTN->Enabled = true;
    ValidEBTN->Enabled = true;
}
Example #15
0
void TForm1::setColor(Variant &vSheet, int nRow, int nCol, int nColor) {
	vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,nCol).OlePropertyGet("Interior").OlePropertySet("Color", nColor);
}
Example #16
0
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
	edtFile->Text = "";
	m_strFileName = "";
	if (OpenDialog1->Execute()) {
		m_bBackup = false;

		UnicodeString strFileName = OpenDialog1->FileName;
		if (! FileExists (strFileName)) {
			MessageBox (Handle, UnicodeString(L"Файл '" + strFileName + L"' не существует").c_str(), L"prompt", MB_OK);
			edtFile->Text = "";
			return;
		}

		edtFile->Text = strFileName;
		// TODO: create backup now or later?
		// TODO: INIT OPERATIONS
		// TODO: scan month
		Variant var_Book,var_Sheet,var_Cell;

		Variant app = Variant::CreateObject("Excel.Application");
		// app.OlePropertySet("Visible",false);
		Variant excel;
		try {
			excel = app.OlePropertyGet("Workbooks").OleFunction("Open", WideString(strFileName.c_str()));
		} catch (...) {
			MessageBox (Handle, UnicodeString(L"Не получается открыть файл '" + strFileName + L"' как excel").c_str(), L"prompt", MB_OK);
			app.OleProcedure("Quit");
			edtFile->Text = "";
			return;
		}

		Log->Lines->Add("Файл загружен производиться анализ");
		Variant vSheets = excel.OlePropertyGet("Worksheets");

		m_nPageClassification = 0;
		m_vMonth.clear();
		cmbMonth->Items->Clear();
		cmbMonth->Items->Add("");
		int nSheets = vSheets.OlePropertyGet("Count");
		Log->Lines->Add("Всего листов: " + IntToStr(nSheets));
		for (int i = 0; i < nSheets; i++) {
			Variant vSheet = vSheets.OlePropertyGet("Item",i+1);
			UnicodeString str = vSheet.OlePropertyGet("Name");
			if (str.UpperCase() == UnicodeString("классификации").UpperCase()) {
				m_nPageClassification = i+1;
			};
			if (str.UpperCase().Pos("МЕСЯЦ ") > 0) {
				cmbMonth->Items->Add(str);
				exlSheet s;
				s.Number = i+1;
				s.Name = str;
				m_vMonth.push_back(s);
			}
			Log->Lines->Add("Лист " + IntToStr(i+1) + ": " + str);
		}

		if (m_nPageClassification == 0) {
			MessageBox (Handle, UnicodeString(L"Не найден лист 'классификации'").c_str(), L"prompt", MB_OK);
			app.OleProcedure("Quit");
			edtFile->Text = "";
			return;
		}

		if (m_vMonth.size() == 0) {
			MessageBox (Handle, UnicodeString(L"Не найден ни один лист с 'месяц xx'").c_str(), L"prompt", MB_OK);
			app.OleProcedure("Quit");
			edtFile->Text = "";
			return;
        }
		app.OleProcedure("Quit");
		m_strFileName = strFileName;
    }
}
//---------------------------------------------------------------------------
// Проверяет, существует ли атрибут
Variant MSXMLWorks::GetAttribute(Variant Node, AnsiString AttributeName)
{
    return Node.OlePropertyGet("attributes").OleFunction("getNamedItem", AttributeName);
    //return attribute.IsEmpty();
}
//---------------------------------------------------------------------------
// Возврщает первый дочерний узел
Variant __fastcall MSXMLWorks::GetFirstNode(Variant Node)
{
    return Node.OlePropertyGet("firstChild");
}
Example #19
0
void __fastcall TForm1::actRedesignClassificationsExecute(TObject *Sender)
{
	lblStatus->Caption = "";
	if(!MakeBackup()) {
		Log->Lines->Add("Не удалось создать резервную копию файла");
		lblStatus->Caption = "Ошибка: Не удалось создать резервную копию файла";
		return;
	}
	m_strRecomendations = "";

	lblStatus->Caption = "Открываю файл на чтение...";
	Variant app = Variant::CreateObject("Excel.Application");
    app.OlePropertySet("Visible", true);
	Variant excel = app.OlePropertyGet("Workbooks").OleFunction("Open", WideString(m_strFileName.c_str()));
	Variant vSheets = excel.OlePropertyGet("Worksheets");
	Variant vSheet = vSheets.OlePropertyGet("Item",m_nPageClassification);
	UnicodeString strPageName = vSheet.OlePropertyGet("Name");
	if (strPageName.UpperCase() != UnicodeString("классификации").UpperCase()) {
		app.OleProcedure("Quit");
		MessageBox (Handle, UnicodeString(L"Не верное имя страницы").c_str(), L"prompt", MB_OK);
		lblStatus->Caption = "Ошибка: Не верное имя страницы";
		return;
	};

	std::vector<exlClass> classes;
	ReadClassifications(vSheet, classes);

	std::vector<exlMonth> months;
	for (unsigned int i = 0; i < m_vMonth.size(); i++) {
		int nMonthPage = m_vMonth[i].Number;
		Variant vSheetMonth = vSheets.OlePropertyGet("Item",nMonthPage);
		ReadMonth(vSheetMonth, months);
	}
//	Log->Lines->Add("Обновляю линки." + IntToStr((int)months.size()));

	int nAll = classes.size() * months.size();
	Log->Lines->Add("Всего записей в месяцах: " + IntToStr((int)months.size()));
	std::vector<exlClass> newclasses;
	int nRemovedClasses = 0;
	ProgressBar1->Max = nAll;
	ProgressBar1->Min = 0;
	ProgressBar1->Position = 0;

	lblStatus->Caption = "Поиск наименований которые отсутвуют в месяцах...";
	Log->Lines->Add("Произвожу поиск наименований которые отсутвуют в месяцах...");
	for (unsigned int iC = 0; iC < classes.size(); iC++) {
		exlClass cl = classes[iC];
		cl.Monthes = "";
		UnicodeString name = classes[iC].Name.UpperCase();
		int nCount = 0;
		for (unsigned int iM = 0; iM < months.size(); iM++) {
			ProgressBar1->Position++;
			Application->ProcessMessages();
			UnicodeString name2 = months[iM].Name.UpperCase();
			if (name == name2) {
			   nCount++;
			   if (cl.Monthes.Pos(months[iM].Month) < 1) {
				  cl.Monthes += months[iM].Month + ";";
			   }
			}
		}
		if (nCount > 0) {
			newclasses.push_back(cl);
		} else {
			nRemovedClasses++;
			Log->Lines->Add("\tНаименование '" + cl.Name + "' - нигде не встречается и будет удалено из классификаций");
		}
	}
	Log->Lines->Add(" ** ");

	nAll = newclasses.size() * months.size();
	ProgressBar1->Max = nAll;
	ProgressBar1->Min = 0;
	ProgressBar1->Position = 0;
	int nAddClasses = 0;
	lblStatus->Caption = "Поиск наименований которые отсутвуют в списке классификаций...";
	Log->Lines->Add("Произвожу поиск наименований которые отсутвуют в списке классификаций...");
	for (unsigned int iM = 0; iM < months.size(); iM++) {
		UnicodeString name = months[iM].Name.UpperCase();
		int nCount = 0;
		for (unsigned int iC = 0; iC < newclasses.size(); iC++) {
			ProgressBar1->Position++;
			Application->ProcessMessages();
			UnicodeString name2 = newclasses[iC].Name.UpperCase();
			if (name == name2) {
			   nCount++;
			}
		}
		if (nCount == 0) {
			Log->Lines->Add("\tНаименование '" + months[iM].Name + "' - будет добавлено в классификации");
			exlClass cl;
			cl.Name = months[iM].Name;
			cl.Class = m_sUnknownClass;
			cl.Monthes += months[iM].Month + ";";
			newclasses.push_back(cl);
			nAddClasses++;

			nAll = newclasses.size() * months.size();
			ProgressBar1->Max = nAll;
		}
	}
	Log->Lines->Add("Будет удалено классификаций: " + IntToStr(nRemovedClasses));
    Log->Lines->Add("Будет добавлено классификаций: " + IntToStr(nAddClasses));
	Log->Lines->Add("Всего классификаций: " + IntToStr((int)(newclasses.size())));


	WriteClassifications(vSheet, newclasses);

	lblStatus->Caption = "Сохраняю файл...";
	Log->Lines->Add("Сохраняю файл...");
	try {
		app.OlePropertySet("DisplayAlerts",false);
		excel.OleProcedure("SaveAs", WideString(m_strFileName.c_str()));
		Log->Lines->Add("Данные сохранены!");
	} catch (...) {
		lblStatus->Caption = "Ошибка: Пожалуйста закройте все открытые копии файла и повторите операцию";
		Log->Lines->Add("Ошибка: Пожалуйста закройте все открытые копии файла и повторите операцию");
	}
    ProgressBar1->Position = 0;
	app.OleProcedure("Quit");
	lblStatus->Caption = "";
}
Example #20
0
void TForm1::setBorders(Variant &vSheet, int nRow, int nCol) {
	vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,nCol).OlePropertyGet("Borders").OlePropertySet("LineStyle", xlContinuous);
}
Example #21
0
void __fastcall TForm1::actCalcClassificationExecute(TObject *Sender)
{
	if(!MakeBackup()) {
		Log->Lines->Add("Не удалось создать резервную копию файла");
		return;
	}

	Variant app = Variant::CreateObject("Excel.Application");
	app.OlePropertySet("Visible", true);
	Variant excel = app.OlePropertyGet("Workbooks").OleFunction("Open", WideString(m_strFileName.c_str()));
	Variant vSheets = excel.OlePropertyGet("Worksheets");
	Variant vSheet = vSheets.OlePropertyGet("Item",m_nPageClassification);
	UnicodeString strPageName = vSheet.OlePropertyGet("Name");
	if (strPageName.UpperCase() != UnicodeString("классификации").UpperCase()) {
	   app.OleProcedure("Quit");
	   MessageBox (Handle, UnicodeString(L"Не верное имя страницы").c_str(), L"prompt", MB_OK);
	   return;
	};

	std::vector<exlClass> classes;
	ReadClassifications(vSheet, classes);

	std::vector<exlMonth> months;
	Variant vSheetMonth;
	double fSumSum = 0;
	for (unsigned int i = 0; i < m_vMonth.size(); i++) {
		if (cmbMonth->Text == m_vMonth[i].Name) {
			int nMonthPage = m_vMonth[i].Number;
			vSheetMonth = vSheets.OlePropertyGet("Item", nMonthPage);
			ReadMonth(vSheetMonth, months);
			ReadMonthSum(vSheetMonth, fSumSum);
		}
	}

	Log->Lines->Add("Произвожу расчет...");
    ProgressBar1->Max = months.size();
	ProgressBar1->Min = 0;
	double nSumHand = 0;

	std::vector<exlSumClass> vSumClasses;
	for (unsigned int i = 0; i < months.size(); i++) {
		ProgressBar1->Position = i;
		int nFound = 0;
		nSumHand += months[i].Price;
		for (unsigned int iC = 0; iC < classes.size(); iC++) {
			if (nFound == 0 && classes[iC].Name.UpperCase() == months[i].Name.UpperCase()) {
				months[i].Class = classes[iC].Class;
				months[i].LinkToClassification = createHyperLinkToClassification(classes, iC);
				nFound++;
			}
		}
		if (nFound == 0) {
			months[i].Class = m_sUnknownClass;
		}

		nFound = 0;
		for (unsigned int iC = 0; iC < vSumClasses.size(); iC++) {
			if (vSumClasses[iC].Name.UpperCase() == months[i].Class.UpperCase()) {
				vSumClasses[iC].Sum += months[i].Price;
				nFound++;
			}
		}
		if (nFound == 0) {
		   exlSumClass sm;
		   sm.Name = months[i].Class;
		   sm.Sum = months[i].Price;
		   vSumClasses.push_back(sm);
		}
	}

	/*for (unsigned int i = 0; i < vSumClasses.size(); i++) {
		Log->Lines->Add(vSumClasses[i].Name + " = " + FloatToStr(vSumClasses[i].Sum));
	}*/

	Log->Lines->Add("Готово.");

	Log->Lines->Add("Сортирую классификации...");
	ProgressBar1->Max = 100;
	ProgressBar1->Min = 0;

	{
		int nPermutation = 1;
		while (nPermutation > 0) {
			nPermutation = 0;
			for (unsigned int iC = 0; iC < vSumClasses.size()-1; iC++) {
				ProgressBar1->Position = (ProgressBar1->Position+1) % ProgressBar1->Max;
				Application->ProcessMessages();
				if (vSumClasses[iC].Name.UpperCase() > vSumClasses[iC+1].Name.UpperCase()) {
					exlSumClass buf = vSumClasses[iC];
					vSumClasses[iC] = vSumClasses[iC+1];
					vSumClasses[iC+1] = buf;
					nPermutation++;
				}
			}
		}
		ProgressBar1->Position = 0;
    }
	Log->Lines->Add("Готово.");

	Log->Lines->Add("Очистка старых данных");
	ProgressBar1->Max = 100;
	ProgressBar1->Min = 0;

	// clear sum classes, 11,12
	{
		bool b = true;
		int nRow = 1;
		while (b) {
			b = false;
			nRow++;
			ProgressBar1->Position = (ProgressBar1->Position+1) % ProgressBar1->Max;
			Application->ProcessMessages();

			vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,11).OleProcedure("ClearFormats");
			vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,12).OleProcedure("ClearFormats");

			UnicodeString sValue11 = vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,11).OlePropertyGet("Value");
			UnicodeString sValue12 = vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,12).OlePropertyGet("Value");

			clearCell(vSheetMonth, nRow, 11);
			clearCell(vSheetMonth, nRow, 12);

			if (sValue12.Trim().Length() > 0 || sValue11.Trim().Length() > 0) {
				b = true;
			}
		}
		ProgressBar1->Position = 0;
	}

	// clear 14,15,16,17
	{
		bool b = true;
		int nRow = 1;
		while (b) {
			b = false;
			nRow++;
			ProgressBar1->Position = (ProgressBar1->Position+1) % ProgressBar1->Max;
			Application->ProcessMessages();

			vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,14).OleProcedure("ClearFormats");
			vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,15).OleProcedure("ClearFormats");
			vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,16).OleProcedure("ClearFormats");
			vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,17).OleProcedure("ClearFormats");

			UnicodeString sValue14 = vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,14).OlePropertyGet("Value");
			UnicodeString sValue15 = vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,15).OlePropertyGet("Value");
			UnicodeString sValue16 = vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,16).OlePropertyGet("Value");
			UnicodeString sValue17 = vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,17).OlePropertyGet("Value");

			clearCell(vSheetMonth, nRow, 14);
			clearCell(vSheetMonth, nRow, 15);
			clearCell(vSheetMonth, nRow, 16);
			clearCell(vSheetMonth, nRow, 17);

			if (
				sValue14.Trim().Length() > 0
				|| sValue15.Trim().Length() > 0
				|| sValue16.Trim().Length() > 0
				|| sValue17.Trim().Length() > 0
			) {
				b = true;
			}
		}
		ProgressBar1->Position = 0;
	}


	Log->Lines->Add("Запись новых данных");
	{
		double nSum = 0;
		int nRow = 2;
		vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,11).OlePropertySet("Value", WideString("Класс"));
		vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,12).OlePropertySet("Value", WideString("Сумма"));
		vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,11).OlePropertyGet("Font").OlePropertySet("Bold", true);
		vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,12).OlePropertyGet("Font").OlePropertySet("Bold", true);
		vSheetMonth.OlePropertyGet("Columns", WideString("K")).OlePropertySet("ColumnWidth", 20);
		vSheetMonth.OlePropertyGet("Columns", WideString("L")).OlePropertySet("ColumnWidth", 15);
		setBorders(vSheetMonth, nRow, 11);
		setBorders(vSheetMonth, nRow, 12);
		setColor(vSheetMonth, nRow, 11, RGBToInt(240, 230, 140));
		setColor(vSheetMonth, nRow, 12, RGBToInt(240, 230, 140));

		ProgressBar1->Max = vSumClasses.size();
		ProgressBar1->Min = 0;
		for (unsigned int i = 0; i < vSumClasses.size(); i++) {
			nRow++;
			ProgressBar1->Position = i;
			nSum += vSumClasses[i].Sum;
			vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,11).OlePropertySet("Value", WideString(vSumClasses[i].Name));
			vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,12).OlePropertySet("Value", WideString(vSumClasses[i].Sum));

			vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,12).OlePropertySet("NumberFormat", WideString(m_strNumberFormat));

			setBorders(vSheetMonth, nRow, 11);
			setBorders(vSheetMonth, nRow, 12);
		}
		nRow++;
		ProgressBar1->Position = 0;

		vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,11).OlePropertySet("Value", WideString("Итого:"));
		vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,12).OlePropertySet("Value", WideString(nSum));
		vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,12).OlePropertySet("NumberFormat", WideString(m_strNumberFormat));

		nRow++;

		vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,11).OlePropertySet("Value", WideString("Сумма сумм по дням:"));
		vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,12).OlePropertySet("Value", WideString(fSumSum));
		vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,12).OlePropertySet("NumberFormat", WideString(m_strNumberFormat));
	}

	{
		double nSum = 0;
		int nRow = 2;
		vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,14).OlePropertySet("Value", WideString("Класс"));
		vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,15).OlePropertySet("Value", WideString("Наименование"));
		vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,16).OlePropertySet("Value", WideString("Цена"));
		vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,17).OlePropertySet("Value", WideString("Ссылка"));

		vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,14).OlePropertyGet("Font").OlePropertySet("Bold", true);
		vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,15).OlePropertyGet("Font").OlePropertySet("Bold", true);
		vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,16).OlePropertyGet("Font").OlePropertySet("Bold", true);
		vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,17).OlePropertyGet("Font").OlePropertySet("Bold", true);

		vSheetMonth.OlePropertyGet("Columns", WideString("N")).OlePropertySet("ColumnWidth", 20);
		vSheetMonth.OlePropertyGet("Columns", WideString("O")).OlePropertySet("ColumnWidth", 50);
		vSheetMonth.OlePropertyGet("Columns", WideString("P")).OlePropertySet("ColumnWidth", 15);
		vSheetMonth.OlePropertyGet("Columns", WideString("Q")).OlePropertySet("ColumnWidth", 50);

		setBorders(vSheetMonth, nRow, 14);
		setBorders(vSheetMonth, nRow, 15);
		setBorders(vSheetMonth, nRow, 16);
		setBorders(vSheetMonth, nRow, 17);

		setColor(vSheetMonth, nRow, 14, RGBToInt(240, 230, 140));
		setColor(vSheetMonth, nRow, 15, RGBToInt(240, 230, 140));
		setColor(vSheetMonth, nRow, 16, RGBToInt(240, 230, 140));
		setColor(vSheetMonth, nRow, 17, RGBToInt(240, 230, 140));

		ProgressBar1->Max = months.size();
		ProgressBar1->Min = 0;
		for (unsigned int i = 0; i < months.size(); i++) {
			nRow++;
			ProgressBar1->Position = i;
			nSum += months[i].Price;

			vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,14).OlePropertySet("Value", WideString(months[i].Class));
			vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,15).OlePropertySet("Value", WideString(months[i].Name));
			vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,16).OlePropertySet("Value", WideString(months[i].Price));
			vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,16).OlePropertySet("NumberFormat", WideString(m_strNumberFormat));

			if (months[i].Price < 0) {
				setColor(vSheetMonth, nRow, 16, RGBToInt(240, 230, 140));
			}


			// TODO: check linkt to classification
			// vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,17).OlePropertySet("Value", WideString(months[i].LinkToClassification.c_str()));

			setBorders(vSheetMonth, nRow, 14);
			setBorders(vSheetMonth, nRow, 15);
			setBorders(vSheetMonth, nRow, 16);
			setBorders(vSheetMonth, nRow, 17);
		}
		nRow++;
		ProgressBar1->Position = 0;

		vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,14).OlePropertySet("Value", WideString("Итого:"));
		vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,16).OlePropertySet("Value", WideString(nSum));
		vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,16).OlePropertySet("NumberFormat", WideString(m_strNumberFormat));
		vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,17).OlePropertySet("NumberFormat", WideString(m_strNumberFormat));
	}

	Log->Lines->Add("Сохраняю файл...");
	try {
		app.OlePropertySet("DisplayAlerts",false);
		excel.OleProcedure("SaveAs", WideString(m_strFileName.c_str()));
		Log->Lines->Add("Данные сохранены!");
	} catch (...) {
		Log->Lines->Add("Ошибка: Пожалуйста закройте все открытые копии файла и повторите операцию");
	}
    ProgressBar1->Position = 0;
	app.OleProcedure("Quit");
}
//---------------------------------------------------------------------------
// Возвращает количество атрибутов узла
int __fastcall MSXMLWorks::GetAttributesCount(Variant Node)
{
    return Node.OlePropertyGet("attributes").OlePropertyGet("length");
}
//---------------------------------------------------------------------------
//
AnsiString __fastcall MSXMLWorks::GetNodeName(Variant Node)
{
    return Node.OlePropertyGet("NodeName");
}
Example #24
0
void TForm1::clearCell(Variant &vSheet, int nRow, int nCol) {
	vSheet.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,nCol).OlePropertySet("Value", WideString(""));
}
//---------------------------------------------------------------------------
// Возвращает следующий узел от указанного
Variant __fastcall MSXMLWorks::GetNextNode(Variant Node)
{
    return Node.OlePropertyGet("nextSibling");
}
Example #26
0
void __fastcall TCZYJSQFrm::ExportBTNClick(TObject *Sender)
{
	QueryBTN->Enabled = false;
    ExportBTN->Enabled = false;
    PreviewBTN->Enabled = false;
    ExitBTN->Enabled = false;
    String savename;

    if(SaveDialog->Execute())
    {
        if(FileExists(SaveDialog->FileName+".xls"))
        {
            QueryBTN->Enabled = true;
            ExportBTN->Enabled = true;
            PreviewBTN->Enabled = true;
            ExitBTN->Enabled = true;
            throw(Exception("该目录下存在同名文件,请重新输入文件名!"));
            return;
        }
        else
        {
            savename = SaveDialog->FileName;
            savename += ".xls";
        }
    }

    Variant ExcelApp;
	try
	{
		ExcelApp = CreateOleObject("Excel.Application");
	}
	catch(...)
	{
		MessageBox(this->Handle, "错误:您的系统中可能没有安装Excel!", "Error in launch Excel!", MB_OK|MB_ICONERROR);
        QueryBTN->Enabled = true;
        ExportBTN->Enabled = true;
        PreviewBTN->Enabled = true;
        ExitBTN->Enabled = true;
		return;
	}

    String Templatepath = GlobalPath + "\\ExportXLSTemplate\\CZYJSTemplate.xlt";
    ExcelApp.OlePropertyGet("workbooks").OleFunction("Open", Templatepath.t_str());
    Variant WB = ExcelApp.OlePropertyGet("ActiveWorkBook");
    Variant ST = WB.OlePropertyGet("Sheets", 1);

    //设置报头信息
    String tmpoutstr = "";

    tmpoutstr = QCZYstr+"操作员收支情况结算";
    ST.OlePropertyGet("Cells",1,1).OlePropertySet("Value", tmpoutstr.t_str());
    ST.OlePropertyGet("Cells",2,2).OlePropertySet("Value", OperatorName.t_str());
    ST.OlePropertyGet("Cells",2,4).OlePropertySet("Value", QSSJstr.t_str());
    ST.OlePropertyGet("Cells",3,2).OlePropertySet("Value", DateTimeToStr(Now()).t_str());
    ST.OlePropertyGet("Cells",3,4).OlePropertySet("Value", JZSJstr.t_str());

    tmpoutstr = KZCSstr+"人次";
    ST.OlePropertyGet("Cells",5,2).OlePropertySet("Value", tmpoutstr.t_str());
    tmpoutstr = "¥"+KCBstr;
    ST.OlePropertyGet("Cells",5,3).OlePropertySet("Value", tmpoutstr.t_str());
    tmpoutstr = "¥"+KZEstr;
    ST.OlePropertyGet("Cells",5,4).OlePropertySet("Value", tmpoutstr.t_str());

    tmpoutstr = AZCSstr+"人次";
    ST.OlePropertyGet("Cells",6,2).OlePropertySet("Value", tmpoutstr.t_str());
    tmpoutstr = "¥"+ACBstr;
    ST.OlePropertyGet("Cells",6,3).OlePropertySet("Value", tmpoutstr.t_str());
    tmpoutstr = "¥"+AZEstr;
    ST.OlePropertyGet("Cells",6,4).OlePropertySet("Value", tmpoutstr.t_str());

    tmpoutstr = IZCSstr+"人次";
    ST.OlePropertyGet("Cells",7,2).OlePropertySet("Value", tmpoutstr.t_str());
    tmpoutstr = "¥"+ICBstr;
    ST.OlePropertyGet("Cells",7,3).OlePropertySet("Value", tmpoutstr.t_str());
    tmpoutstr = "¥"+IZEstr;
    ST.OlePropertyGet("Cells",7,4).OlePropertySet("Value", tmpoutstr.t_str());

    tmpoutstr = GZCSstr+"人次";
    ST.OlePropertyGet("Cells",8,2).OlePropertySet("Value", tmpoutstr.t_str());
    tmpoutstr = "¥"+GCBstr;
    ST.OlePropertyGet("Cells",8,3).OlePropertySet("Value", tmpoutstr.t_str());
    tmpoutstr = "¥"+GZEstr;
    ST.OlePropertyGet("Cells",8,4).OlePropertySet("Value", tmpoutstr.t_str());

    tmpoutstr = DZCSstr+"人次";
    ST.OlePropertyGet("Cells",9,2).OlePropertySet("Value", tmpoutstr.t_str());
    tmpoutstr = "¥"+DCBstr;
    ST.OlePropertyGet("Cells",9,3).OlePropertySet("Value", tmpoutstr.t_str());
    tmpoutstr = "¥"+DZEstr;
    ST.OlePropertyGet("Cells",9,4).OlePropertySet("Value", tmpoutstr.t_str());

    tmpoutstr = CZCSstr+"人次";
    ST.OlePropertyGet("Cells",10,2).OlePropertySet("Value", tmpoutstr.t_str());
    tmpoutstr = "¥"+CCBstr;
    ST.OlePropertyGet("Cells",10,3).OlePropertySet("Value", tmpoutstr.t_str());
    tmpoutstr = "¥"+CZEstr;
    ST.OlePropertyGet("Cells",10,4).OlePropertySet("Value", tmpoutstr.t_str());

    tmpoutstr = TZCSstr+"人次";
    ST.OlePropertyGet("Cells",11,2).OlePropertySet("Value", tmpoutstr.t_str());
    tmpoutstr = "¥"+TCBstr;
    ST.OlePropertyGet("Cells",11,3).OlePropertySet("Value", tmpoutstr.t_str());
    tmpoutstr = "¥"+TZEstr;
    ST.OlePropertyGet("Cells",11,4).OlePropertySet("Value", tmpoutstr.t_str());

    tmpoutstr = QZCSstr+"人次";
    ST.OlePropertyGet("Cells",12,2).OlePropertySet("Value", tmpoutstr.t_str());
    tmpoutstr = "¥"+QCBstr;
    ST.OlePropertyGet("Cells",12,3).OlePropertySet("Value", tmpoutstr.t_str());
    tmpoutstr = "¥"+QZEstr;
    ST.OlePropertyGet("Cells",12,4).OlePropertySet("Value", tmpoutstr.t_str());

    tmpoutstr = JSZCSstr+"人次";
    ST.OlePropertyGet("Cells",13,2).OlePropertySet("Value", tmpoutstr.t_str());
    tmpoutstr = "¥"+JSZCBstr;
    ST.OlePropertyGet("Cells",13,3).OlePropertySet("Value", tmpoutstr.t_str());
    tmpoutstr = "¥"+JSZJEstr;
    ST.OlePropertyGet("Cells",13,4).OlePropertySet("Value", tmpoutstr.t_str());

    tmpoutstr = "¥"+ZCZJEstr;
    ST.OlePropertyGet("Cells",14,4).OlePropertySet("Value", tmpoutstr.t_str());
    tmpoutstr = "¥"+SRZJEstr;
    ST.OlePropertyGet("Cells",15,4).OlePropertySet("Value", tmpoutstr.t_str());
    tmpoutstr = "¥"+ZJSstr;
    ST.OlePropertyGet("Cells",16,4).OlePropertySet("Value", tmpoutstr.t_str());

    ExcelApp.OlePropertyGet("Columns").OleFunction("AutoFit");
    WB.OleFunction("SaveAs", savename.t_str());
    ExcelApp.OleFunction("Quit");
    ExcelApp = Unassigned;
    MessageBox(this->Handle, "数据已完成导出!", "Successfully!", MB_OK|MB_ICONINFORMATION);

    QueryBTN->Enabled = true;
    ExportBTN->Enabled = true;
    PreviewBTN->Enabled = true;
    ExitBTN->Enabled = true;
}
//---------------------------------------------------------------------------
// Возвращает количество атрибутов узла
AnsiString __fastcall MSXMLWorks::GetAttributeValue(Variant Node, int AttributeIndex)
{
    return Node.OlePropertyGet("attributes").OlePropertyGet("item",AttributeIndex).OlePropertyGet("Value");
}
Example #28
0
//---------------------------------------------------------------------------
void __fastcall TCZMXExportThread::Execute()
{
    //---- Place thread code here ----
    ValidEXBTN->Enabled = false;
    ValidPreBTN->Enabled = false;
    ValidEBTN->Enabled = false;

    Variant ExcelApp;
    try
    {
        ExcelApp = CreateOleObject("Excel.Application");
    }
    catch(...)
    {
        MessageBox(CZMXShowFrm->Handle, "错误:您的系统中可能没有安装Excel!", "Error in launch Excel!", MB_OK|MB_ICONERROR);
        ValidEXBTN->Enabled = true;
        ValidPreBTN->Enabled = true;
        ValidEBTN->Enabled = true;
        return;
    }

    ValidQuery->Open();
    String DTX = "";
    String path = GlobalPath;
    String Templatepath;
    ValidQuery->First();
    int allrecord = ValidQuery->RecordCount;
    for(int i = 0; i <65531; i++)
    {
        DTX += ValidQuery->FieldByName("kh")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("bh")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("NAME")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("BUMEN")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("BANBIE")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("ZUBIE")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("ckje")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("sf_ye")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("sycs")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("sflx")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("jyno")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("CZY")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("pkey")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("sfrq")->AsAnsiString.Trim();
        DTX += "\n";
        Validprogress->Position = i*100/allrecord;
        ValidQuery->Next();
        if(ValidQuery->Eof)
            break;
    }

    Templatepath = path + "\\ExportXLSTemplate\\CZMXTemplate.xlt";
    ExcelApp.OlePropertyGet("workbooks").OleFunction("Open", Templatepath.t_str());
    Variant WB = ExcelApp.OlePropertyGet("ActiveWorkBook");
    Variant ST = WB.OlePropertyGet("Sheets", 1);

    //设置报头信息
    String tmpoutstr = "";
    ST.OlePropertyGet("Cells",2,2).OlePropertySet("Value", ValidKHstr.t_str());
    ST.OlePropertyGet("Cells",2,4).OlePropertySet("Value", ValidBHstr.t_str());
    ST.OlePropertyGet("Cells",2,6).OlePropertySet("Value", ValidBBstr.t_str());
    ST.OlePropertyGet("Cells",2,8).OlePropertySet("Value", ValidCZCZYstr.t_str());
    tmpoutstr = "¥" + ValidAllCKstr;
    ST.OlePropertyGet("Cells",2,10).OlePropertySet("Value", tmpoutstr.t_str());
    ST.OlePropertyGet("Cells",2,12).OlePropertySet("Value", ValidCZYstr.t_str());
    ST.OlePropertyGet("Cells",2,14).OlePropertySet("Value", ValidBeginDatestr.t_str());

    ST.OlePropertyGet("Cells",3,2).OlePropertySet("Value", ValidBMstr.t_str());
    if(ValidDKQCZtag)
        ST.OlePropertyGet("Cells",3,4).OlePropertySet("Value", "Y");
    else
        ST.OlePropertyGet("Cells",3,4).OlePropertySet("Value", "N");

    ST.OlePropertyGet("Cells",3,6).OlePropertySet("Value", ValidZBstr.t_str());
    if(ValidPOSCZtag)
        ST.OlePropertyGet("Cells",3,8).OlePropertySet("Value", "Y");
    else
        ST.OlePropertyGet("Cells",3,8).OlePropertySet("Value", "N");

    if(ValidFKCZtag)
        ST.OlePropertyGet("Cells",3,10).OlePropertySet("Value", "Y");
    else
        ST.OlePropertyGet("Cells",3,10).OlePropertySet("Value", "N");


    ST.OlePropertyGet("Cells",3,12).OlePropertySet("Value", DateTimeToStr(Now()).t_str());
    ST.OlePropertyGet("Cells",3,14).OlePropertySet("Value", ValidEndDatestr.t_str());

    Variant RE = ST.OlePropertyGet("Range", "A7").OleFunction("Select");
    Clipboard()->Clear();
    Clipboard()->SetTextBuf(DTX.c_str());
    ST.OleFunction("Paste");
    Clipboard()->Clear();

    ExcelApp.OlePropertyGet("Columns").OleFunction("AutoFit");
    WB.OleFunction("SaveAs", Validsavepath.t_str());
    ExcelApp.OleFunction("Quit");
    ExcelApp = Unassigned;
    Validprogress->Position = 100;
    MessageBox(CZMXShowFrm->Handle, "数据已完成导出!", "Successfully!", MB_OK|MB_ICONINFORMATION);

    ValidEXBTN->Enabled = true;
    ValidPreBTN->Enabled = true;
    ValidEBTN->Enabled = true;
}
Example #29
0
//---------------------------------------------------------------------------
void __fastcall TCTQFrm::ExportBTNClick(TObject *Sender)
{
	if(SaveDialog->Execute())
    {
    	ExportBTN->Enabled = false;
        PreviewBTN->Enabled = false;
        if(FileExists(SaveDialog->FileName+".xls"))
        {
            ExportBTN->Enabled = true;
            PreviewBTN->Enabled = true;
            throw(Exception("该目录下存在同名文件,请重新输入文件名!"));
            return;
        }
        else
        {
            String savename = SaveDialog->FileName;
            savename += ".xls";
            Variant ExcelApp;
            try
            {
                ExcelApp = CreateOleObject("Excel.Application");
            }
            catch(...)
            {
                MessageBox(this->Handle, "错误:您的系统中可能没有安装Excel!", "Error in launch Excel!", MB_OK|MB_ICONERROR);
                return;
            }

            String Templatepath = GlobalPath + "\\ExportXLSTemplate\\CTTJTemplate.xlt";
            ExcelApp.OlePropertyGet("workbooks").OleFunction("Open", Templatepath.t_str());
            Variant WB = ExcelApp.OlePropertyGet("ActiveWorkBook");
            Variant ST = WB.OlePropertyGet("Sheets", 1);

            ST.OlePropertyGet("Cells",2,2).OlePropertySet("Value", (BeginDatestr+" 00:00:00").t_str());
            ST.OlePropertyGet("Cells",2,7).OlePropertySet("Value", (EndDatestr+" 23:59:59").t_str());
            ST.OlePropertyGet("Cells",3,2).OlePropertySet("Value", CTStr.t_str());
            ST.OlePropertyGet("Cells",3,5).OlePropertySet("Value", OperatorName.t_str());
            ST.OlePropertyGet("Cells",3,8).OlePropertySet("Value", DateTimeToStr(Now()).t_str());

            ST.OlePropertyGet("Cells",6,2).OlePropertySet("Value", cxTextEdit1->Text.t_str());
            ST.OlePropertyGet("Cells",7,2).OlePropertySet("Value", cxTextEdit2->Text.t_str());
            ST.OlePropertyGet("Cells",8,2).OlePropertySet("Value", cxTextEdit3->Text.t_str());
            ST.OlePropertyGet("Cells",9,2).OlePropertySet("Value", cxTextEdit4->Text.t_str());

            ST.OlePropertyGet("Cells",6,4).OlePropertySet("Value", cxTextEdit5->Text.t_str());
            ST.OlePropertyGet("Cells",7,4).OlePropertySet("Value", cxTextEdit6->Text.t_str());
            ST.OlePropertyGet("Cells",8,4).OlePropertySet("Value", cxTextEdit7->Text.t_str());
            ST.OlePropertyGet("Cells",9,4).OlePropertySet("Value", cxTextEdit8->Text.t_str());

            ST.OlePropertyGet("Cells",6,6).OlePropertySet("Value", cxTextEdit9->Text.t_str());
            ST.OlePropertyGet("Cells",7,6).OlePropertySet("Value", cxTextEdit10->Text.t_str());
            ST.OlePropertyGet("Cells",8,6).OlePropertySet("Value", cxTextEdit11->Text.t_str());
            ST.OlePropertyGet("Cells",9,6).OlePropertySet("Value", cxTextEdit12->Text.t_str());

            ST.OlePropertyGet("Cells",6,8).OlePropertySet("Value", cxTextEdit13->Text.t_str());
            ST.OlePropertyGet("Cells",7,8).OlePropertySet("Value", cxTextEdit14->Text.t_str());
            ST.OlePropertyGet("Cells",8,8).OlePropertySet("Value", cxTextEdit15->Text.t_str());
            ST.OlePropertyGet("Cells",9,8).OlePropertySet("Value", cxTextEdit16->Text.t_str());

            ST.OlePropertyGet("Cells",6,10).OlePropertySet("Value", cxTextEdit17->Text.t_str());
            ST.OlePropertyGet("Cells",7,10).OlePropertySet("Value", cxTextEdit18->Text.t_str());
            ST.OlePropertyGet("Cells",8,10).OlePropertySet("Value", cxTextEdit19->Text.t_str());
            ST.OlePropertyGet("Cells",9,10).OlePropertySet("Value", cxTextEdit20->Text.t_str());

            ExcelApp.OlePropertyGet("Columns").OleFunction("AutoFit");
            WB.OleFunction("SaveAs", savename.t_str());
            ExcelApp.OleFunction("Quit");
            ExcelApp = Unassigned;
            MessageBox(this->Handle, "数据已完成导出!", "Successfully!", MB_OK|MB_ICONINFORMATION);
        }
    	ExportBTN->Enabled = true;
        PreviewBTN->Enabled = true;
    }
}
//---------------------------------------------------------------------------
void __fastcall TXFTJALLExportThread::Execute()
{
	//---- Place thread code here ----
    ValidEXBTN->Enabled = false;
    ValidPreBTN->Enabled = false;
    ValidEBTN->Enabled = false;
    ValidQBTN->Enabled = false;

    Variant ExcelApp;
	try
	{
		ExcelApp = CreateOleObject("Excel.Application");
	}
	catch(...)
	{
		MessageBox(XFTJQFrm->Handle, "错误:您的系统中可能没有安装Excel!", "Error in launch Excel!", MB_OK|MB_ICONERROR);
        ValidEXBTN->Enabled = true;
        ValidPreBTN->Enabled = true;
        ValidEBTN->Enabled = true;
		return;
	}

    ValidQuery->Open();
    String DTX = "";
    String path = GlobalPath;
    String Templatepath;
    ValidQuery->First();
    int allrecord = ValidQuery->RecordCount;
    for(int i = 0; i <65531; i++)
    {
        DTX += ValidQuery->FieldByName("qdate")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("ZSFZE")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("ZSFCS")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("BFSFZE")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("BFCS")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("LHSFZE")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("LHCS")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("SUSFZE")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("SUCS")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("NTSFZE")->AsAnsiString.Trim();
        DTX += "\t";
        DTX += ValidQuery->FieldByName("NTCS")->AsAnsiString.Trim();
        DTX += "\n";
        Validprogress->Position = i*100/allrecord;
        ValidQuery->Next();
        if(ValidQuery->Eof)
            break;
    }

    Templatepath = path + "\\ExportXLSTemplate\\XFTJALLMXTemplate.xlt";
    ExcelApp.OlePropertyGet("workbooks").OleFunction("Open", Templatepath.t_str());
    Variant WB = ExcelApp.OlePropertyGet("ActiveWorkBook");
    Variant ST = WB.OlePropertyGet("Sheets", 1);

    ST.OlePropertyGet("Cells",2,2).OlePropertySet("Value", ValidBHStr.t_str());
    ST.OlePropertyGet("Cells",2,5).OlePropertySet("Value", ValidBMStr.t_str());
    ST.OlePropertyGet("Cells",2,9).OlePropertySet("Value", ValidBeginDatestr.t_str());
    ST.OlePropertyGet("Cells",3,2).OlePropertySet("Value", ValidCZYStr.t_str());
    ST.OlePropertyGet("Cells",3,5).OlePropertySet("Value", DateTimeToStr(Now()).t_str());
    ST.OlePropertyGet("Cells",3,9).OlePropertySet("Value", ValidEndDatestr.t_str());

    ST.OlePropertyGet("Cells",5,2).OlePropertySet("Value", ValidZZE.t_str());
    ST.OlePropertyGet("Cells",6,2).OlePropertySet("Value", ValidZZCS.t_str());

    ST.OlePropertyGet("Cells",5,4).OlePropertySet("Value", ValidBZE.t_str());
    ST.OlePropertyGet("Cells",6,4).OlePropertySet("Value", ValidBZCS.t_str());

    ST.OlePropertyGet("Cells",5,6).OlePropertySet("Value", ValidLZE.t_str());
    ST.OlePropertyGet("Cells",6,6).OlePropertySet("Value", ValidLZCS.t_str());

    ST.OlePropertyGet("Cells",5,8).OlePropertySet("Value", ValidSZE.t_str());
    ST.OlePropertyGet("Cells",6,8).OlePropertySet("Value", ValidSZCS.t_str());

    ST.OlePropertyGet("Cells",5,10).OlePropertySet("Value", ValidNZE.t_str());
    ST.OlePropertyGet("Cells",6,10).OlePropertySet("Value", ValidNZCS.t_str());

    Variant RE = ST.OlePropertyGet("Range", "A9").OleFunction("Select");
    Clipboard()->Clear();
    Clipboard()->SetTextBuf(DTX.c_str());
    ST.OleFunction("Paste");
    Clipboard()->Clear();

    ExcelApp.OlePropertyGet("Columns").OleFunction("AutoFit");
    WB.OleFunction("SaveAs", Validsavepath.t_str());
    ExcelApp.OleFunction("Quit");
    ExcelApp = Unassigned;
    Validprogress->Position = 100;
    MessageBox(XFTJQFrm->Handle, "数据已完成导出!", "Successfully!", MB_OK|MB_ICONINFORMATION);

    ValidEXBTN->Enabled = true;
    ValidPreBTN->Enabled = true;
    ValidEBTN->Enabled = true;
    ValidQBTN->Enabled = true;
}