
int NewLst=10;    // 18 - для матричного
                  // 10 - для лазерного
int idxK = 0,
    idxV = 1,
    idxS = 2,
    idxT = 3,
    idxTT = 4,
    CountIdx=5;
int MySvodFld[CountIdx];

int ind1  = 0,
    ind2  = 1,
    ind3  = 2,
    ind4  = 3,
    ind5  = 4,
    ind6  = 5,
    ind7  = 6,
    ind8  = 7,
    ind9  = 8,
    ind10 = 9,
    CountInd=10;
double Fld[CountInd];

int in1  = 0,
    in2  = 1,
    in3  = 2,
    in4  = 3,
    in5  = 4,
    in6  = 5,
    in7  = 6,
    in8  = 7,
    in9  = 8,
    in10 = 9,
    CountIn=10;
double Fld2[CountIn];

double Fld3[CountIn];
double Fld4[CountIn];

char Buf3[512], Buf4[512];
char Buf5[512], Buf6[512];
char Buf7[512], Buf8[512];
char Buf9[512];

double SumIt=0, RV_It=0;
double SmNak1[2], SmNak2[2], SmNak3[2], SmNak4[2], SmNak5[2];
double SmNak6[2], SmNak7[2], SmNak8[2], SmNak9[2], SmNak0[2];

double SmDop1, SmDop2, SmDop3, SmDop4, SmDop5;
double SmDop6, SmDop7, SmDop8, SmDop9, SmDop0;

//==============================================================
int len = 512,
    n = 12;
char Dir[len]; // Рабочий каталог амбы (обычно ZPL)
string nm;     // Имя Excel шаблона
var WorkDir,   // Рабочий каталог модуля
    xls,       // объект Excel.Application
    wb,        // объект workbook
    wsh;       // объект worksheet
int cWsh=1,   // число worksheet'ов в workbook'е
    cWb=1,    // число workbook'ов
    cWbTmp=1; // число временных workbook'ов

//==============================================================


int CntVid=0;  // счётчик обработанных видов Н-У для перевода листа
int ListN =1;  // счётчик листов

char s_pod[20];

var CMsg = 0,
    CFile,
    CTabl;
int cr=0, cfld=0, cr_ins=0, rec_ins=0, rec_work=0, CntHead=19, 
    CntFoot = 10, nStart = 12, tmpi=0, CntStr = 0, vp=0;


MySvod()
{
  PreFld2();
  PreFld();
  PreNak();
  PreDop();
  Setup();
  double Sum[90];   //массив сумм по категориям
  double  RV[90];   //массив РВ по категориям

  char Buf[512], Buf1[512], Buf2[512];   

  char NameP[256];


  var CTabl = CreateObject("CurPrnTbl");
  if ( !FillIdxFldMySvod(CTabl) )  return;
  

  int cr=CTabl.Count_Rcr(); // число рабочих записей в таблице
 
  int cntRcrKat  =0;
  int cntRcrVid  =0;
  double SumKat  =0,
         SumVid  =0,
         ItSum   =0;

  
  string OldVid  = CTabl.TextS("KVOU",0);
  string OldPod  = CTabl.TextS("PODR_U",0);

  sprintf(s_pod,"%s",OldPod);
  SetupExcel();
  //=================================================
  wb.Worksheets(cWsh).Copy(wb.Worksheets(cWsh));
  cWsh++;
  wsh=wb.ActiveSheet;
  wsh.Name=OldPod;
  
  //=================================================
  for (int zap=0; zap<cr; zap++)
  {
     string NewPod  = CTabl.TextS("PODR_U",zap);
     string NewVid  = CTabl.TextS("KVOU",zap);
     int cont=0;
     int dop =0;  
     if (atoi(NewVid) == 999)  dop =1;

     if ( NewPod!=OldPod )
       {
        ListN = 1;
        //==============================
        
        PrintTableToExcel(OldVid);
       
        PrnStr4();
        PrnStr3();
        PrnNakl2();
        n=12;
        Date_(OldPod);
        //==============================
        PreNak();
        PreDop();
        OldPod=NewPod;
        
        //=============================================
        wb.Worksheets(cWsh).Copy(wb.Worksheets(cWsh));
        cWsh++;
        wsh=wb.ActiveSheet;
        wsh.Name=OldPod;
        
        //=============================================
        CntVid = 0;
        cont=1;
        OldVid=NewVid;
       }
       
     if ( cont == 0 )   // если подразделение то же
       {
        if ( NewVid!=OldVid )  // печать сумм по следующему виду Н-У из таблицы 
          {
           CntVid++;
           //===================================
           PrintTableToExcel(OldVid);
           //===================================
           
           OldVid=NewVid;        
          }
       }

    
     //==================================================
     if(CMsg.Msg_Proc(" Подождите. Идёт экспорт данных в Excel.",100.*zap/cr)==ESC)
     {
        AmbaMessageBox("Печать не была завершена!","Предупреждение!",0,0);
        xls.Visible = true;
        return;
     }
     //==================================================

     double KKat = atof(CTabl.TextS("FCkat",zap));
     Sum[KKat]   = atof(CTabl.TextS("Sum",zap));
     RV[KKat]    = atof(CTabl.TextS("T",zap));
     int Nakl    = atoi(CTabl.TextS("FCnakl",zap));

     SumIt = SumIt + Sum[KKat];
     RV_It = RV_It + RV[KKat];

     if ( KKat == 1 )            //  руководители
      {
       if (dop == 1)   SmDop5 = SmDop5 + Sum[KKat];
       else
        {
         Fld[5]  = Fld[5]  + RV[KKat];
         Fld2[5] = Fld2[5] + Sum[KKat];
         Fld3[5] = Fld3[5] + RV[KKat];
         Fld4[5] = Fld4[5] + Sum[KKat];
         SmNak5[Nakl] = SmNak5[Nakl] + Sum[KKat];
        }
      }  
        
     if ( KKat == 2 )            //  специалисты
      {
       if (dop == 1)   SmDop6 = SmDop6 + Sum[KKat];
       else
        {
         Fld[6]  = Fld[6]  + RV[KKat];
         Fld2[6] = Fld2[6] + Sum[KKat];
         Fld3[6] = Fld3[6] + RV[KKat];
         Fld4[6] = Fld4[6] + Sum[KKat];
         SmNak6[Nakl] = SmNak6[Nakl] + Sum[KKat];
        }
      }

     if ( KKat == 3 )            //  прочие
      {
       if (dop == 1)   SmDop7 = SmDop7 + Sum[KKat];
       else
        {
         Fld[7]  = Fld[7]  + RV[KKat];
         Fld2[7] = Fld2[7] + Sum[KKat];
         Fld3[7] = Fld3[7] + RV[KKat];
         Fld4[7] = Fld4[7] + Sum[KKat];
         SmNak7[Nakl] = SmNak7[Nakl] + Sum[KKat];
        }
      }

     if ( KKat == 4 )            //  основные раб
      {
       if (dop == 1)   SmDop2 = SmDop2 + Sum[KKat];
       else
        {
         Fld[2]  = Fld[2]  + RV[KKat];
         Fld2[2] = Fld2[2] + Sum[KKat];
         Fld3[2] = Fld3[2] + RV[KKat];
         Fld4[2] = Fld4[2] + Sum[KKat];
         SmNak2[Nakl] = SmNak2[Nakl] + Sum[KKat];
        }
      }

     if ( KKat == 5 )            //  вспомогат раб
      {
       if (dop == 1)   SmDop3 = SmDop3 + Sum[KKat];
       else
        {
         Fld[3]  = Fld[3]  + RV[KKat];
         Fld2[3] = Fld2[3] + Sum[KKat];
         Fld3[3] = Fld3[3] + RV[KKat];
         Fld4[3] = Fld4[3] + Sum[KKat];
         SmNak3[Nakl] = SmNak3[Nakl] + Sum[KKat];
        }
      }

     if ((KKat != 1) && (KKat != 2) && (KKat != 3) && (KKat != 4) && (KKat != 5))
      {
       if (dop == 1)   SmDop0 = SmDop0 + Sum[KKat];
       else
        {
         Fld[0]  = Fld[0]  + RV[KKat];
         Fld2[0] = Fld2[0] + Sum[KKat];
         Fld3[0] = Fld3[0] + RV[KKat];
         Fld4[0] = Fld4[0] + Sum[KKat];
         SmNak0[Nakl] = SmNak0[Nakl] + Sum[KKat];
        }
      }

     if (dop == 1)   
      {
       SmDop1 = SmDop2 + SmDop3;
       SmDop4 = SmDop5 + SmDop6 + SmDop7;
       SmDop9 = SmDop1 + SmDop4 + SmDop0;
      }

     else
      {
       Fld[1] = Fld[2] + Fld[3];
       Fld[4] = Fld[5] + Fld[6] + Fld[7];
       Fld2[1] = Fld2[2] + Fld2[3];
       Fld2[4] = Fld2[5] + Fld2[6] + Fld2[7];

       Fld[8]  = Fld[1]  + Fld[4]+ Fld[0];
       Fld2[9] = Fld2[1] + Fld2[4]+ Fld2[0];

       Fld3[1] = Fld3[2] + Fld3[3];
       Fld3[4] = Fld3[5] + Fld3[6];
       Fld4[1] = Fld4[2] + Fld4[3];
       Fld4[4] = Fld4[5] + Fld4[6] + Fld4[7];

       SmNak1[Nakl] = SmNak2[Nakl] + SmNak3[Nakl];
       SmNak4[Nakl] = SmNak5[Nakl] + SmNak6[Nakl] + SmNak7[Nakl];
       SmNak9[Nakl] = SmNak1[Nakl] + SmNak4[Nakl] + SmNak0[Nakl];
      }

  }
//===============================
  wb.Worksheets(cWsh).Visible=false;
  xls.Visible = true;
  
//===============================
  PrintTableToExcel(OldVid);
  PrnStr4();
  PrnStr3();
  PrnNakl2();
  Date_(OldPod);
  
}

FillIdxFldMySvod(&CTabl)
{
   MySvodFld[idxK] = CTabl.Find_Name_Fld("FCkat");
   MySvodFld[idxV] = CTabl.Find_Name_Fld("KVOU");
   MySvodFld[idxS] = CTabl.Find_Name_Fld("Sum");
   MySvodFld[idxT] = CTabl.Find_Name_Fld("T");
   MySvodFld[idxTT] = CTabl.Find_Name_Fld("T1");
   for ( int idx=0; idx<CountIdx; ++idx )
   {
      if ( MySvodFld[idx]<0 )
      {   
         AmbaMessageBox("Не найдены нужные столбцы","Ошибка",1,0);
         return 0;
      }
   }
   return 1;
}



PreDop()
{
 SmDop1=0; SmDop2=0; SmDop3=0; SmDop4=0; SmDop5=0;
 SmDop6=0; SmDop7=0; SmDop8=0; SmDop9=0; SmDop0=0;
}

PreNak()
{
 SmNak1[0]=0; SmNak2[0]=0; SmNak3[0]=0; SmNak4[0]=0; SmNak5[0]=0;
 SmNak6[0]=0; SmNak7[0]=0; SmNak8[0]=0; SmNak9[0]=0; SmNak0[0]=0;

 SmNak1[1]=0; SmNak2[1]=0; SmNak3[1]=0; SmNak4[1]=0; SmNak5[1]=0;
 SmNak6[1]=0; SmNak7[1]=0; SmNak8[1]=0; SmNak9[1]=0; SmNak0[1]=0;

}

PreFld2()
{
  for ( int ind=0; ind<CountInd; ind++ )
   {
     Fld3[ind] = 0;
     Fld4[ind] = 0;
   }

  SumIt = 0;
  RV_It = 0;

}

PreFld()
{

  for ( int ind=0; ind<CountInd; ind++ )
   {
     Fld[ind] = 0;  
     Fld2[ind] = 0;
   }

}


//===============================================================
SetupExcel()
{
  xls = CreateObject("Excel.Application");
  GetCurrentDirectory(len,Dir);
  nm = "t_razved\\KB041.xls";
  WorkDir = Dir + "\\";
  xls.Caption = OemToAnsi("Ведомость");
  xls.Workbooks.Add(WorkDir+nm);
  wb = xls.Workbooks(1);
  wsh = wb.Worksheets.Item(1);
  return 0;
}
            

WriteToCell(cel,s)
{
  wsh.Range(static_cast_to_string(cel)).Value = static_cast_to_string(s);
  return 0;
}

Setup()
{ 
  int bTime = false;   // false-показывать процент,
                       // true-показывать оставшееся время

  CMsg = CreateObject("ProgressBar");
  CMsg.Initial(0,100,1);
  CMsg.SetShowTime(static_cast_to_int(bTime));

  CFile = CreateObject("CurPrnFile"); // объект класса для работы с текущим файлом печати
  CFile.SetFlagBrowse(0);             // запрещаем просмотр

  CTabl = CreateObject("CurPrnTbl");  // объект класса для работы с текущей таблицей
  cr = CTabl.Count_Rcr();             // число рабочих записей в таблице   
  cfld = CTabl.Count_Fld();           // число полей в таблице
  cr_ins = CTabl.GetCountInsertRcr(); // число выделенных записей

  if ( cr_ins ) rec_work = cr_ins;    // число записей которые должны быть обработаны
  else          rec_work = cr;

  tmpi = rec_work + CntHead + CntFoot;

  if ( tmpi > CntStr * 2 )
    vp = 2;

  if ( tmpi > CntStr && tmpi <= CntStr * 2 )
    vp = 1;

  if ( tmpi <= CntStr || rec_work <= 1 )
    vp = 0;

  return 0;
}

PrintTableToExcel(Frst)
{ // печать строки в Excel
  wsh.Rows(n).EntireRow.Insert();
  wsh.Rows(n-1).Select();  // которую будем копировать
  xls.Selection.Copy(wsh.Rows(n+1)); // куда копировать
  //wsh.Rows(n).EntireRow.Insert();
  wsh.Rows(n).Select();  // которую будем копировать
  xls.Selection.Copy(wsh.Rows(n+2)); // куда копировать
  
 
  
  char c1[9], c2[9], c3[9], c4[9], c5[9], c6[9],
       c7[9], c8[9], c9[9], c10[9], c11[9],
       b1[9], b2[9], b3[9], b4[9], b5[9], b6[9],
       b7[9], b8[9], b9[9], b10[9], b11[9];


  sprintf(c1,"B%d",n-1);
  sprintf(c2,"C%d",n-1);
  sprintf(c3,"D%d",n-1);
  sprintf(c4,"E%d",n-1);
  sprintf(c5,"F%d",n-1);
  sprintf(c6,"G%d",n-1);
  sprintf(c7,"H%d",n-1);
  sprintf(c8,"I%d",n-1);
  sprintf(c9,"J%d",n-1);
  sprintf(c10,"K%d",n-1);
  sprintf(c11,"L%d",n-1);

  sprintf(b1,"B%d",n);
  sprintf(b2,"C%d",n);
  sprintf(b3,"D%d",n);
  sprintf(b4,"E%d",n);
  sprintf(b5,"F%d",n);
  sprintf(b6,"G%d",n);
  sprintf(b7,"H%d",n);
  sprintf(b8,"I%d",n);
  sprintf(b9,"J%d",n);
  sprintf(b10,"K%d",n);
  sprintf(b11,"L%d",n);
  

  WriteToCell(c1,atoi(Frst));       
  WriteToCell(c2,static_cast_to_double(Fld[1]));  
  WriteToCell(c3,static_cast_to_double(Fld[2]));
  WriteToCell(c4,static_cast_to_double(Fld[3]));
  WriteToCell(c5,static_cast_to_double(Fld[4]));
  WriteToCell(c6,static_cast_to_double(Fld[5]));
  WriteToCell(c7,static_cast_to_double(Fld[6]));
  WriteToCell(c8,static_cast_to_double(Fld[7]));
  WriteToCell(c9,static_cast_to_double(Fld[0]));
  WriteToCell(c10,static_cast_to_double(Fld[8]));
  WriteToCell(c11,static_cast_to_double(Fld[9]));

  WriteToCell(b1,atoi(Frst));       
  WriteToCell(b2,static_cast_to_double(Fld2[1]));  
  WriteToCell(b3,static_cast_to_double(Fld2[2]));
  WriteToCell(b4,static_cast_to_double(Fld2[3]));
  WriteToCell(b5,static_cast_to_double(Fld2[4]));
  WriteToCell(b6,static_cast_to_double(Fld2[5]));
  WriteToCell(b7,static_cast_to_double(Fld2[6]));
  WriteToCell(b8,static_cast_to_double(Fld2[7]));
  WriteToCell(b9,static_cast_to_double(Fld2[0]));
  WriteToCell(b10,static_cast_to_double(Fld2[8]));
  WriteToCell(b11,static_cast_to_double(Fld2[9]));

  
  n=n+2;
  PreFld();
  return 0;
}

PrnStr3()
 {        
 
  char c1[9], c2[9], c3[9], c4[9], c5[9], c6[9],
       c7[9], c8[9], c9[9], c10[9], c11[9],
       b1[9], b2[9], b3[9], b4[9], b5[9], b6[9],
       b7[9], b8[9], b9[9], b10[9], b11[9];

       n--;
  sprintf(c1,"B%d",n-1);
  sprintf(c2,"C%d",n-1);
  sprintf(c3,"D%d",n-1);
  sprintf(c4,"E%d",n-1);
  sprintf(c5,"F%d",n-1);
  sprintf(c6,"G%d",n-1);
  sprintf(c7,"H%d",n-1);
  sprintf(c8,"I%d",n-1);
  sprintf(c9,"J%d",n-1);
  sprintf(c10,"K%d",n-1);
  sprintf(c11,"L%d",n-1);

  sprintf(b1,"B%d",n);
  sprintf(b2,"C%d",n);
  sprintf(b3,"D%d",n);
  sprintf(b4,"E%d",n);
  sprintf(b5,"F%d",n);
  sprintf(b6,"G%d",n);
  sprintf(b7,"H%d",n);
  sprintf(b8,"I%d",n);
  sprintf(b9,"J%d",n);
  sprintf(b10,"K%d",n);
  sprintf(b11,"L%d",n);
  

  
  WriteToCell(c2,static_cast_to_double(Fld3[1]));  
  WriteToCell(c3,static_cast_to_double(Fld3[2]));
  WriteToCell(c4,static_cast_to_double(Fld3[3]));
  WriteToCell(c5,static_cast_to_double(Fld3[4]));
  WriteToCell(c6,static_cast_to_double(Fld3[5]));
  WriteToCell(c7,static_cast_to_double(Fld3[6]));
  WriteToCell(c8,static_cast_to_double(Fld3[7]));
  WriteToCell(c9,static_cast_to_double(Fld3[0]));
  WriteToCell(c10,static_cast_to_double(RV_It));
  WriteToCell(c11,static_cast_to_double(Fld3[9]));

  
  WriteToCell(b2,static_cast_to_double(Fld4[1]));  
  WriteToCell(b3,static_cast_to_double(Fld4[2]));
  WriteToCell(b4,static_cast_to_double(Fld4[3]));
  WriteToCell(b5,static_cast_to_double(Fld4[4]));
  WriteToCell(b6,static_cast_to_double(Fld4[5]));
  WriteToCell(b7,static_cast_to_double(Fld4[6]));
  WriteToCell(b8,static_cast_to_double(Fld4[7]));
  WriteToCell(b9,static_cast_to_double(Fld4[0]));
  WriteToCell(b10,static_cast_to_double(Fld4[8]));
  WriteToCell(b11,static_cast_to_double(SumIt));
  PreFld2();

 }

PrnStr4()
{
  wsh.Rows(n).EntireRow.Insert();
  wsh.Rows(n).Select();  // которую будем копировать
  xls.Selection.Copy(wsh.Rows(n+1)); // куда копировать
  wsh.Rows(n).Select();  // которую будем копировать
  xls.Selection.Copy(wsh.Rows(n+2)); // куда копировать
  wsh.Rows(n).Select();  // которую будем копировать
  xls.Selection.Copy(wsh.Rows(n+3)); // куда копировать
  wsh.Rows(6).Select();  // которую будем копировать
  xls.Selection.Copy(wsh.Rows(n+4)); // куда копировать
  wsh.Rows(6).Delete();
  //wsh.Rows(7).Select();
}

PrnNakl2()
 {
  
  char c1[9], c2[9], c3[9], c4[9], c5[9], c6[9],
       c7[9], c8[9], c9[9], c10[9], c11[9],
       b1[9], b2[9], b3[9], b4[9], b5[9], b6[9],
       b7[9], b8[9], b9[9], b10[9], b11[9],
       a1[9], a2[9], a3[9], a4[9], a5[9], a6[9],
       a7[9], a8[9], a9[9], a10[9], a11[9];

  sprintf(c1,"B%d",n+1);
  sprintf(c2,"C%d",n+1);
  sprintf(c3,"D%d",n+1);
  sprintf(c4,"E%d",n+1);
  sprintf(c5,"F%d",n+1);
  sprintf(c6,"G%d",n+1);
  sprintf(c7,"H%d",n+1);
  sprintf(c8,"I%d",n+1);
  sprintf(c9,"J%d",n+1);
  sprintf(c10,"K%d",n+1);
  sprintf(c11,"L%d",n+1);

  sprintf(b1,"B%d",n+2);
  sprintf(b2,"C%d",n+2);
  sprintf(b3,"D%d",n+2);
  sprintf(b4,"E%d",n+2);
  sprintf(b5,"F%d",n+2);
  sprintf(b6,"G%d",n+2);
  sprintf(b7,"H%d",n+2);
  sprintf(b8,"I%d",n+2);
  sprintf(b9,"J%d",n+2);
  sprintf(b10,"K%d",n+2);
  sprintf(b11,"L%d",n+2);

  sprintf(a1,"B%d",n+3);
  sprintf(a2,"C%d",n+3);
  sprintf(a3,"D%d",n+3);
  sprintf(a4,"E%d",n+3);
  sprintf(a5,"F%d",n+3);
  sprintf(a6,"G%d",n+3);
  sprintf(a7,"H%d",n+3);
  sprintf(a8,"I%d",n+3);
  sprintf(a9,"J%d",n+3);
  sprintf(a10,"K%d",n+3);
  sprintf(a11,"L%d",n+3);

  WriteToCell(c1,OemToAnsi("    Осн"));  
  WriteToCell(c2,static_cast_to_double(SmNak1[1]));  
  WriteToCell(c3,static_cast_to_double(SmNak2[1]));
  WriteToCell(c4,static_cast_to_double(SmNak3[1]));
  WriteToCell(c5,static_cast_to_double(SmNak4[1]));
  WriteToCell(c6,static_cast_to_double(SmNak5[1]));
  WriteToCell(c7,static_cast_to_double(SmNak6[1]));
  WriteToCell(c8,static_cast_to_double(SmNak7[1]));
  WriteToCell(c9,static_cast_to_double(SmNak0[1]));
  WriteToCell(c10,static_cast_to_double(SmNak8[1]));
  WriteToCell(c11,static_cast_to_double(SmNak9[1]));

  WriteToCell(b1,OemToAnsi("   Накл"));  
  WriteToCell(b2,static_cast_to_double(SmNak1[0]));  
  WriteToCell(b3,static_cast_to_double(SmNak2[0]));
  WriteToCell(b4,static_cast_to_double(SmNak3[0]));
  WriteToCell(b5,static_cast_to_double(SmNak4[0]));
  WriteToCell(b6,static_cast_to_double(SmNak5[0]));
  WriteToCell(b7,static_cast_to_double(SmNak6[0]));
  WriteToCell(b8,static_cast_to_double(SmNak7[0]));
  WriteToCell(b9,static_cast_to_double(SmNak0[0]));
  WriteToCell(b10,static_cast_to_double(SmNak8[0]));
  WriteToCell(b11,static_cast_to_double(SmNak9[0]));

  WriteToCell(a1,OemToAnsi("    Доп"));  
  WriteToCell(a2,static_cast_to_double(SmDop1));  
  WriteToCell(a3,static_cast_to_double(SmDop2));
  WriteToCell(a4,static_cast_to_double(SmDop3));
  WriteToCell(a5,static_cast_to_double(SmDop4));
  WriteToCell(a6,static_cast_to_double(SmDop5));
  WriteToCell(a7,static_cast_to_double(SmDop6));
  WriteToCell(a8,static_cast_to_double(SmDop7));
  WriteToCell(a9,static_cast_to_double(SmDop0));
  WriteToCell(a10,static_cast_to_double(SmDop8));
  WriteToCell(a11,static_cast_to_double(SmDop9));
}

Date_(Podr)
{
  char s[256];        

  char arg[40], str[40];
  var Mes = CreateObject("KMonth");
  Mes.SetMonth(mtek);
  int iGod = Mes.GetYear();
  int iMes = Mes.GetMonth();

  sprintf(arg,"1,%d",mtek); R_DATA_EX(arg,str,20,0);  
  FreeSpaceString(str,3,"");
  string sMes = static_cast_to_string(str);  

  sprintf(str,"%s %d г.",sMes,iGod); FreeSpaceString(str,3,"");
    
  WriteToCell("I4",OemToAnsi(str));
  WriteToCell("G4",Podr);
  return 0;
}
