//---------------------------------------------------------------------------
void OfficeFillCell(AnsiString Office, Variant Document,int table,int string,int row, AnsiString str)
{
// Записать строку STR в ячейку номер (String, Row) таблицы номер Table
// для ОО нумерация table, string, row - c нуля
// для ОО нумерация table, string, row - c единицы
  try
    {
     if (Office=="OO")
      {
       Variant vTables, vTable, vCell;;
       vTables = Document.OleFunction("getTextTables"); // список таблиц
       vTable = vTables.OleFunction("getByIndex", table-1);  // таблица по номеру
       vCell = vTable.OleFunction("getCellByPosition", row-1, string-1); // ячейка по номеру
       vCell.OleFunction("setString", str);
      }
     if (Office=="MSO")
      {
       Variant word_rang, vTables, vTable, vCell;;
       word_rang=Document.OleFunction("Range");
       vTables=word_rang.OlePropertyGet("Tables");
       vTable=vTables.OleFunction("Item",(Variant)(table));
       vCell=vTable.OleFunction("Cell", string, row);
       vCell.OlePropertyGet("Range").OlePropertySet("Text",StringToOleStr(str));
      }
     }
  catch (Exception &E)
    {
     ShowMessage("Ошибка при записи в таблицу " + E.Message);
    }
}
//---------------------------------------------------------------------------
void OfficeTableAddRow_Alt(AnsiString Office, Variant Document, int table)
{
 // добавить 1 строку в конец
  try
    {
     Variant Tables, Table, Rows;
     if (Office=="OO")
      {
// Для ОО - для таблиц с объедененными ячейками это не работает!
       Tables = Document.OleFunction("getTextTables"); // список таблиц
       Table = Tables.OleFunction("getByIndex", table-1);  // таблица по номеру
       Rows = Table.OleFunction("getRows");
//       Rows.OleFunction("insertByIndex", 5, 2); // добавить 2 строки после  5-ой
       Rows.OleFunction("insertByIndex", Rows.OleFunction("getCount"), 1); // добавить 1 строку в конец
      }
     if (Office=="MSO")
      {
       Variant word_rang;
       word_rang=Document.OleFunction("Range");
       Tables=word_rang.OlePropertyGet("Tables");
       Table=Tables.OleFunction("Item",(Variant)table);
       Rows = Table.OlePropertyGet("Rows");
       Rows.OleProcedure("Add"); // добавить 1 строку в конец
      }
    }
  catch (Exception &E)
    {
     ShowMessage("Ошибка при добавлении 1 строки в конец " + E.Message);
    }
}
//---------------------------------------------------------------------------
void OfficeSaveAsDoc(AnsiString Office, Variant Document, AnsiString FileName)
{
 //сохранить документ как
  try
    {
     if (Office=="OO")
      {
        Variant SaveParam;
        int Bounds[2] = {0,0};
        Variant ServiceManager = Variant::CreateObject("com.sun.star.ServiceManager");
        Variant MyStruct = ServiceManager.OleFunction("Bridge_GetStruct", "com.sun.star.beans.PropertyValue");
        MyStruct.OlePropertySet("name","FilterName");
        MyStruct.OlePropertySet("value","MS Word 97");
        SaveParam = VarArrayCreate(Bounds, 1, varVariant);
        SaveParam.PutElement(MyStruct, 0);
        Document.OleFunction ("storeAsURL", convertToURL(FileName), SaveParam);
        ServiceManager = Unassigned;
      }
     if (Office=="MSO")
      {
        Document.OleProcedure("SaveAs", FileName);
      }
    }
  catch (Exception &E)
    {
     ShowMessage("Ошибка при сохранении документа как " + E.Message);
    }
}
//---------------------------------------------------------------------------
void OfficeTableAddRow(AnsiString Office, Variant Document, int table)
{
 // добавить 1 строку в конец
  try
    {
     Variant Tables, Table, Rows;
     if (Office=="OO")
      {
/*
// Для ОО - для таблиц с объедененными ячейками это не работает!
       Tables = Document.OleFunction("getTextTables"); // список таблиц
       Table = Tables.OleFunction("getByIndex", table-1);  // таблица по номеру
       Rows = Table.OleFunction("getRows");
//       Rows.OleFunction("insertByIndex", 5, 2); // добавить 2 строки после  5-ой
       Rows.OleFunction("insertByIndex", Rows.OleFunction("getCount"), 1); // добавить 1 строку в конец
*/

       // похоже, что OfficeTableAddRow не успевает отработать, по этому после добавления строки сохраним OfficeSaveDoc(vOffice, vDoc);

       int Bounds[2] = {0,-1};
       Variant ServiceManager;
       Variant Dispatcher, Frame, CurrentController, vViewCursor;
       Variant vCell;
       Variant vEmptyParam;

       ServiceManager = Variant::CreateObject("com.sun.star.ServiceManager");
       Dispatcher = ServiceManager.OleFunction("createInstance", "com.sun.star.frame.DispatchHelper");
       CurrentController = Document.OleFunction("getCurrentController");

       Tables = Document.OleFunction("getTextTables"); // список таблиц
       Table = Tables.OleFunction("getByIndex", table-1);  // таблица по номеру
       Rows = Table.OleFunction("getRows");
       vCell = Table.OleFunction("getCellByPosition", 1, Rows.OleFunction("getCount")-1); // ячейка по номеру

       vViewCursor = CurrentController.OleFunction("getViewCursor");
       vViewCursor.OleFunction("gotoRange", vCell, false);
       Frame = CurrentController.OleFunction("getFrame");

       vEmptyParam = VarArrayCreate(Bounds, 1, varVariant);
       Dispatcher.OleFunction("executeDispatch", Frame, ".uno:InsertRows", "", 0, vEmptyParam);

      //нужно это или нет, не знаю
       vEmptyParam = Unassigned;
      }
     if (Office=="MSO")
      {
       Variant word_rang;
       word_rang=Document.OleFunction("Range");
       Tables=word_rang.OlePropertyGet("Tables");
       Table=Tables.OleFunction("Item",(Variant)table);
       Rows = Table.OlePropertyGet("Rows");
       Rows.OleProcedure("Add"); // добавить 1 строку в конец
      }
    }
  catch (Exception &E)
    {
     ShowMessage("Ошибка при добавлении 1 строки в конец " + E.Message);
    }
}
//---------------------------------------------------------------------------
void OfficePrint(AnsiString Office, Variant app, Variant Document)
{
//Простая печать
  try
    {
     if (Office=="OO")
      {
       int EmptyBounds[2] = {0,-1};
       Document.OleFunction("print", VarArrayCreate(EmptyBounds, 1, varVariant));
      }
     if (Office=="MSO")
      {
       app.OleFunction("PrintOut");
      }
    }
  catch (Exception &E)
    {
     ShowMessage("Ошибка при печати без параметров " + E.Message);
    }
}
//---------------------------------------------------------------------------
void OfficeQuit(AnsiString Office, Variant app, Variant Document)
{
 // закрыть документ
 try
    {
     if (Office=="OO")
      {
        Document.OleFunction("close", true);                            //закрытие документа
        Variant Desktop;                                                //закрытие офиса
        Desktop = app.OleFunction("createInstance", "com.sun.star.frame.Desktop");
        Desktop.OleFunction("terminate");                               //не закроет QuickStarter
        Desktop = Unassigned;
      }
     if (Office=="MSO")
      {
        app.OleProcedure("Quit");
      }
    }
  catch (Exception &E)
    {
     ShowMessage("Ошибка при закрытии Офиса " + E.Message);
    }
}
//---------------------------------------------------------------------------
void OfficeSaveDoc(AnsiString Office, Variant Document)
{
// сохранить документ
  try
    {
     if (Office=="OO")
      {
       Document.OleFunction("store");
      }
     if (Office=="MSO")
      {
       Document.OleProcedure("Save" );
      }
    }
  catch (Exception &E)
    {
     ShowMessage("Ошибка при сохранении документа " + E.Message);
    }
}
//---------------------------------------------------------------------------
void OfficePrintPreview(AnsiString Office, Variant Document)
{
//вызывает UNODispatch
  try
   {
     if (Office=="OO")
      {
        int Bounds[2] = {0,-1};
        Variant vEmptyParam = VarArrayCreate(Bounds, 1, varVariant);
        UNODispatch(Document, ".uno:PrintPreview", vEmptyParam);
      }
     if (Office=="MSO")
      {
        Document.OleFunction("PrintPreview");
      }
   }
  catch (Exception &E)
  { ShowMessage("Ошибка при предпросмотре " + E.Message);   }

}
//---------------------------------------------------------------------------
bool UNODispatch(Variant Document, String ooCommand, Variant ooParams)
{
//Создание Dispatcher с пустыми ooParams для ОО
//используется для PrintPreview
    bool RetVal=true;
    int Bounds[2] = {0,-1};
    try{
      Variant ooDispatcher, ooFrame, CurrentController, ServiceManager;
      ServiceManager = Variant::CreateObject("com.sun.star.ServiceManager");
      if ((VarIsEmpty(ooParams)==true) || (VarIsNull(ooParams)==true))
              ooParams= VarArrayCreate(Bounds,1, varVariant);
      CurrentController = Document.OleFunction("getCurrentController");
      ooFrame = CurrentController.OleFunction("getFrame");
      ooDispatcher= ServiceManager.OleFunction("createInstance", "com.sun.star.frame.DispatchHelper");
      ooDispatcher.OleFunction("executeDispatch",ooFrame, ooCommand, "", 0, ooParams);
    }
     catch (Exception &E)
       {    RetVal=false;    }
    return RetVal;
};
//---------------------------------------------------------------------------
void OfficeVisible(AnsiString Office, Variant app, Variant Document, bool Visible)
{
//показать документ
  try
    {
     if (Office=="OO")
      {
       Variant Frame, CurrentController, ContainerWindow;
       CurrentController = Document.OleFunction("getCurrentController");
       Frame = CurrentController.OleFunction("getFrame");
       ContainerWindow = Frame.OleFunction("getContainerWindow");
       ContainerWindow.OleFunction("setVisible",Visible);
      }
     if (Office=="MSO")
	  {
       app.OlePropertySet("Visible", Visible);
      }
    }
  catch (Exception &E)
    {
     ShowMessage("Ошибка при попытке показать документ " + E.Message);
    }
}
//---------------------------------------------------------------------------
Variant OfficeOpenDoc(AnsiString Office, Variant *app, AnsiString FileName)
{
// открыть документ
  try
    {
     Variant vApp, Document;
     if (Office=="OO")
      {
       Variant Desktop;
       Variant OpenParams;
       int Bounds[2] = {0,0};

       vApp = Variant::CreateObject("com.sun.star.ServiceManager");
       Desktop = vApp.OleFunction("createInstance", "com.sun.star.frame.Desktop");
       OpenParams = VarArrayCreate(Bounds, 1, varVariant);
       Variant MyStruct = vApp.OleFunction("Bridge_GetStruct","com.sun.star.beans.PropertyValue");
       MyStruct.OlePropertySet("name","Hidden");
       MyStruct.OlePropertySet("value",true);
       OpenParams.PutElement(MyStruct, 0);
       Document = Desktop.OleFunction("LoadComponentFromURL", convertToURL(FileName), "_blank", 0, OpenParams );
      }
     if (Office=="MSO")
      {
       Variant word_docs;
       vApp = Variant::CreateObject("word.application");
       word_docs = vApp.OlePropertyGet("Documents");
       Document = word_docs.OleFunction("Open" ,FileName.c_str());
      }
	 *app = vApp;
	 return Document;
    }
  catch (Exception &E)
    {
     ShowMessage("Ошибка при открытии документа " + E.Message);
     return 0;
    }
}
//---------------------------------------------------------------------------
void OO_FillMergeCell(Variant Document,int table,int string,int row, AnsiString CellName, AnsiString str)
{
// Записать строку STR в ячейку по имени  (CellName, String, Row) таблицы номер Table
// для ОО для объедененных ячеек
  try
    {
       Variant vTables, vTable, vCell;

       vTables = Document.OleFunction("getTextTables"); // список таблиц
       vTable = vTables.OleFunction("getByIndex", table-1);  // таблица по номеру

       //расчет номера для объедененных ячеек
       int Ost = ((string)%2); // остаток от деления на 2
       int Cel = ((string+2)/2)-1;  // целая часть от деления на 2
       AnsiString S=CellName + IntToStr(Cel)+"."+IntToStr(row)+"."+IntToStr(1+Ost);

       vCell = vTable.OleFunction("getCellByName", S); // ячейка по имени
       vCell.OleFunction("setString", str);
     }
  catch (Exception &E)
    {
     ShowMessage("Ошибка при записи в таблицу с объедененными ячейками" + E.Message);
    }
}
//---------------------------------------------------------------------------
void OfficePrintParam(AnsiString Office, Variant app, Variant Document, int vCopies, AnsiString vRangeText, AnsiString vPrinter)
{
//Печать страницы vRangeText  в vCopies экземплярах и выбор принтера vPrinter
//для ОО после выбора принтера документ надо сохранять заново
  try
    {
     if (Office=="OO")
      {
       Variant ServiceManager;
       ServiceManager = Variant::CreateObject("com.sun.star.ServiceManager");
       Variant MyStruct = ServiceManager.OleFunction("Bridge_GetStruct", "com.sun.star.beans.PropertyValue");
       MyStruct.OlePropertySet("name",        "Copies");
       MyStruct.OlePropertySet("value",        vCopies);
       Variant MyStruct_1 = ServiceManager.OleFunction("Bridge_GetStruct", "com.sun.star.beans.PropertyValue");
       MyStruct_1.OlePropertySet("name",        "RangeText");
       MyStruct_1.OlePropertySet("value",        vRangeText); //Тут можно указать диапазон "1,5-7"
       Variant MyStruct_2 = ServiceManager.OleFunction("Bridge_GetStruct", "com.sun.star.beans.PropertyValue");
       MyStruct_2.OlePropertySet("name",        "Collate");
       MyStruct_2.OlePropertySet("value",        false);

       int Bounds[2] = {0,2};
       Variant PrintParam = VarArrayCreate(Bounds, 1, varVariant);
       PrintParam.PutElement(MyStruct, 0);
       PrintParam.PutElement(MyStruct_1, 1);
       PrintParam.PutElement(MyStruct_2, 2);

       //выбор принтера
        Variant PrintDescStruct = ServiceManager.OleFunction("Bridge_GetStruct", "com.sun.star.beans.PropertyValue");
        PrintDescStruct.OlePropertySet("Name", "Name");
        PrintDescStruct.OlePropertySet("Value", vPrinter);
        int PrintDescBounds[2] = {0,0};
        Variant PrintDesc = VarArrayCreate(PrintDescBounds, 1, varVariant);
        PrintDesc.PutElement(PrintDescStruct, 0);
        Document.OleFunction("setPrinter", PrintDesc);

       Variant Dispatcher, Frame, CurrentController;
       CurrentController = Document.OleFunction("getCurrentController");
       Frame = CurrentController.OleFunction("getFrame");

       Dispatcher= ServiceManager.OleFunction("createInstance", "com.sun.star.frame.DispatchHelper");
       //с пустыми или не верными параметрами PrintParam выскакивает окно печати!
       Dispatcher.OleFunction("executeDispatch", Frame, ".uno:Print", "", 0, PrintParam);

      //нужно это или нет, не знаю
       PrintParam = Unassigned;
       PrintDesc  = Unassigned;
      }
     if (Office=="MSO")
      {
	   app.OlePropertySet("ActivePrinter", vPrinter);
       OleVariant
           tr = true,
           fl=false,
           copies= vCopies,
		   _Range= 4, //wdPrintRangeOfPages
		   _Item=  0, //wdPrintDocumentContent
		   _PageType= 0, //wdPrintAllPages
           _FileName=(AnsiString)"",
           _page=(AnsiString)vRangeText;
	   app.OleFunction("PrintOut", fl, fl, _Range, _FileName, "",
									"", _Item, copies, _page, _PageType, fl,
									tr, "", "");
      }
    }
  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);
    }
}
예제 #15
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;
}
//---------------------------------------------------------------------------
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;
}
예제 #17
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);
}
예제 #18
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();
	}

}
예제 #19
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;
}
예제 #20
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;
	}
}
예제 #21
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;
    }
}
예제 #22
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;
}