Exemplo n.º 1
0
void doc2txt::convertPro(AnsiString WordFile,AnsiString PathPutTxt)
{
	TStringList* word=new TStringList;
	String filename = WordFile;
	Variant  vVarApp,vVarDoc,vVarParagraphs,vVarParagraph;
	AnsiString resolution = ExtractFileExt(filename);
	AnsiString str = StringReplace( ExtractFileName(filename),resolution,"",TReplaceFlags()<< rfReplaceAll << rfIgnoreCase);

	try
	{
		vVarApp=CreateOleObject("Word.Application");
	}
	catch(...)
	{
		MessageBox(0, "Не удачно получилось открыть Word", "Внимание", MB_OK);
		return;
	}

	vVarApp.OlePropertySet("Visible",false);
	vVarDoc = vVarApp.OlePropertyGet("Documents");
	vVarDoc.OleProcedure("Open", StringToOleStr(filename));
	vVarDoc = vVarDoc.OleFunction("Item",1);
	vVarDoc.OleProcedure("Activate");
	String s = vVarDoc.OlePropertyGet("Content").OlePropertyGet("Text");
	word->Add(s);
	word->SaveToFile( PathPutTxt + str +".txt" );
	vVarApp.OleProcedure("Quit");
	delete word;
}
Exemplo n.º 2
0
//---------------------------------------------------------------------------
//
MSXMLWorks::MSXMLWorks()
{
    //Variant xmlObj = CreateOleObject("Microsoft.XMLDOM");
    //Variant xmlDoc = CreateOleObject("MSXML.DOMDocument");
    xmlDoc = CreateOleObject("Msxml2.DOMDocument.3.0");
    xmlDoc.OlePropertySet("Async", false);
}
Exemplo n.º 3
0
void __fastcall TForm1::Button11Click(TObject *Sender)
{
Variant v,v1;
 if(!fStart)
 {
  try
  {
   //Создаем объект Word.Application
   vVarApp=CreateOleObject("Word.Application");
   fStart=true;
  }
  catch(...)
  {
   MessageBox(0, "Ошибка при открытии сервера Word",
                 "Ошибка", MB_OK);
  return;
  }
 }
 //Делаем сервер видимым
 vVarApp.OlePropertySet("Visible",true);
 //Получаем свойство Documents объекта
 vVarDocs=vVarApp.OlePropertyGet("Documents");
 //Создаем два документа
 vVarDocs.OleProcedure("Add");
 //Проверяем, что создано два документа

 //Будем работать с первым документом - Item == 2;
 vVarDoc=vVarDocs.OleFunction("Item",1);
 //Смотреть будем тоже на первый документ
}
Exemplo n.º 4
0
//---------------------------------------------------------------------------
void __fastcall TFormMain::TalkToWordClick(TObject *Sender)
{
     Variant V;

     V = CreateOleObject("Word.Basic");
     V.Exec(Procedure("AppShow"));
     V.Exec(Procedure("FileNew") << "Normal");
     V.Exec(Procedure("Insert") << "Hello from Borland");
}
Exemplo n.º 5
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;
    }
}
Exemplo n.º 6
0
void __fastcall TMainForm::ExportClick(TObject *Sender)
{
  const char columns_name[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  const int xlAlignCenter = -4108;
  const int xlHAlignLeft = -4131;
  const int xlVAlignTop = -4160;


  AnsiString range_str;

  Variant app, ws, range;
  app = CreateOleObject("Excel.Application");
  app.OlePropertySet("Visible", true);
  app.OlePropertyGet("Workbooks").OleProcedure("Add");
  ws = app.OlePropertyGet("Worksheets").OlePropertyGet("Item",1);

  ws.OlePropertySet("Name", "Отчет");

  range_str = "A1:" + AnsiString(columns_name [m_view_list.size()-1]) + "1";

  range = ws.OlePropertyGet("Range", range_str.c_str());
  range.OleProcedure("Merge");
  range.OlePropertySet("Value", m_caption.c_str());
  range.OlePropertyGet("Font").OlePropertySet("Size", 12);
  range.OlePropertyGet("Font").OlePropertySet("Bold", true);
  range.OlePropertySet("HorizontalAlignment", xlAlignCenter);
  range.OlePropertySet("VerticalAlignment", xlAlignCenter);
  range.OlePropertySet("RowHeight", 30);

  for (unsigned int col=0; col < m_view_list.size(); col++)
  {
    ws.OlePropertyGet("Cells").
      OlePropertyGet("Item", 2, col+1).
      OlePropertySet("Value", m_view_list[col].full_name.c_str());

    ws.OlePropertyGet("Cells").
      OlePropertyGet("Item", 2, col+1).
      OlePropertyGet("Font").OlePropertySet("Bold", true);
  }

   int row = 3;

   OraQueryAllJournal->First();
   while (!OraQueryAllJournal->Eof)
   {
     for (unsigned int col=0; col < m_view_list.size(); col++)
     {
       ws.OlePropertyGet("Cells").
         OlePropertyGet("Item", row, col+1).
         OlePropertySet("Value", OraQueryAllJournal->FieldByName(m_view_list[col].field_name)->AsString.c_str());
     }

     OraQueryAllJournal->Next();
     row++;
   }

   range_str = "A2:" + AnsiString(columns_name [m_view_list.size()-1]) + IntToStr (row-1);
   range = ws.OlePropertyGet("Range", range_str.c_str());
   range.OleProcedure("AutoFormat");
   range.OlePropertySet("HorizontalAlignment", xlHAlignLeft);
   range.OlePropertySet("VerticalAlignment", xlVAlignTop);
   range.OlePropertySet("WrapText", true);   

   range_str = "A2:" + AnsiString(columns_name [m_view_list.size()-1]) + "2";
   range = ws.OlePropertyGet("Range", range_str.c_str());
   range.OlePropertyGet("Interior").OlePropertySet("Color", 0xC0C0C0);
   range.OlePropertySet("HorizontalAlignment", xlAlignCenter);
}
Exemplo n.º 7
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;
	}
}
Exemplo n.º 8
0
void __fastcall TReportForm::ToolButton6Click(TObject *Sender)
{
	Variant ExcelApp, ExcelBooks, Book, WorkSheet, Cells, EmptyParam;
	TDateTime dtReport = Date();
	UnicodeString s=ExtractFileDir(Application->ExeName)+"\\template.xls";

	if (!FileExists(s))
	{
		ShowMessage("Файл шаблона не найден");
		return;
	}

	TVirtualNode *t_root=VirtualStringTree1->RootNode->FirstChild;
	TVirtualNode *t_child;
	TReportData *data_root, *data_child;

	try
	{
		ExcelApp = GetActiveOleObject("Excel.Application");
		ExcelBooks = ExcelApp.OlePropertyGet("WorkBooks");
	}
	catch (...)
	{
		try
		{
			ExcelApp = CreateOleObject("Excel.Application");
			ExcelBooks = ExcelApp.OlePropertyGet("WorkBooks");

		}
		catch (...)
		{
		  ShowMessage("Microsoft Excel не установлен");
		return;
		}
	}

	int i = 27;
	int j = 2;
	TFormatSettings format_settings;
	GetLocaleFormatSettings(LOCALE_SYSTEM_DEFAULT, format_settings);
	format_settings.DecimalSeparator = ',';

	try
	{
    	ExcelApp.OlePropertySet("Visible", false);
		Book = ExcelBooks.OleFunction("Add", s.t_str());
		WorkSheet = Book.OlePropertyGet("Worksheets").OlePropertyGet("Item", 1);
		Cells = WorkSheet.OlePropertyGet("Cells");
		Cells.OlePropertyGet("Item",4,3).OlePropertySet("Value", dtReport.FormatString("dd.mm.yyyy").t_str());
		Cells.OlePropertyGet("Item",8,1).OleProcedure("Select");
		MainForm->Chart5->CopyToClipboardMetafile(true);
		WorkSheet.OleProcedure("Paste");
		Variant shapes = WorkSheet.OlePropertyGet("Shapes").OleFunction("Item", 1);
		shapes.OleFunction("ScaleWidth", 0.9, EmptyParam, EmptyParam);
		shapes.OleFunction("ScaleHeight", 0.9, EmptyParam, EmptyParam);


		for (size_t k=0; k < VirtualStringTree1->RootNodeCount; k++)
		{
			if (t_root)
			{
				data_root = (TReportData *)ReportForm->VirtualStringTree1->GetNodeData(t_root);
				if (data_root)
				{
					s=data_root->Name;
					Cells.OlePropertyGet("Item",i,j).OlePropertySet("Value", s.t_str());
					i++;
				}


				t_child=t_root->FirstChild;
				while (t_child)
				{
					data_child=(TReportData *)ReportForm->VirtualStringTree1->GetNodeData(t_child);
					if (data_root)
					{
						s=data_child->Name;
						Cells.OlePropertyGet("Item",i,j).OlePropertySet("Value", s.t_str());
						Cells.OlePropertyGet("Item",i,j+1).OlePropertySet("Value", FloatToStrF(data_child->pcs, ffFixed, 5, 2, format_settings).t_str());
						Cells.OlePropertyGet("Item",i,j+2).OlePropertySet("Value", FloatToStrF(data_child->pi, ffFixed, 5, 2, format_settings).t_str());
						Cells.OlePropertyGet("Item",i,j+3).OlePropertySet("Value", FloatToStrF(data_child->angle, ffFixed, 5, 2,format_settings).t_str());
						i++;

					}
					t_child = t_child->NextSibling;
				}

				Cells.OlePropertyGet("Item",i,j).OlePropertySet("Value", "Средний диаметр");
				Cells.OlePropertyGet("Item",i,j).OlePropertyGet("Font").OlePropertySet("Bold", true);
				Cells.OlePropertyGet("Item",i,j+1).OlePropertySet("Value", FloatToStrF(data_root->pcs, ffFixed, 5, 2, format_settings).t_str());
				i++;
				Cells.OlePropertyGet("Item",i,j).OlePropertySet("Value", "Средний ПДД");
				Cells.OlePropertyGet("Item",i,j).OlePropertyGet("Font").OlePropertySet("Bold", true);
				Cells.OlePropertyGet("Item",i,j+1).OlePropertySet("Value", FloatToStrF(data_root->pi, ffFixed, 5, 2, format_settings).t_str());
				i++;
				Cells.OlePropertyGet("Item",i,j).OlePropertySet("Value", "СКО");
				Cells.OlePropertyGet("Item",i,j).OlePropertyGet("Font").OlePropertySet("Bold", true);
				Cells.OlePropertyGet("Item",i,j+1).OlePropertySet("Value", FloatToStrF(data_root->rms, ffFixed, 5, 2, format_settings).t_str());
				i++;
			}

			t_root=t_root->NextSibling;
		}
	}
	__finally
	{
		ExcelApp.OlePropertySet("Visible", true);
		ExcelApp=Unassigned();
	}

}
Exemplo n.º 9
0
void __fastcall TReportForm::ToolButton3Click(TObject *Sender)
{

  Variant WordApp, WordSel, WordDoc, EmptyParam, table, cell, range;
  TDateTime dtReport = Date();
  UnicodeString s=ExtractFileDir(Application->ExeName)+"\\template.doc";

  if (!FileExists(s)) {
	ShowMessage("Файл шаблона не найден");
	return;
  }

  TVirtualNode *t_root=VirtualStringTree1->RootNode->FirstChild;
  TVirtualNode *t_child;
  TReportData *data_root, *data_child;

  try {
	WordApp=GetActiveOleObject("Word.Application");
  } catch (...) {
	try {
	  WordApp=CreateOleObject("Word.Application");

	} catch (...) {
	  ShowMessage("Microsoft Word не установлен");
	  return;
	}
  }



  try {
	WordApp.OlePropertySet("Visible", false);
	WordDoc=WordApp.OlePropertyGet("Documents").OleFunction("Add", s.t_str());


//	if (WordDoc.OlePropertyGet("Bookmarks").OleFunction("Exists", "date"))
//	  ShowMessage("!");

//	WordDoc.OleFunction("GoTo", 0xFFFFFFFF, EmptyParam, EmptyParam, "date").OleFunction("Select");
	WordApp.OlePropertyGet("Selection").OleFunction("goto", 0xFFFFFFFF, EmptyParam, EmptyParam, "date");
	WordApp.OlePropertyGet("Selection").OleProcedure("TypeText", dtReport.FormatString("dd.mm.yyyy").t_str());
	WordApp.OlePropertyGet("Selection").OleFunction("goto", 0xFFFFFFFF, EmptyParam, EmptyParam, "img");
	MainForm->Chart5->CopyToClipboardMetafile(true);
	WordApp.OlePropertyGet("Selection").OleFunction("Paste");


	WordApp.OlePropertyGet("Selection").OleFunction("goto", 0xFFFFFFFF, EmptyParam, EmptyParam, "table");

//	table=WordDoc.OlePropertyGet("Tables").OleFunction("Item", 1);
//	cell=table.OleFunction("Cell", 1, 1);
//	range=cell.OlePropertyGet("Range");
//	range.OlePropertySet("Text", "F**k");
	for (size_t i=0; i < VirtualStringTree1->RootNodeCount; i++) {
	  if (!(t_root == NULL)) {
		data_root=(TReportData *)ReportForm->VirtualStringTree1->GetNodeData(t_root);
		if (!(data_root == NULL)) {
		  s=data_root->Name;
		  WordApp.OlePropertyGet("Selection").OleProcedure("TypeText", s.t_str());
		  WordApp.OlePropertyGet("Selection").OleFunction("MoveRight", 12);
		  WordApp.OlePropertyGet("Selection").OleFunction("MoveRight", 12);
		  WordApp.OlePropertyGet("Selection").OleFunction("MoveRight", 12);
		  WordApp.OlePropertyGet("Selection").OleFunction("MoveRight", 12);
		}
		else
		  continue;

		t_child=t_root->FirstChild;
		while (!(t_child == NULL))
		{
		  data_child=(TReportData *)ReportForm->VirtualStringTree1->GetNodeData(t_child);
		  if (!(data_child == NULL) && (t_child->CheckState == csCheckedNormal)) {
			s=data_child->Name;
			WordApp.OlePropertyGet("Selection").OleProcedure("TypeText", s.t_str());
			WordApp.OlePropertyGet("Selection").OleFunction("MoveRight", 12);
			WordApp.OlePropertyGet("Selection").OleProcedure("TypeText",  FloatToStrF(data_child->pcs, ffFixed, 5, 2).t_str());
			WordApp.OlePropertyGet("Selection").OleFunction("MoveRight", 12);
			WordApp.OlePropertyGet("Selection").OleProcedure("TypeText",  FloatToStrF(data_child->pi, ffFixed, 5, 2).t_str());
			WordApp.OlePropertyGet("Selection").OleFunction("MoveRight", 12);
			WordApp.OlePropertyGet("Selection").OleProcedure("TypeText",  FloatToStr(data_child->angle).t_str());
			WordApp.OlePropertyGet("Selection").OleFunction("MoveRight", 12);
		  }
		  t_child=t_child->NextSibling;
		}
		WordApp.OlePropertyGet("Selection").OlePropertyGet("Font").OlePropertySet("Bold", true);
		WordApp.OlePropertyGet("Selection").OlePropertyGet("ParagraphFormat").OlePropertySet("Alignment", 0);
		WordApp.OlePropertyGet("Selection").OleProcedure("TypeText", "Средний диаметр");
		WordApp.OlePropertyGet("Selection").OleFunction("MoveRight", 12);
		WordApp.OlePropertyGet("Selection").OlePropertyGet("Font").OlePropertySet("Bold", false);
		WordApp.OlePropertyGet("Selection").OlePropertyGet("ParagraphFormat").OlePropertySet("Alignment", 1);
		s=FloatToStrF(data_root->pcs, ffFixed, 5, 2)+" нм.";
		WordApp.OlePropertyGet("Selection").OleProcedure("TypeText",  s.t_str());
		WordApp.OlePropertyGet("Selection").OleFunction("MoveRight", 12);
		WordApp.OlePropertyGet("Selection").OleFunction("MoveRight", 12);
		WordApp.OlePropertyGet("Selection").OleFunction("MoveRight", 12);
		WordApp.OlePropertyGet("Selection").OleProcedure("TypeText", "Средний ППД");
		WordApp.OlePropertyGet("Selection").OleFunction("MoveRight", 12);
		WordApp.OlePropertyGet("Selection").OleProcedure("TypeText",  FloatToStrF(data_root->pi, ffFixed, 5, 2).t_str());
		WordApp.OlePropertyGet("Selection").OleFunction("MoveRight", 12);
		WordApp.OlePropertyGet("Selection").OleFunction("MoveRight", 12);
		WordApp.OlePropertyGet("Selection").OleFunction("MoveRight", 12);
		WordApp.OlePropertyGet("Selection").OleProcedure("TypeText", "СКО");
		WordApp.OlePropertyGet("Selection").OleFunction("MoveRight", 12);
		s=FloatToStrF(data_root->rms, ffFixed, 5, 2)+" нм.";
		WordApp.OlePropertyGet("Selection").OleProcedure("TypeText",  s.t_str());
		WordApp.OlePropertyGet("Selection").OleFunction("MoveRight", 12);
		WordApp.OlePropertyGet("Selection").OleFunction("MoveRight", 12);
		if (!(i == (VirtualStringTree1->RootNodeCount-1))) {
		  WordApp.OlePropertyGet("Selection").OleFunction("MoveRight", 12);
		  WordApp.OlePropertyGet("Selection").OlePropertyGet("Font").OlePropertySet("Bold", false);
		  WordApp.OlePropertyGet("Selection").OlePropertyGet("ParagraphFormat").OlePropertySet("Alignment", 1);
		}
	  }
	  t_root=t_root->NextSibling;
	}




	/*

	for (int i=0; i < 100; i++) {
	  WordApp.OlePropertyGet("Selection").OleProcedure("TypeText", "F**k");
	  WordApp.OlePropertyGet("Selection").OleFunction("MoveRight", 12);
	}
	  */

	/*WordApp.OlePropertyGet("Selection").OlePropertyGet("ParagraphFormat").OlePropertySet("Alignment", 1);
	WordApp.OlePropertyGet("Selection").OlePropertyGet("Font").OlePropertySet("Bold", true);
	WordApp.OlePropertyGet("Selection").OleProcedure("TypeText", "Протокол измерений");
	WordApp.OlePropertyGet("Selection").OleProcedure("TypeParagraph");
	WordApp.OlePropertyGet("Selection").OleProcedure("TypeParagraph");
	WordApp.OlePropertyGet("Selection").OlePropertyGet("ParagraphFormat").OlePropertySet("Alignment", 0);
	WordApp.OlePropertyGet("Selection").OlePropertyGet("Font").OlePropertySet("Bold", false);
	WordApp.OlePropertyGet("Selection").OleProcedure("TypeText", dtReport.FormatString("dd.mm.yyyy").t_str());
	WordApp.OlePropertyGet("Selection").OleProcedure("TypeParagraph");
	WordApp.OlePropertyGet("Selection").OleProcedure("TypeParagraph");
	WordApp.OlePropertyGet("Tables").OlePropertySet("Add", 3, 3);
	 */
  }
  __finally{
    WordApp.OlePropertySet("Visible", true);
	WordApp=Unassigned();
  }

}
Exemplo n.º 10
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);
}
Exemplo n.º 11
0
//---------------------------------------------------------------------------
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;
}
Exemplo n.º 12
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;
}
Exemplo n.º 13
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;
}
Exemplo n.º 14
0
void __fastcall TForm1::Button10Click(TObject *Sender)
{
Variant v,v1;
 if(!fStart)
 {
  try
  {
   //Создаем объект Word.Application
   vVarApp=CreateOleObject("Word.Application");
   fStart=true;
  }
  catch(...)
  {
   MessageBox(0, "Ошибка при открытии сервера Word",
                 "Ошибка", MB_OK);
  return;
  }
 }
 //Делаем сервер видимым
 vVarApp.OlePropertySet("Visible",true);
 //Получаем свойство Documents объекта
 vVarDocs=vVarApp.OlePropertyGet("Documents");
 //Создаем два документа
 vVarDocs.OleProcedure("Add");

 vVarDoc=vVarDocs.OleFunction("Item",1);
 //Смотреть будем тоже на первый документ
 vVarDoc.OleProcedure("Activate");
 //vVarDoc.OleProcedure("Select");
 vVarParagraphs=vVarDoc.OlePropertyGet("Paragraphs");
 //Задаем текст для вывода
 str="\t\t\"Утверждаю\"     \t\t";
 //Добавляем параграф
 vVarParagraphs.OleProcedure("Add");
 //Работаем с первым параграфом
 vVarParagraph=vVarParagraphs.OleFunction("Item",1);
 //Заносим в него текст
 vVarParagraph.OlePropertyGet("Range").
               OlePropertySet("Text",str.c_str());
 //Выравниваем по правому краю
 vVarParagraph.OlePropertySet("Alignment",2);
 //Второй параграф
 str="\t\tНачальник ЦЭИК филиала ФГУП \"ЦЭНКИ\"\t\t";
 vVarParagraphs.OleProcedure("Add");
 vVarParagraph=vVarParagraphs.OleFunction("Item",2);
 vVarParagraph.OlePropertyGet("Range").
               OlePropertySet("Text",str.c_str());
 vVarParagraph.OlePropertySet("Alignment",2);
 //Третий параграф
 str="\t\t\"Космический центр \"Южный\"\t\t";
 vVarParagraphs.OleProcedure("Add");
 vVarParagraph=vVarParagraphs.OleFunction("Item",3);
 vVarParagraph.OlePropertyGet("Range").
               OlePropertySet("Text",str.c_str());
 vVarParagraph.OlePropertySet("Alignment",2);

 //Четвертый параграф
  str="\t\t_____________________\t\t";
 vVarParagraphs.OleProcedure("Add");
 vVarParagraph=vVarParagraphs.OleFunction("Item",4);
 vVarParagraph.OlePropertyGet("Range").
               OlePropertySet("Text",str.c_str());
 vVarParagraph.OlePropertySet("Alignment",2);

 str="\t\t\"_____\"______________20__года\t\t";
 vVarParagraphs.OleProcedure("Add");
 vVarParagraph=vVarParagraphs.OleFunction("Item",5);
 vVarParagraph.OlePropertyGet("Range").
               OlePropertySet("Text",str.c_str());
 vVarParagraph.OlePropertySet("Alignment",2);

 //Шестой параграф
 str="Перемещение ТМЦ";
 vVarParagraphs.OleProcedure("Add");
 vVarParagraph=vVarParagraphs.OleFunction("Item",6);
 vVarParagraph.OlePropertyGet("Range").
               OlePropertySet("Text",str.c_str());
 //wdAlignParagraphCenter
 vVarParagraph.OlePropertySet("Alignment",1);

 str="Проводил ";
 vVarParagraphs.OleProcedure("Add");
 vVarParagraph=vVarParagraphs.OleFunction("Item",7);
 vVarParagraph.OlePropertyGet("Range").
               OlePropertySet("Text",str.c_str());
 //wdAlignParagraphCenter

 vVarParagraph.OlePropertySet("Alignment",0);
  str=Edit4->Text+"    "+Edit5->Text;
 vVarParagraphs.OleProcedure("Add");
 vVarParagraph=vVarParagraphs.OleFunction("Item",8);
 vVarParagraph.OlePropertyGet("Range").
               OlePropertySet("Text",str.c_str());
 //wdAlignParagraphCenter
 vVarParagraph.OlePropertySet("Alignment",0);
 TDateTime CurrentDate = Date();

 str="Выявлены предметы не из "+Edit2->Text+" кабинета";
 vVarParagraphs.OleProcedure("Add");
 vVarParagraph=vVarParagraphs.OleFunction("Item",9);
 vVarParagraph.OlePropertyGet("Range").
               OlePropertySet("Text",str.c_str());
 //wdAlignParagraphCenter
 vVarParagraph.OlePropertySet("Alignment",1);

 str="На "+CurrentDate;
 vVarParagraphs.OleProcedure("Add");
 vVarParagraph=vVarParagraphs.OleFunction("Item",10);
 vVarParagraph.OlePropertyGet("Range").
               OlePropertySet("Text",str.c_str());
 //wdAlignParagraphCenter
 vVarParagraph.OlePropertySet("Alignment",1);
 vVarParagraphs.OleProcedure("Add");
 vVarParagraphs.OleProcedure("Add");


 str="Перечисленные предметы необходимо переместить.";
 vVarParagraphs.OleProcedure("Add");
 vVarParagraph=vVarParagraphs.OleFunction("Item",13);
 vVarParagraph.OlePropertyGet("Range").
               OlePropertySet("Text",str.c_str());
 //wdAlignParagraphCenter
 vVarParagraph.OlePropertySet("Alignment",0);

 str="Члены комиссии_____________________________________";
 vVarParagraphs.OleProcedure("Add");
 vVarParagraph=vVarParagraphs.OleFunction("Item",14);
 vVarParagraph.OlePropertyGet("Range").
               OlePropertySet("Text",str.c_str());
 //wdAlignParagraphCenter
 vVarParagraph.OlePropertySet("Alignment",0);
 str="                                   _____________________________________";
 vVarParagraphs.OleProcedure("Add");
 vVarParagraph=vVarParagraphs.OleFunction("Item",15);
 vVarParagraph.OlePropertyGet("Range").
               OlePropertySet("Text",str.c_str());
 //wdAlignParagraphCenter
 vVarParagraph.OlePropertySet("Alignment",0);
 str="                                   _____________________________________";
 vVarParagraphs.OleProcedure("Add");
 vVarParagraph=vVarParagraphs.OleFunction("Item",16);
 vVarParagraph.OlePropertyGet("Range").
               OlePropertySet("Text",str.c_str());
 //wdAlignParagraphCenter
 vVarParagraph.OlePropertySet("Alignment",0);
 str="                                   _____________________________________";
 vVarParagraphs.OleProcedure("Add");
 vVarParagraph=vVarParagraphs.OleFunction("Item",17);
 vVarParagraph.OlePropertyGet("Range").
               OlePropertySet("Text",str.c_str());
 //wdAlignParagraphCenter
 vVarParagraph.OlePropertySet("Alignment",0);


 //Масштаб отлбражения документа
 vVarApp.OlePropertyGet("ActiveWindow").
         OlePropertyGet("ActivePane").
         OlePropertyGet("View").
         OlePropertyGet("Zoom").
         OlePropertySet("Percentage",100);
 //Проверка грамматики
  vVarApp.OlePropertyGet("Options").
          OlePropertySet("CheckGrammarAsYouType",false);
  vVarApp.OlePropertyGet("Options").
          OlePropertySet("CheckGrammarWithSpelling",false);
 //Шрифт  устанавливаем для строки параграфа
 vVarParagraph=vVarParagraphs.OleFunction("Item",6);
 v=vVarParagraph.OlePropertyGet("Range").
               OlePropertyGet("Font");

 //Размер шрифта
 v.OlePropertySet("Size",18);
 //Имя шрифта
 v.OlePropertySet("Name","Times New Roman");
 //Стиль шрифта
 v.OlePropertySet("Bold",true);

 //Все буквы в верхнем регистре
 v.OlePropertySet("AllCaps",false);
 //Гравированный шрифт утопленный
  //В верхнем индексе
  v.OlePropertySet("Superscript",false);
 //В нижнем индексе
  v.OlePropertySet("Subscript",false);
 //Расстояние между буквами
  v.OlePropertySet("Spacing",0);
 //Масштаб
  v.OlePropertySet("Scaling",100);
 //Смещенный вверх или вниз в пикселях
  v.OlePropertySet("Position",0);
 //Кернинг - слияние в пунктах
 v.OlePropertySet("Kerning",1);
 //Анимация
 v.OlePropertySet("Animation",0);
 //Запоминаем где курсор - свойство Selection
 v=vVarApp.OlePropertyGet("Selection");
 //Сдвинем курсор на 5 параграфов вниз
 v.OleProcedure("MoveDown",4,5);
 //Встанем на начало строки
 v.OleProcedure("HomeKey",5);
 //Сдвигаемся на 13 символов вправо
 v.OleProcedure("MoveRight",1,13);

 ///////////////////////Cоздание таблицы//////////
 //Добавляем два параграфа
 vVarParagraphs.OleProcedure("Add");
 vVarParagraphs.OleProcedure("Add");
 //Выбираем ряд в параграфе
 vVarParagraph=vVarParagraphs.OleFunction("Item",11);
 vVarParagraph.OlePropertySet("Alignment",1);
 vVarRange = vVarParagraph.OlePropertyGet("Range");
 //Добавляем таблицу
 vVarDoc.OlePropertyGet("Tables").
         OleProcedure("Add", vVarRange, ADOTable1->RecordCount+1, 11,1,1);
 //Работать будем с первой таблицей
 vVarTable=vVarDoc.OlePropertyGet("Tables").
                   OleFunction("Item",1);
 //Выравниваем таблицу по центру
 vVarTable.OlePropertyGet("Rows").
           OlePropertySet("Alignment",1);
 //Установка ширины таблицы
 vVarTable.OleFunction("AutoFitBehavior",2);
 //Сетка в таблице
  vVarApp.OlePropertyGet("ActiveWindow").
          OlePropertyGet("View").
          OlePropertySet("TableGridlines",true);
 //Стиль таблицы
 vVarTable.OleFunction("AutoFormat",25);
 //Занесение информации в ячейки


  for(int i=1;i <= 11;i++)
  {
        String txt=ADOTable1->Fields->Fields[i-1]->FieldName;
        vVarCell=vVarTable.OleFunction("Cell",1,i);
        vVarCell.OleFunction("Select");
        v = vVarApp.OlePropertyGet("Selection").
        OlePropertyGet("Font");
        v.OlePropertySet("Size",16);
        v.OlePropertySet("Underline",0);
        vVarCell.OlePropertyGet("Range").
        OlePropertySet("Text",txt.c_str());
  }

  int k=2;
  ADOTable1->First();
  while(!ADOTable1->Eof) {
        if(ADOTable1->FieldByName("Кабинет")->AsString==Edit2->Text)
        {
        ADOTable1->Next();
        continue;
        }
        for(int i=1;i <= 11;i++)
        {
        String txt=ADOTable1->Fields->Fields[i-1]->AsString;

        vVarCell=vVarTable.OleFunction("Cell",k,i);
        vVarCell.OleFunction("Select");
        v = vVarApp.OlePropertyGet("Selection").
        OlePropertyGet("Font");
        v.OlePropertySet("Size",16);
        v.OlePropertySet("Underline",0);
        vVarCell.OlePropertyGet("Range").
        OlePropertySet("Text",txt.c_str());
        }
        k++;
        ADOTable1->Next();
    }

 AnsiString vAsCurDir=Edit6->Text.c_str();
 AnsiString vAsCurDir1=vAsCurDir+"\\Перемещения.doc";
 vVarDoc=vVarDocs.OleFunction("Item",1);
 vVarDoc.OleProcedure("SaveAs",vAsCurDir1.c_str());
 vVarApp.OleProcedure("Quit");
 fStart=false;
}
Exemplo n.º 15
0
//---------------------------------------------------------------------------
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;
}