// начало


  string name;                  // читаем имя workbook'а, чтобы обращатья потом к нему по имени
  var WSheet1; // создаем ссылку на на наш worksheet чтобы избежать впоследствии длинных записей
  string cell; // в эту строку будем записывать имена ячеек worksheet'а
  int len = 512;
  char Dir[len]; // Рабочий каталог амбы (обычно ZPL)
  string nm;     // Имя Excel шаблона
  var WorkDir,   // Рабочий каталог модуля
      xls,       // объект Excel.Application
      wb,        // объект workbook
      wsh;       // объект worksheet

  char ex1[99], ex2[10], ex3[12];

  int nStart = 8;
  int n = nStart;
  int NmLnEx = nStart;


int NewLst = 56;     //  56 - для матричн

int idxP = 0,
    idxK = 1,
    idxT = 2,
    idxS = 3,
    idxS01 = 4,
    idxS02 = 5,
    idxS03 = 6,
    idxS04 = 7,
    idxS05 = 8,
    idxS06 = 9,
    idxS07 = 10,
    idxS08 = 11,
    idxS09 = 12,
    idxS10 = 13,
    idxS11 = 14,
    idxS12 = 15,
    idxS13 = 16,
    idxS14 = 17,
    CountIdx=18;
int TblFld[CountIdx];


  double SumObS=0, SumObR=0, SumObV=0;
  double SrSm, SrSmN;
  double SumS[20];   // для строки  Служащие
  double SumR[20];   // для строки  Рабочие
  double SumV[20];   // для строки  Всего
  double s=0, r=0, v=0, sIt=0;      //  суммы общие по строке "Служ" "Раб"
  double sm23=0, sm25=0, sm26=0, sm29=0;
  double sm23_sl=0, sm23_rb=0, sm25_sl=0, sm25_rb=0, sm26_sl=0, sm26_rb=0, sm29_sl=0, sm29_rb=0;  // 20180119

  double Sum23[20];   // для строки  БалСч_23    20131005
  double Sum25[20];   // для строки  БалСч_25    20131005
  double Sum26[20];   // для строки  БалСч_26    20131005
  double Sum29[20];   // для строки  БалСч_29    20131005

  double Sum23_sl[20];   // для строки  БалСч_23_служ  20180119
  double Sum23_rb[20];   // для строки  БалСч_23_раб   20180119
  double Sum25_sl[20];   // для строки  БалСч_25_служ  20180119
  double Sum25_rb[20];   // для строки  БалСч_25_раб   20180119
  double Sum26_sl[20];   // для строки  БалСч_26_служ  20180119
  double Sum26_rb[20];   // для строки  БалСч_26_раб   20180119
  double Sum29_sl[20];   // для строки  БалСч_29_служ  20180119
  double Sum29_rb[20];   // для строки  БалСч_29_раб   20180119


  double Sm23N[20];   //  для       20131005
  double Sm25N[20];   //  строк     20131005
  double Sm26N[20];   //  по        20131005
  double Sm29N[20];   //  НТН       20131005
  double Sm23N_sl[20];   //      20180120
  double Sm25N_sl[20];   //      20180120
  double Sm26N_sl[20];   //      20180120
  double Sm29N_sl[20];   //      20180120
  double Sm23N_rb[20];   //      20180120
  double Sm25N_rb[20];   //      20180120
  double Sm26N_rb[20];   //      20180120
  double Sm29N_rb[20];   //      20180120


  double SmSN[20];   //  для строк
  double SmRN[20];   //    по
  double SmVN[20];   //   НТН
  double sN=0, rN=0, vN=0;
  double sm23N=0, sm25N=0, sm26N=0, sm29N=0;
  double sm23N_sl=0, sm25N_sl=0, sm26N_sl=0, sm29N_sl=0;  // 20180120
  double sm23N_rb=0, sm25N_rb=0, sm26N_rb=0, sm29N_rb=0;  // 20180120

  double SumIt[20];
  double SrIT = 0;

  double SumKP[20], SumKPsl[20], SumKPrb[20];
  double SumKP23[20], SumKP25[20], SumKP26[20], SumKP29[20];
  double SumZV[20], SumZVsl[20], SumZVrb[20];
  double SumZV23[20], SumZV25[20], SumZV26[20], SumZV29[20];
  double SumPR[20], SumPRsl[20], SumPRrb[20];                   // 2014_02_24
  double SumPR23[20], SumPR25[20], SumPR26[20], SumPR29[20];    // 2014_02_24

  double SumIt23[20], SumIt25[20], SumIt26[20], SumIt29[20];    // 2014_03_03   для общих итогов по всему
  double sIt23=0, sIt25=0, sIt26=0, sIt29=0;                            // 2014_03_03   заводу по счетам


  double SumKP23_sl[20], SumKP25_sl[20], SumKP26_sl[20], SumKP29_sl[20];   //20180119
  double SumZV23_sl[20], SumZV25_sl[20], SumZV26_sl[20], SumZV29_sl[20];   //20180119
  double SumPR23_sl[20], SumPR25_sl[20], SumPR26_sl[20], SumPR29_sl[20];   //20180119
  double SumKP23_rb[20], SumKP25_rb[20], SumKP26_rb[20], SumKP29_rb[20];   //20180119
  double SumZV23_rb[20], SumZV25_rb[20], SumZV26_rb[20], SumZV29_rb[20];   //20180119
  double SumPR23_rb[20], SumPR25_rb[20], SumPR26_rb[20], SumPR29_rb[20];   //20180119

  int kp, zv, pr;
  double sItKP=0, sItZV=0, sItPR=0;         // для итогов по КП и Заводу
  double sItKPsl=0, sItKPrb=0;     // отдельно по служ и раб
  double sItZVsl=0, sItZVrb=0;     // отдельно по служ и раб
  double sItPRsl=0, sItPRrb=0;     // отдельно по служ и раб
  double sItKP23=0, sItKP25=0, sItKP26=0, sItKP29=0;                //20131007  
  double sItZV23=0, sItZV25=0, sItZV26=0, sItZV29=0;                //20131007  
  double sItPR23=0, sItPR25=0, sItPR26=0, sItPR29=0;                //2014_02_24

  double sItKP23_sl=0, sItKP25_sl=0, sItKP26_sl=0, sItKP29_sl=0;    //20180119
  double sItKP23_rb=0, sItKP25_rb=0, sItKP26_rb=0, sItKP29_rb=0;    //20180119
  double sItZV23_sl=0, sItZV25_sl=0, sItZV26_sl=0, sItZV29_sl=0;    //20180119
  double sItZV23_rb=0, sItZV25_rb=0, sItZV26_rb=0, sItZV29_rb=0;    //20180119
  double sItPR23_sl=0, sItPR25_sl=0, sItPR26_sl=0, sItPR29_sl=0;    //20180119
  double sItPR23_rb=0, sItPR25_rb=0, sItPR26_rb=0, sItPR29_rb=0;    //20180119


  double SrKP=0, SrZV=0, SrPR=0;           // численн по КП и Заводу
  double SrKPsl=0, SrKPrb=0;       // отдельно по служ и раб
  double SrZVsl=0, SrZVrb=0;       // отдельно по служ и раб
  double SrPRsl=0, SrPRrb=0;
  double SrSmKP, SrSmZV, SrSmPR;

  double SrKP23=0, SrKP25=0, SrKP26=0, SrKP29=0;    //вместо       SrKPsl=0, SrKPrb=0;  20131005
  double SrZV23=0, SrZV25=0, SrZV26=0, SrZV29=0;    //вместо       SrZVsl=0, SrZVrb=0;  20131005
  double SrPR23=0, SrPR25=0, SrPR26=0, SrPR29=0;    //2014_02_24
  double SrIt23=0, SrIt25=0, SrIt26=0, SrIt29=0;    // 2014_03_03  для общих итогов по счетам

  double SrKP23_sl=0, SrKP25_sl=0, SrKP26_sl=0, SrKP29_sl=0;    // 20180119
  double SrKP23_rb=0, SrKP25_rb=0, SrKP26_rb=0, SrKP29_rb=0;    // 20180119
  double SrZV23_sl=0, SrZV25_sl=0, SrZV26_sl=0, SrZV29_sl=0;    // 20180119
  double SrZV23_rb=0, SrZV25_rb=0, SrZV26_rb=0, SrZV29_rb=0;    // 20180119
  double SrPR23_sl=0, SrPR25_sl=0, SrPR26_sl=0, SrPR29_sl=0;    // 20180119
  double SrPR23_rb=0, SrPR25_rb=0, SrPR26_rb=0, SrPR29_rb=0;    // 20180119


  double SrS=0, SrR=0, SrV=0;      // численн по подразд
  double SrSN=0, SrRN=0, SrVN=0;   // численн по НТН

  double Sr23=0, Sr25=0, Sr26=0, Sr29=0;      // численн по подразд 20131005
  double SrN23=0, SrN25=0, SrN26=0, SrN29=0;  // численн по НТН     20131005
  double SrN23_sl=0, SrN25_sl=0, SrN26_sl=0, SrN29_sl=0;   // 20180120
  double SrN23_rb=0, SrN25_rb=0, SrN26_rb=0, SrN29_rb=0;   // 20180120

  double Sr23_sl=0, Sr25_sl=0, Sr26_sl=0, Sr29_sl=0;      // численн по бал сч служащие
  double Sr23_rb=0, Sr25_rb=0, Sr26_rb=0, Sr29_rb=0;      // численн по бал сч рабочие


  int Kat, Bal;

  char Buf3[512], Buf4[512];
  char Buf31[512], Buf32[512], Buf33[512], Buf34[512];
  char Buf5[512];

  int cont = 0;

int CntStr=0;  // счётчик обработанных строк для перевода листа



Tbl6()
{
  SetupExcel();

  PreSum2();
  PreSum();
  PreSumBal();
  Head();

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

  var CTabl = CreateObject("CurPrnTbl");
  if ( !FillIdxFldTbl(CTabl) )  return;
  
  int cr=CTabl.Count_Rcr(); // число рабочих записей в таблице

  int cntRcrTab  =0;         
  string OldPod  = CTabl.Text(TblFld[idxP],0);
  string NewPod;

  string OlPodN  = CTabl.TextS("PodrN",0);
  string NwPodN;
  string NwPodU;
  int kpO, zvO, prO;

//______________ по записям таблицы _________________
  for (int zap=0; zap<cr; zap++)
   {
     NewPod  = CTabl.Text(TblFld[idxP],zap);
     NwPodN  = CTabl.TextS("PodrN",zap);
     cont = 0;

     kp = 0;
     zv = 0;
     pr = 0;
     NwPodU  = atoi(CTabl.TextS("Podr_U",zap));
     if ( NwPodU == 100) kp = 1;
     if ( NwPodU == 500) zv = 1;
     if ( NwPodU == 800) pr = 1;


     if ( NwPodN != OlPodN )  {         // если новый НТН    
       PrnStr(atoi(OldPod),kpO,zvO,prO);
       OldPod=NewPod;
                        
       if ( atoi(OlPodN) < 100 )   PrnStr2(atoi(OlPodN));   // если подразд не в НТН то итоги не нужны

       OlPodN=NwPodN;
      }

     else   {
       if ( NewPod != OldPod )  {
           PrnStr(atoi(OldPod),kpO,zvO,prO);
           OldPod=NewPod;
         }
      }


     Kat = atof(CTabl.Text(TblFld[idxK],zap));
     Bal = atoi(CTabl.TextS("Bal",zap));         // 20131005


     if (Bal == 23)                              // 20131005
      {
       Sum23[1] += atof(CTabl.Text(TblFld[idxS01],zap));
       Sum23[2] += atof(CTabl.Text(TblFld[idxS02],zap));
       Sum23[3] += atof(CTabl.Text(TblFld[idxS03],zap));
       Sum23[4] += atof(CTabl.Text(TblFld[idxS04],zap));
       Sum23[5] += atof(CTabl.Text(TblFld[idxS05],zap));
       Sum23[6] += atof(CTabl.Text(TblFld[idxS06],zap));
       Sum23[7] += atof(CTabl.Text(TblFld[idxS07],zap));
       Sum23[8] += atof(CTabl.Text(TblFld[idxS08],zap));
       Sum23[9] += atof(CTabl.Text(TblFld[idxS09],zap));
       Sum23[10] += atof(CTabl.Text(TblFld[idxS10],zap));      // 20200429
//       Sum23[11] += atof(CTabl.Text(TblFld[idxS11],zap));
//       Sum23[12] += atof(CTabl.Text(TblFld[idxS12],zap));
//       Sum23[13] += atof(CTabl.Text(TblFld[idxS13],zap));
//       Sum23[14] += atof(CTabl.Text(TblFld[idxS14],zap));

       Sr23    += atof(CTabl.Text(TblFld[idxS],zap));
       SrIt23  += atof(CTabl.Text(TblFld[idxS],zap));

       if (( Kat == 1) || ( Kat == 2) || ( Kat == 3))  //_______ если служащий то заполняем массив Sum23_sl[] 
         {
          Sum23_sl[1] += atof(CTabl.Text(TblFld[idxS01],zap));
          Sum23_sl[2] += atof(CTabl.Text(TblFld[idxS02],zap));
          Sum23_sl[3] += atof(CTabl.Text(TblFld[idxS03],zap));
          Sum23_sl[4] += atof(CTabl.Text(TblFld[idxS04],zap));
          Sum23_sl[5] += atof(CTabl.Text(TblFld[idxS05],zap));
          Sum23_sl[6] += atof(CTabl.Text(TblFld[idxS06],zap));
          Sum23_sl[7] += atof(CTabl.Text(TblFld[idxS07],zap));
          Sum23_sl[8] += atof(CTabl.Text(TblFld[idxS08],zap));
          Sum23_sl[9] += atof(CTabl.Text(TblFld[idxS09],zap));
          Sum23_sl[10] += atof(CTabl.Text(TblFld[idxS10],zap));     // 20200429
//          Sum23_sl[11] += atof(CTabl.Text(TblFld[idxS11],zap));
//          Sum23_sl[12] += atof(CTabl.Text(TblFld[idxS12],zap));
//          Sum23_sl[13] += atof(CTabl.Text(TblFld[idxS13],zap));
//          Sum23_sl[14] += atof(CTabl.Text(TblFld[idxS14],zap));

                            Sr23_sl  += atof(CTabl.Text(TblFld[idxS],zap));
          if ( kp == 1 )  SrKP23_sl  += atof(CTabl.Text(TblFld[idxS],zap));
          if ( zv == 1 )  SrZV23_sl  += atof(CTabl.Text(TblFld[idxS],zap));
          if ( pr == 1 )  SrPR23_sl  += atof(CTabl.Text(TblFld[idxS],zap));
         }
       if (( Kat == 4) || ( Kat == 5))                 //_______ если рабочий то заполняем массив Sum23_rb[] 
         {
          Sum23_rb[1] += atof(CTabl.Text(TblFld[idxS01],zap));
          Sum23_rb[2] += atof(CTabl.Text(TblFld[idxS02],zap));
          Sum23_rb[3] += atof(CTabl.Text(TblFld[idxS03],zap));
          Sum23_rb[4] += atof(CTabl.Text(TblFld[idxS04],zap));
          Sum23_rb[5] += atof(CTabl.Text(TblFld[idxS05],zap));
          Sum23_rb[6] += atof(CTabl.Text(TblFld[idxS06],zap));
          Sum23_rb[7] += atof(CTabl.Text(TblFld[idxS07],zap));
          Sum23_rb[8] += atof(CTabl.Text(TblFld[idxS08],zap));
          Sum23_rb[9] += atof(CTabl.Text(TblFld[idxS09],zap));
          Sum23_rb[10] += atof(CTabl.Text(TblFld[idxS10],zap));       // 20200429
//          Sum23_rb[11] += atof(CTabl.Text(TblFld[idxS11],zap));
//          Sum23_rb[12] += atof(CTabl.Text(TblFld[idxS12],zap));
//          Sum23_rb[13] += atof(CTabl.Text(TblFld[idxS13],zap));
//          Sum23_rb[14] += atof(CTabl.Text(TblFld[idxS14],zap));

                            Sr23_rb  += atof(CTabl.Text(TblFld[idxS],zap));
          if ( kp == 1 )  SrKP23_rb  += atof(CTabl.Text(TblFld[idxS],zap));
          if ( zv == 1 )  SrZV23_rb  += atof(CTabl.Text(TblFld[idxS],zap));
          if ( pr == 1 )  SrPR23_rb  += atof(CTabl.Text(TblFld[idxS],zap));
         }      
      }


     if (Bal == 25)                              // 20131007
      {
       Sum25[1] += atof(CTabl.Text(TblFld[idxS01],zap));
       Sum25[2] += atof(CTabl.Text(TblFld[idxS02],zap));
       Sum25[3] += atof(CTabl.Text(TblFld[idxS03],zap));
       Sum25[4] += atof(CTabl.Text(TblFld[idxS04],zap));
       Sum25[5] += atof(CTabl.Text(TblFld[idxS05],zap));
       Sum25[6] += atof(CTabl.Text(TblFld[idxS06],zap));
       Sum25[7] += atof(CTabl.Text(TblFld[idxS07],zap));
       Sum25[8] += atof(CTabl.Text(TblFld[idxS08],zap));
       Sum25[9] += atof(CTabl.Text(TblFld[idxS09],zap));
       Sum25[10] += atof(CTabl.Text(TblFld[idxS10],zap));       // 20200429
//       Sum25[11] += atof(CTabl.Text(TblFld[idxS11],zap));
//       Sum25[12] += atof(CTabl.Text(TblFld[idxS12],zap));
//       Sum25[13] += atof(CTabl.Text(TblFld[idxS13],zap));
//       Sum25[14] += atof(CTabl.Text(TblFld[idxS14],zap));

       Sr25    += atof(CTabl.Text(TblFld[idxS],zap));
       SrIt25  += atof(CTabl.Text(TblFld[idxS],zap));

       if (( Kat == 1) || ( Kat == 2) || ( Kat == 3))  //_______ если служащий то заполняем массив Sum23_sl[] 
         {
          Sum25_sl[1] += atof(CTabl.Text(TblFld[idxS01],zap));
          Sum25_sl[2] += atof(CTabl.Text(TblFld[idxS02],zap));
          Sum25_sl[3] += atof(CTabl.Text(TblFld[idxS03],zap));
          Sum25_sl[4] += atof(CTabl.Text(TblFld[idxS04],zap));
          Sum25_sl[5] += atof(CTabl.Text(TblFld[idxS05],zap));
          Sum25_sl[6] += atof(CTabl.Text(TblFld[idxS06],zap));
          Sum25_sl[7] += atof(CTabl.Text(TblFld[idxS07],zap));
          Sum25_sl[8] += atof(CTabl.Text(TblFld[idxS08],zap));
          Sum25_sl[9] += atof(CTabl.Text(TblFld[idxS09],zap));
          Sum25_sl[10] += atof(CTabl.Text(TblFld[idxS10],zap));       // 20200429
//          Sum25_sl[11] += atof(CTabl.Text(TblFld[idxS11],zap));
//          Sum25_sl[12] += atof(CTabl.Text(TblFld[idxS12],zap));
//          Sum25_sl[13] += atof(CTabl.Text(TblFld[idxS13],zap));
//          Sum25_sl[14] += atof(CTabl.Text(TblFld[idxS14],zap));

                            Sr25_sl  += atof(CTabl.Text(TblFld[idxS],zap));
          if ( kp == 1 )  SrKP25_sl  += atof(CTabl.Text(TblFld[idxS],zap));
          if ( zv == 1 )  SrZV25_sl  += atof(CTabl.Text(TblFld[idxS],zap));
          if ( pr == 1 )  SrPR25_sl  += atof(CTabl.Text(TblFld[idxS],zap));
         }
       if (( Kat == 4) || ( Kat == 5))                 //_______ если рабочий то заполняем массив Sum23_rb[] 
         {
          Sum25_rb[1] += atof(CTabl.Text(TblFld[idxS01],zap));
          Sum25_rb[2] += atof(CTabl.Text(TblFld[idxS02],zap));
          Sum25_rb[3] += atof(CTabl.Text(TblFld[idxS03],zap));
          Sum25_rb[4] += atof(CTabl.Text(TblFld[idxS04],zap));
          Sum25_rb[5] += atof(CTabl.Text(TblFld[idxS05],zap));
          Sum25_rb[6] += atof(CTabl.Text(TblFld[idxS06],zap));
          Sum25_rb[7] += atof(CTabl.Text(TblFld[idxS07],zap));
          Sum25_rb[8] += atof(CTabl.Text(TblFld[idxS08],zap));
          Sum25_rb[9] += atof(CTabl.Text(TblFld[idxS09],zap));
          Sum25_rb[10] += atof(CTabl.Text(TblFld[idxS10],zap));      // 20200429
//          Sum25_rb[11] += atof(CTabl.Text(TblFld[idxS11],zap));
//          Sum25_rb[12] += atof(CTabl.Text(TblFld[idxS12],zap));
//          Sum25_rb[13] += atof(CTabl.Text(TblFld[idxS13],zap));
//          Sum25_rb[14] += atof(CTabl.Text(TblFld[idxS14],zap));

                            Sr25_rb  += atof(CTabl.Text(TblFld[idxS],zap));
          if ( kp == 1 )  SrKP25_rb  += atof(CTabl.Text(TblFld[idxS],zap));
          if ( zv == 1 )  SrZV25_rb  += atof(CTabl.Text(TblFld[idxS],zap));
          if ( pr == 1 )  SrPR25_rb  += atof(CTabl.Text(TblFld[idxS],zap));
         }
      }


     if (Bal == 26)                              // 20131007
      {
       Sum26[1] += atof(CTabl.Text(TblFld[idxS01],zap));
       Sum26[2] += atof(CTabl.Text(TblFld[idxS02],zap));
       Sum26[3] += atof(CTabl.Text(TblFld[idxS03],zap));
       Sum26[4] += atof(CTabl.Text(TblFld[idxS04],zap));
       Sum26[5] += atof(CTabl.Text(TblFld[idxS05],zap));
       Sum26[6] += atof(CTabl.Text(TblFld[idxS06],zap));
       Sum26[7] += atof(CTabl.Text(TblFld[idxS07],zap));
       Sum26[8] += atof(CTabl.Text(TblFld[idxS08],zap));
       Sum26[9] += atof(CTabl.Text(TblFld[idxS09],zap));
       Sum26[10] += atof(CTabl.Text(TblFld[idxS10],zap));        // 20200429
//       Sum26[11] += atof(CTabl.Text(TblFld[idxS11],zap));
//       Sum26[12] += atof(CTabl.Text(TblFld[idxS12],zap));
//       Sum26[13] += atof(CTabl.Text(TblFld[idxS13],zap));
//       Sum26[14] += atof(CTabl.Text(TblFld[idxS14],zap));

          Sr26 += atof(CTabl.Text(TblFld[idxS],zap));
       SrIt26  += atof(CTabl.Text(TblFld[idxS],zap));

       if (( Kat == 1) || ( Kat == 2) || ( Kat == 3))  //_______ если служащий то заполняем массив Sum26_sl[] 
         {
          Sum26_sl[1] += atof(CTabl.Text(TblFld[idxS01],zap));
          Sum26_sl[2] += atof(CTabl.Text(TblFld[idxS02],zap));
          Sum26_sl[3] += atof(CTabl.Text(TblFld[idxS03],zap));
          Sum26_sl[4] += atof(CTabl.Text(TblFld[idxS04],zap));
          Sum26_sl[5] += atof(CTabl.Text(TblFld[idxS05],zap));
          Sum26_sl[6] += atof(CTabl.Text(TblFld[idxS06],zap));
          Sum26_sl[7] += atof(CTabl.Text(TblFld[idxS07],zap));
          Sum26_sl[8] += atof(CTabl.Text(TblFld[idxS08],zap));
          Sum26_sl[9] += atof(CTabl.Text(TblFld[idxS09],zap));
          Sum26_sl[10] += atof(CTabl.Text(TblFld[idxS10],zap));      // 20200429
//          Sum26_sl[11] += atof(CTabl.Text(TblFld[idxS11],zap));
//          Sum26_sl[12] += atof(CTabl.Text(TblFld[idxS12],zap));
//          Sum26_sl[13] += atof(CTabl.Text(TblFld[idxS13],zap));
//          Sum26_sl[14] += atof(CTabl.Text(TblFld[idxS14],zap));

                            Sr26_sl  += atof(CTabl.Text(TblFld[idxS],zap));
          if ( kp == 1 )  SrKP26_sl  += atof(CTabl.Text(TblFld[idxS],zap));
          if ( zv == 1 )  SrZV26_sl  += atof(CTabl.Text(TblFld[idxS],zap));
          if ( pr == 1 )  SrPR26_sl  += atof(CTabl.Text(TblFld[idxS],zap));
         }
       if (( Kat == 4) || ( Kat == 5))                 //_______ если рабочий то заполняем массив Sum26_rb[] 
         {
          Sum26_rb[1] += atof(CTabl.Text(TblFld[idxS01],zap));
          Sum26_rb[2] += atof(CTabl.Text(TblFld[idxS02],zap));
          Sum26_rb[3] += atof(CTabl.Text(TblFld[idxS03],zap));
          Sum26_rb[4] += atof(CTabl.Text(TblFld[idxS04],zap));
          Sum26_rb[5] += atof(CTabl.Text(TblFld[idxS05],zap));
          Sum26_rb[6] += atof(CTabl.Text(TblFld[idxS06],zap));
          Sum26_rb[7] += atof(CTabl.Text(TblFld[idxS07],zap));
          Sum26_rb[8] += atof(CTabl.Text(TblFld[idxS08],zap));
          Sum26_rb[9] += atof(CTabl.Text(TblFld[idxS09],zap));
          Sum26_rb[10] += atof(CTabl.Text(TblFld[idxS10],zap));       // 20200429
//          Sum26_rb[11] += atof(CTabl.Text(TblFld[idxS11],zap));
//          Sum26_rb[12] += atof(CTabl.Text(TblFld[idxS12],zap));
//          Sum26_rb[13] += atof(CTabl.Text(TblFld[idxS13],zap));
//          Sum26_rb[14] += atof(CTabl.Text(TblFld[idxS14],zap));

                            Sr26_rb  += atof(CTabl.Text(TblFld[idxS],zap));
          if ( kp == 1 )  SrKP26_rb  += atof(CTabl.Text(TblFld[idxS],zap));
          if ( zv == 1 )  SrZV26_rb  += atof(CTabl.Text(TblFld[idxS],zap));
          if ( pr == 1 )  SrPR26_rb  += atof(CTabl.Text(TblFld[idxS],zap));
         }
      }


     if (Bal == 29)                              // 20131007
      {
       Sum29[1] += atof(CTabl.Text(TblFld[idxS01],zap));
       Sum29[2] += atof(CTabl.Text(TblFld[idxS02],zap));
       Sum29[3] += atof(CTabl.Text(TblFld[idxS03],zap));
       Sum29[4] += atof(CTabl.Text(TblFld[idxS04],zap));
       Sum29[5] += atof(CTabl.Text(TblFld[idxS05],zap));
       Sum29[6] += atof(CTabl.Text(TblFld[idxS06],zap));
       Sum29[7] += atof(CTabl.Text(TblFld[idxS07],zap));
       Sum29[8] += atof(CTabl.Text(TblFld[idxS08],zap));
       Sum29[9] += atof(CTabl.Text(TblFld[idxS09],zap));
       Sum29[10] += atof(CTabl.Text(TblFld[idxS10],zap));        // 20200429
//       Sum29[11] += atof(CTabl.Text(TblFld[idxS11],zap));
//       Sum29[12] += atof(CTabl.Text(TblFld[idxS12],zap));
//       Sum29[13] += atof(CTabl.Text(TblFld[idxS13],zap));
//       Sum29[14] += atof(CTabl.Text(TblFld[idxS14],zap));

       Sr29    += atof(CTabl.Text(TblFld[idxS],zap));
       SrIt29  += atof(CTabl.Text(TblFld[idxS],zap));

       if (( Kat == 1) || ( Kat == 2) || ( Kat == 3))  //_______ если служащий то заполняем массив Sum29_sl[] 
         {
          Sum29_sl[1] += atof(CTabl.Text(TblFld[idxS01],zap));
          Sum29_sl[2] += atof(CTabl.Text(TblFld[idxS02],zap));
          Sum29_sl[3] += atof(CTabl.Text(TblFld[idxS03],zap));
          Sum29_sl[4] += atof(CTabl.Text(TblFld[idxS04],zap));
          Sum29_sl[5] += atof(CTabl.Text(TblFld[idxS05],zap));
          Sum29_sl[6] += atof(CTabl.Text(TblFld[idxS06],zap));
          Sum29_sl[7] += atof(CTabl.Text(TblFld[idxS07],zap));
          Sum29_sl[8] += atof(CTabl.Text(TblFld[idxS08],zap));
          Sum29_sl[9] += atof(CTabl.Text(TblFld[idxS09],zap));
          Sum29_sl[10] += atof(CTabl.Text(TblFld[idxS10],zap));       // 20200429
//          Sum29_sl[11] += atof(CTabl.Text(TblFld[idxS11],zap));
//          Sum29_sl[12] += atof(CTabl.Text(TblFld[idxS12],zap));
//          Sum29_sl[13] += atof(CTabl.Text(TblFld[idxS13],zap));
//          Sum29_sl[14] += atof(CTabl.Text(TblFld[idxS14],zap));

                            Sr29_sl  += atof(CTabl.Text(TblFld[idxS],zap));
          if ( kp == 1 )  SrKP29_sl  += atof(CTabl.Text(TblFld[idxS],zap));
          if ( zv == 1 )  SrZV29_sl  += atof(CTabl.Text(TblFld[idxS],zap));
          if ( pr == 1 )  SrPR29_sl  += atof(CTabl.Text(TblFld[idxS],zap));
         }
       if (( Kat == 4) || ( Kat == 5))                 //_______ если рабочий то заполняем массив Sum29_rb[] 
         {
          Sum29_rb[1] += atof(CTabl.Text(TblFld[idxS01],zap));
          Sum29_rb[2] += atof(CTabl.Text(TblFld[idxS02],zap));
          Sum29_rb[3] += atof(CTabl.Text(TblFld[idxS03],zap));
          Sum29_rb[4] += atof(CTabl.Text(TblFld[idxS04],zap));
          Sum29_rb[5] += atof(CTabl.Text(TblFld[idxS05],zap));
          Sum29_rb[6] += atof(CTabl.Text(TblFld[idxS06],zap));
          Sum29_rb[7] += atof(CTabl.Text(TblFld[idxS07],zap));
          Sum29_rb[8] += atof(CTabl.Text(TblFld[idxS08],zap));
          Sum29_rb[9] += atof(CTabl.Text(TblFld[idxS09],zap));
          Sum29_rb[10] += atof(CTabl.Text(TblFld[idxS10],zap));        // 20200429
//          Sum29_rb[11] += atof(CTabl.Text(TblFld[idxS11],zap));
//          Sum29_rb[12] += atof(CTabl.Text(TblFld[idxS12],zap));
//          Sum29_rb[13] += atof(CTabl.Text(TblFld[idxS13],zap));
//          Sum29_rb[14] += atof(CTabl.Text(TblFld[idxS14],zap));

                            Sr29_rb  += atof(CTabl.Text(TblFld[idxS],zap));
          if ( kp == 1 )  SrKP29_rb  += atof(CTabl.Text(TblFld[idxS],zap));
          if ( zv == 1 )  SrZV29_rb  += atof(CTabl.Text(TblFld[idxS],zap));
          if ( pr == 1 )  SrPR29_rb  += atof(CTabl.Text(TblFld[idxS],zap));
         }
      }


     // для общих сумм по  KP,  ZV,  PR

     if (( Kat == 1) || ( Kat == 2) || ( Kat == 3))     
      {
       SumS[1] += atof(CTabl.Text(TblFld[idxS01],zap));
       SumS[2] += atof(CTabl.Text(TblFld[idxS02],zap));
       SumS[3] += atof(CTabl.Text(TblFld[idxS03],zap));
       SumS[4] += atof(CTabl.Text(TblFld[idxS04],zap));
       SumS[5] += atof(CTabl.Text(TblFld[idxS05],zap));
       SumS[6] += atof(CTabl.Text(TblFld[idxS06],zap));
       SumS[7] += atof(CTabl.Text(TblFld[idxS07],zap));
       SumS[8] += atof(CTabl.Text(TblFld[idxS08],zap));
       SumS[9] += atof(CTabl.Text(TblFld[idxS09],zap));
       SumS[10] += atof(CTabl.Text(TblFld[idxS10],zap));         // 20200429
//       SumS[11] += atof(CTabl.Text(TblFld[idxS11],zap));
//       SumS[12] += atof(CTabl.Text(TblFld[idxS12],zap));
//       SumS[13] += atof(CTabl.Text(TblFld[idxS13],zap));
//       SumS[14] += atof(CTabl.Text(TblFld[idxS14],zap));

                          SrS  += atof(CTabl.Text(TblFld[idxS],zap));      
       if ( kp == 1 )  SrKPsl  += atof(CTabl.Text(TblFld[idxS],zap));
       if ( zv == 1 )  SrZVsl  += atof(CTabl.Text(TblFld[idxS],zap));
       if ( pr == 1 )  SrPRsl  += atof(CTabl.Text(TblFld[idxS],zap));
      }
     
     if (( Kat == 4) || ( Kat == 5))
      {
       SumR[1] += atof(CTabl.Text(TblFld[idxS01],zap));
       SumR[2] += atof(CTabl.Text(TblFld[idxS02],zap));
       SumR[3] += atof(CTabl.Text(TblFld[idxS03],zap));
       SumR[4] += atof(CTabl.Text(TblFld[idxS04],zap));
       SumR[5] += atof(CTabl.Text(TblFld[idxS05],zap));
       SumR[6] += atof(CTabl.Text(TblFld[idxS06],zap));
       SumR[7] += atof(CTabl.Text(TblFld[idxS07],zap));
       SumR[8] += atof(CTabl.Text(TblFld[idxS08],zap));
       SumR[9] += atof(CTabl.Text(TblFld[idxS09],zap));
       SumR[10] += atof(CTabl.Text(TblFld[idxS10],zap));         // 20200429
//       SumR[11] += atof(CTabl.Text(TblFld[idxS11],zap));
//       SumR[12] += atof(CTabl.Text(TblFld[idxS12],zap));
//       SumR[13] += atof(CTabl.Text(TblFld[idxS13],zap));
//       SumR[14] += atof(CTabl.Text(TblFld[idxS14],zap));

                          SrR  += atof(CTabl.Text(TblFld[idxS],zap));
       if ( kp == 1 )  SrKPrb  += atof(CTabl.Text(TblFld[idxS],zap));
       if ( zv == 1 )  SrZVrb  += atof(CTabl.Text(TblFld[idxS],zap));
       if ( pr == 1 )  SrPRrb  += atof(CTabl.Text(TblFld[idxS],zap));
      }

                     SrIT  += atof(CTabl.Text(TblFld[idxS],zap));
     if ( kp == 1 )  SrKP  += atof(CTabl.Text(TblFld[idxS],zap));
     if ( zv == 1 )  SrZV  += atof(CTabl.Text(TblFld[idxS],zap));
     if ( pr == 1 )  SrPR  += atof(CTabl.Text(TblFld[idxS],zap));

     kpO = kp;
     zvO = zv;
     prO = pr;
   }
  PrnStr(atoi(OldPod),kpO,zvO,prO);
  PrnStrIt();


  xls.Visible=true;         // делаем Excel видимым

}


Head()
{

  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);  //Trim(str);
  FreeSpaceString(str,3,"");
  string sMes = static_cast_to_string(str);  

  sprintf(str,"%s %d г.",sMes,iGod); FreeSpaceString(str,3,"");

  char s[256];
  return 0;
}



PreSum2()
{
 for ( int ii=1; ii<=14; ii++ )  {
   SmSN[ii] = 0;
   SmRN[ii] = 0;
   SmVN[ii] = 0;

   Sm23N[ii] = 0;
   Sm25N[ii] = 0;
   Sm26N[ii] = 0;
   Sm29N[ii] = 0;
   Sm23N_sl[ii] = 0;
   Sm25N_sl[ii] = 0;
   Sm26N_sl[ii] = 0;
   Sm29N_sl[ii] = 0;
   Sm23N_rb[ii] = 0;
   Sm25N_rb[ii] = 0;
   Sm26N_rb[ii] = 0;
   Sm29N_rb[ii] = 0;

 }
 sN =  rN =  vN = 0;
 sm23N =  sm25N =  sm26N =  sm29N = 0; 
 sm23N_sl =  sm25N_sl =  sm26N_sl =  sm29N_sl = 0; 
 sm23N_rb =  sm25N_rb =  sm26N_rb =  sm29N_rb = 0; 
}



PreSum()
{
 for ( int ii=1; ii<=14; ii++ )  {
   SumS[ii] = 0;
   SumR[ii] = 0;
   SumV[ii] = 0;

   Sum23[ii] = 0;
   Sum25[ii] = 0;
   Sum26[ii] = 0;
   Sum29[ii] = 0;
  }
}
PreSumBal()
{
 Sr23_sl = Sr23_rb = 0;
 Sr25_sl = Sr25_rb = 0;
 Sr26_sl = Sr26_rb = 0;
 Sr29_sl = Sr29_rb = 0;
 sm23_sl = sm23_rb = 0;
 sm25_sl = sm25_rb = 0;
 sm26_sl = sm26_rb = 0;
 sm29_sl = sm29_rb = 0;

 for ( int ii=1; ii<=14; ii++ )
  {
   Sum23_sl[ii] = Sum23_rb[ii] = 0;
   Sum25_sl[ii] = Sum25_rb[ii] = 0;
   Sum26_sl[ii] = Sum26_rb[ii] = 0;
   Sum29_sl[ii] = Sum29_rb[ii] = 0;
  }
}



PrnStrIt()
 {
    SrSmKP = sItKP / SrKP;
    double SrSmKPsl = sItKPsl / SrKPsl;
    double SrSmKPrb = sItKPrb / SrKPrb;
    sprintf(ex1," КП ");

    double SrSmKP23 = 0;
    sprintf(ex2,"_23_");
    SrSmKP23 = sItKP23_sl / SrKP23_sl;
    sprintf(ex3,"СЛУЖАЩИЕ");
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrKP23_sl,sItKP23_sl,SumKP23_sl[1],SumKP23_sl[2],SumKP23_sl[3],SumKP23_sl[4],SumKP23_sl[5],SumKP23_sl[6],SumKP23_sl[7],SumKP23_sl[8],SumKP23_sl[9],SrSmKP23);
    SrSmKP23 = sItKP23_rb / SrKP23_rb;
    sprintf(ex3,"РАБОЧИЕ");
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrKP23_rb,sItKP23_rb,SumKP23_rb[1],SumKP23_rb[2],SumKP23_rb[3],SumKP23_rb[4],SumKP23_rb[5],SumKP23_rb[6],SumKP23_rb[7],SumKP23_rb[8],SumKP23_rb[9],SrSmKP23);
    sprintf(ex3,"________");
    SrKP23 = SrKP23_sl + SrKP23_rb;
    SrSmKP23 = sItKP23 / SrKP23;
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrKP23,sItKP23,SumKP23[1],SumKP23[2],SumKP23[3],SumKP23[4],SumKP23[5],SumKP23[6],SumKP23[7],SumKP23[8],SumKP23[9],SrSmKP23);

    double SrSmKP25 = 0;
    sprintf(ex2,"_25_");
    SrSmKP25 = sItKP25_sl / SrKP25_sl;
    sprintf(ex3,"СЛУЖАЩИЕ");
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrKP25_sl,sItKP25_sl,SumKP25_sl[1],SumKP25_sl[2],SumKP25_sl[3],SumKP25_sl[4],SumKP25_sl[5],SumKP25_sl[6],SumKP25_sl[7],SumKP25_sl[8],SumKP25_sl[9],SrSmKP25);
    SrSmKP25 = sItKP25_rb / SrKP25_rb;
    sprintf(ex3,"РАБОЧИЕ");
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrKP25_rb,sItKP25_rb,SumKP25_rb[1],SumKP25_rb[2],SumKP25_rb[3],SumKP25_rb[4],SumKP25_rb[5],SumKP25_rb[6],SumKP25_rb[7],SumKP25_rb[8],SumKP25_rb[9],SrSmKP25);
    sprintf(ex3,"________");
    SrKP25 = SrKP25_sl + SrKP25_rb;
    SrSmKP25 = sItKP25 / SrKP25;    
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrKP25,sItKP25,SumKP25[1],SumKP25[2],SumKP25[3],SumKP25[4],SumKP25[5],SumKP25[6],SumKP25[7],SumKP25[8],SumKP25[9],SrSmKP25);

    double SrSmKP26 = 0;
    sprintf(ex2,"_26_");
    SrSmKP26 = sItKP26_sl / SrKP26_sl;
    sprintf(ex3,"СЛУЖАЩИЕ");
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrKP26_sl,sItKP26_sl,SumKP26_sl[1],SumKP26_sl[2],SumKP26_sl[3],SumKP26_sl[4],SumKP26_sl[5],SumKP26_sl[6],SumKP26_sl[7],SumKP26_sl[8],SumKP26_sl[9],SrSmKP26);
    SrSmKP26 = sItKP26_rb / SrKP26_rb;
    sprintf(ex3,"РАБОЧИЕ");
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrKP26_rb,sItKP26_rb,SumKP26_rb[1],SumKP26_rb[2],SumKP26_rb[3],SumKP26_rb[4],SumKP26_rb[5],SumKP26_rb[6],SumKP26_rb[7],SumKP26_rb[8],SumKP26_rb[9],SrSmKP26);
    SrKP26 = SrKP26_sl + SrKP26_rb;
    SrSmKP26 = sItKP26 / SrKP26;
    sprintf(ex3,"________");
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrKP26,sItKP26,SumKP26[1],SumKP26[2],SumKP26[3],SumKP26[4],SumKP26[5],SumKP26[6],SumKP26[7],SumKP26[8],SumKP26[9],SrSmKP26);

    double SrSmKP29 = 0;
    sprintf(ex2,"_29_");
    SrSmKP29 = sItKP29_sl / SrKP29_sl;
    sprintf(ex3,"СЛУЖАЩИЕ");
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrKP29_sl,sItKP29_sl,SumKP29_sl[1],SumKP29_sl[2],SumKP29_sl[3],SumKP29_sl[4],SumKP29_sl[5],SumKP29_sl[6],SumKP29_sl[7],SumKP29_sl[8],SumKP29_sl[9],SrSmKP29);
    SrSmKP29 = sItKP29_rb / SrKP29_rb;
    sprintf(ex3,"РАБОЧИЕ");
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrKP29_rb,sItKP29_rb,SumKP29_rb[1],SumKP29_rb[2],SumKP29_rb[3],SumKP29_rb[4],SumKP29_rb[5],SumKP29_rb[6],SumKP29_rb[7],SumKP29_rb[8],SumKP29_rb[9],SrSmKP29);
    SrKP29 = SrKP29_sl + SrKP29_rb;
    SrSmKP29 = sItKP29 / SrKP29;
    sprintf(ex3,"________");
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrKP29,sItKP29,SumKP29[1],SumKP29[2],SumKP29[3],SumKP29[4],SumKP29[5],SumKP29[6],SumKP29[7],SumKP29[8],SumKP29[9],SrSmKP29);

    sprintf(ex2,"всего");  
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrKP,sItKP,SumKP[1],SumKP[2],SumKP[3],SumKP[4],SumKP[5],SumKP[6],SumKP[7],SumKP[8],SumKP[9],SrSmKP);

//---------------------------------------------

    SrSmZV = sItZV / SrZV;
    double SrSmZVsl = sItZVsl / SrZVsl;
    double SrSmZVrb = sItZVrb / SrZVrb;
    sprintf(ex1,"Завод");

    double SrSmZV23 = 0;
    sprintf(ex2,"_23_");
    SrSmZV23 = sItZV23_sl / SrZV23_sl;
    sprintf(ex3,"СЛУЖАЩИЕ");
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrZV23_sl,sItZV23_sl,SumZV23_sl[1],SumZV23_sl[2],SumZV23_sl[3],SumZV23_sl[4],SumZV23_sl[5],SumZV23_sl[6],SumZV23_sl[7],SumZV23_sl[8],SumZV23_sl[9],SrSmZV23);
    SrSmZV23 = sItZV23_rb / SrZV23_rb;
    sprintf(ex3,"РАБОЧИЕ");
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrZV23_rb,sItZV23_rb,SumZV23_rb[1],SumZV23_rb[2],SumZV23_rb[3],SumZV23_rb[4],SumZV23_rb[5],SumZV23_rb[6],SumZV23_rb[7],SumZV23_rb[8],SumZV23_rb[9],SrSmZV23);
    SrSmZV23 = 0;
    SrZV23 = SrZV23_sl + SrZV23_rb;
    SrSmZV23 = sItZV23 / SrZV23;
    sprintf(ex3,"________");
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrZV23,sItZV23,SumZV23[1],SumZV23[2],SumZV23[3],SumZV23[4],SumZV23[5],SumZV23[6],SumZV23[7],SumZV23[8],SumZV23[9],SrSmZV23);

    sprintf(ex2,"_25_");
    double SrSmZV25 = 0;
    SrSmZV25 = sItZV25_sl / SrZV25_sl;
    sprintf(ex3,"СЛУЖАЩИЕ");
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrZV25_sl,sItZV25_sl,SumZV25_sl[1],SumZV25_sl[2],SumZV25_sl[3],SumZV25_sl[4],SumZV25_sl[5],SumZV25_sl[6],SumZV25_sl[7],SumZV25_sl[8],SumZV25_sl[9],SrSmZV25);
    SrSmZV25 = sItZV25_rb / SrZV25_rb;
    sprintf(ex3,"РАБОЧИЕ");
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrZV25_rb,sItZV25_rb,SumZV25_rb[1],SumZV25_rb[2],SumZV25_rb[3],SumZV25_rb[4],SumZV25_rb[5],SumZV25_rb[6],SumZV25_rb[7],SumZV25_rb[8],SumZV25_rb[9],SrSmZV25);
    sprintf(ex3,"________");
    SrZV25 = SrZV25_sl + SrZV25_rb;
    SrSmZV25 = sItZV25 / SrZV25;
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrZV25,sItZV25,SumZV25[1],SumZV25[2],SumZV25[3],SumZV25[4],SumZV25[5],SumZV25[6],SumZV25[7],SumZV25[8],SumZV25[9],SrSmZV25);

    sprintf(ex2,"_26_");
    double SrSmZV26 = 0;
    SrSmZV26 = sItZV26_sl / SrZV26_sl;
    sprintf(ex3,"СЛУЖАЩИЕ");
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrZV26_sl,sItZV26_sl,SumZV26_sl[1],SumZV26_sl[2],SumZV26_sl[3],SumZV26_sl[4],SumZV26_sl[5],SumZV26_sl[6],SumZV26_sl[7],SumZV26_sl[8],SumZV26_sl[9],SrSmZV26);
    SrSmZV26 = sItZV26_rb / SrZV26_rb;
    sprintf(ex3,"РАБОЧИЕ");
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrZV26_rb,sItZV26_rb,SumZV26_rb[1],SumZV26_rb[2],SumZV26_rb[3],SumZV26_rb[4],SumZV26_rb[5],SumZV26_rb[6],SumZV26_rb[7],SumZV26_rb[8],SumZV26_rb[9],SrSmZV26);
    sprintf(ex3,"________");
    SrZV26 = SrZV26_sl + SrZV26_rb;
    SrSmZV26 = sItZV26 / SrZV26;
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrZV26,sItZV26,SumZV26[1],SumZV26[2],SumZV26[3],SumZV26[4],SumZV26[5],SumZV26[6],SumZV26[7],SumZV26[8],SumZV26[9],SrSmZV26);

    sprintf(ex2,"_29_");
    double SrSmZV29 = 0;
    SrSmZV26 = sItZV29_sl / SrZV29_sl;
    sprintf(ex3,"СЛУЖАЩИЕ");
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrZV29_sl,sItZV29_sl,SumZV29_sl[1],SumZV29_sl[2],SumZV29_sl[3],SumZV29_sl[4],SumZV29_sl[5],SumZV29_sl[6],SumZV29_sl[7],SumZV29_sl[8],SumZV29_sl[9],SrSmZV29);
    SrSmZV29 = sItZV29_rb / SrZV29_rb;
    sprintf(ex3,"РАБОЧИЕ");
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrZV29_rb,sItZV29_rb,SumZV29_rb[1],SumZV29_rb[2],SumZV29_rb[3],SumZV29_rb[4],SumZV29_rb[5],SumZV29_rb[6],SumZV29_rb[7],SumZV29_rb[8],SumZV29_rb[9],SrSmZV29);
    sprintf(ex3,"________");
    SrZV29 = SrZV29_sl + SrZV29_rb;
    SrSmZV29 = sItZV29 / SrZV29;
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrZV29,sItZV29,SumZV29[1],SumZV29[2],SumZV29[3],SumZV29[4],SumZV29[5],SumZV29[6],SumZV29[7],SumZV29[8],SumZV29[9],SrSmZV29);

    sprintf(ex2,"всего");  
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrZV,sItZV,SumZV[1],SumZV[2],SumZV[3],SumZV[4],SumZV[5],SumZV[6],SumZV[7],SumZV[8],SumZV[9],SrSmZV);

//---------------------------------------------

    SrSmPR = sItPR / SrPR;
    double SrSmPRsl = sItPRsl / SrPRsl;
    double SrSmPRrb = sItPRrb / SrPRrb;
    sprintf(ex1,"Прочие");

    sprintf(ex2,"_23_");
    double SrSmPR23 = 0;
    SrSmPR23 = sItPR23_sl / SrPR23_sl;
    sprintf(ex3,"СЛУЖАЩИЕ");
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrPR23_sl,sItPR23_sl,SumPR23_sl[1],SumPR23_sl[2],SumPR23_sl[3],SumPR23_sl[4],SumPR23_sl[5],SumPR23_sl[6],SumPR23_sl[7],SumPR23_sl[8],SumPR23_sl[9],SrSmPR23);
    SrSmPR23 = sItPR23_rb / SrPR23_rb;
    sprintf(ex3,"РАБОЧИЕ");
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrPR23_rb,sItPR23_rb,SumPR23_rb[1],SumPR23_rb[2],SumPR23_rb[3],SumPR23_rb[4],SumPR23_rb[5],SumPR23_rb[6],SumPR23_rb[7],SumPR23_rb[8],SumPR23_rb[9],SrSmPR23);
    sprintf(ex3,"________");
    SrPR23 = SrPR23_sl + SrPR23_rb;
    SrSmPR23 = sItPR23 / SrPR23;
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrPR23,sItPR23,SumPR23[1],SumPR23[2],SumPR23[3],SumPR23[4],SumPR23[5],SumPR23[6],SumPR23[7],SumPR23[8],SumPR23[9],SrSmPR23);

    sprintf(ex2,"_25_");
    double SrSmPR25 = 0;
    SrSmPR25 = sItPR25_sl / SrPR25_sl;
    sprintf(ex3,"СЛУЖАЩИЕ");
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrPR25_sl,sItPR25_sl,SumPR25_sl[1],SumPR25_sl[2],SumPR25_sl[3],SumPR25_sl[4],SumPR25_sl[5],SumPR25_sl[6],SumPR25_sl[7],SumPR25_sl[8],SumPR25_sl[9],SrSmPR25);
    SrSmPR25 = sItPR25_rb / SrPR25_rb;
    sprintf(ex3,"РАБОЧИЕ");
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrPR25_rb,sItPR25_rb,SumPR25_rb[1],SumPR25_rb[2],SumPR25_rb[3],SumPR25_rb[4],SumPR25_rb[5],SumPR25_rb[6],SumPR25_rb[7],SumPR25_rb[8],SumPR25_rb[9],SrSmPR25);
    sprintf(ex3,"________");
    SrPR25 = SrPR25_sl + SrPR25_rb;
    SrSmPR25 = sItPR25 / SrPR25;
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrPR25,sItPR25,SumPR25[1],SumPR25[2],SumPR25[3],SumPR25[4],SumPR25[5],SumPR25[6],SumPR25[7],SumPR25[8],SumPR25[9],SrSmPR25);

    sprintf(ex2,"_26_");
    double SrSmPR26 = 0;
    SrSmPR26 = sItPR26_sl / SrPR26_sl;
    sprintf(ex3,"СЛУЖАЩИЕ");
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrPR26_sl,sItPR26_sl,SumPR26_sl[1],SumPR26_sl[2],SumPR26_sl[3],SumPR26_sl[4],SumPR26_sl[5],SumPR26_sl[6],SumPR26_sl[7],SumPR26_sl[8],SumPR26_sl[9],SrSmPR26);
    SrSmPR26 = sItPR26_rb / SrPR26_rb;
    sprintf(ex3,"РАБОЧИЕ");
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrPR26_rb,sItPR26_rb,SumPR26_rb[1],SumPR26_rb[2],SumPR26_rb[3],SumPR26_rb[4],SumPR26_rb[5],SumPR26_rb[6],SumPR26_rb[7],SumPR26_rb[8],SumPR26_rb[9],SrSmPR26);
    sprintf(ex3,"________");
    SrPR26 = SrPR26_sl + SrPR26_rb;
    SrSmPR26 = sItPR26 / SrPR26;
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrPR26,sItPR26,SumPR26[1],SumPR26[2],SumPR26[3],SumPR26[4],SumPR26[5],SumPR26[6],SumPR26[7],SumPR26[8],SumPR26[9],SrSmPR26);

    sprintf(ex2,"_29_");
    double SrSmPR29 = 0;
    SrSmPR29 = sItPR29_sl / SrPR29_sl;
    sprintf(ex3,"СЛУЖАЩИЕ");
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrPR29_sl,sItPR29_sl,SumPR29_sl[1],SumPR29_sl[2],SumPR29_sl[3],SumPR29_sl[4],SumPR29_sl[5],SumPR29_sl[6],SumPR29_sl[7],SumPR29_sl[8],SumPR29_sl[9],SrSmPR29);
    SrSmPR29 = sItPR29_rb / SrPR29_rb;
    sprintf(ex3,"РАБОЧИЕ");
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrPR29_rb,sItPR29_rb,SumPR29_rb[1],SumPR29_rb[2],SumPR29_rb[3],SumPR29_rb[4],SumPR29_rb[5],SumPR29_rb[6],SumPR29_rb[7],SumPR29_rb[8],SumPR29_rb[9],SrSmPR29);
    sprintf(ex3,"________");
    SrPR29 = SrPR29_sl + SrPR29_rb;
    SrSmPR29 = sItPR29 / SrPR29;
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrPR29,sItPR29,SumPR29[1],SumPR29[2],SumPR29[3],SumPR29[4],SumPR29[5],SumPR29[6],SumPR29[7],SumPR29[8],SumPR29[9],SrSmPR29);

    sprintf(ex2,"всего");  
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrPR,sItPR,SumPR[1],SumPR[2],SumPR[3],SumPR[4],SumPR[5],SumPR[6],SumPR[7],SumPR[8],SumPR[9],SrSmPR);


    double  SrSm23 = sIt23  / SrIt23;
    sprintf(ex1,"_____");
    sprintf(ex2,"сч_23");
    WritStringEx2(ex1,ex2,ex3,SrIt23,sIt23,SumIt23[1],SumIt23[2],SumIt23[3],SumIt23[4],SumIt23[5],SumIt23[6],SumIt23[7],SumIt23[8],SumIt23[9],SrSm23);

    double  SrSm25 = sIt25  / SrIt25;
    sprintf(ex1,"_____");
    sprintf(ex2,"сч_25");
    WritStringEx2(ex1,ex2,ex3,SrIt25,sIt25,SumIt25[1],SumIt25[2],SumIt25[3],SumIt25[4],SumIt25[5],SumIt25[6],SumIt25[7],SumIt25[8],SumIt25[9],SrSm25);

    double  SrSm26 = sIt26  / SrIt26;
    sprintf(ex1,"_____");
    sprintf(ex2,"сч_26");
    WritStringEx2(ex1,ex2,ex3,SrIt26,sIt26,SumIt26[1],SumIt26[2],SumIt26[3],SumIt26[4],SumIt26[5],SumIt26[6],SumIt26[7],SumIt26[8],SumIt26[9],SrSm26);

    double  SrSm29 = sIt29  / SrIt29;
    sprintf(ex1,"_____");
    sprintf(ex2,"сч_29");
    WritStringEx2(ex1,ex2,ex3,SrIt29,sIt29,SumIt29[1],SumIt29[2],SumIt29[3],SumIt29[4],SumIt29[5],SumIt29[6],SumIt29[7],SumIt29[8],SumIt29[9],SrSm29);


    
    double SrSmIT = sIt  / SrIT;

    sprintf(ex1,"   ");
    sprintf(ex2,"ИТОГО");
    WritStringEx2(ex1,ex2,ex3,SrIT,sIt,SumIt[1],SumIt[2],SumIt[3],SumIt[4],SumIt[5],SumIt[6],SumIt[7],SumIt[8],SumIt[9],SrSmIT);

 }

        
PrnStr2(Frst)
 {
  vN = sm23N + sm25N + sm26N + sm29N;

  if (sm23N)   {
    sprintf(ex1,"НТН_: %s",static_cast_to_string(Frst));
    sprintf(ex2,"_23_");
    sprintf(ex3,"_Служ_");
    SrSmN = 0;
    if (SrN23_sl != 0)  SrSmN=sm23N_sl/SrN23_sl;                    
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrN23_sl,sm23N_sl,Sm23N_sl[1],Sm23N_sl[2],Sm23N_sl[3],Sm23N_sl[4],Sm23N_sl[5],Sm23N_sl[6],Sm23N_sl[7],Sm23N_sl[8],Sm23N_sl[9],SrSmN);

    sprintf(ex3,"_Раб-е_");
    SrSmN = 0;
    if (SrN23_rb != 0)  SrSmN=sm23N_rb/SrN23_rb;
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrN23_rb, sm23N_rb,Sm23N_rb[1],Sm23N_rb[2],Sm23N_rb[3],Sm23N_rb[4],Sm23N_rb[5],Sm23N_rb[6],Sm23N_rb[7],Sm23N_rb[8],Sm23N_rb[9],SrSmN);

    sprintf(ex3,"_______");
    SrSmN = 0;
    if (SrN23 != 0)    SrSmN=sm23N/SrN23;
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrN23,sm23N,Sm23N[1],Sm23N[2],Sm23N[3],Sm23N[4],Sm23N[5],Sm23N[6],Sm23N[7],Sm23N[8],Sm23N[9],SrSmN);
    SrSmN=0;
  }

  if (sm25N)   {
    sprintf(ex1,"НТН_: %s",static_cast_to_string(Frst));
    sprintf(ex2,"_25_");

    sprintf(ex3,"_Служ_");
    SrSmN = 0;
    if (SrN25_sl != 0)    SrSmN=sm25N_sl/SrN25_sl;
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrN25_sl,sm25N_sl,Sm25N_sl[1],Sm25N_sl[2],Sm25N_sl[3],Sm25N_sl[4],Sm25N_sl[5],Sm25N_sl[6],Sm25N_sl[7],Sm25N_sl[8],Sm25N_sl[9],SrSmN);

    sprintf(ex3,"_Раб-е_");
    SrSmN = 0;
    if (SrN25_rb != 0)    SrSmN=sm25N_rb/SrN25_rb;
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrN25_rb,sm25N_rb,Sm25N_rb[1],Sm25N_rb[2],Sm25N_rb[3],Sm25N_rb[4],Sm25N_rb[5],Sm25N_rb[6],Sm25N_rb[7],Sm25N_rb[8],Sm25N_rb[9],SrSmN);

    sprintf(ex3,"_______");
    SrSmN = 0;
    if (SrN25 != 0)    SrSmN=sm25N/SrN25;
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrN25,sm25N,Sm25N[1],Sm25N[2],Sm25N[3],Sm25N[4],Sm25N[5],Sm25N[6],Sm25N[7],Sm25N[8],Sm25N[9],SrSmN);
    SrSmN=0;
  }

  if (sm26N)   {
    sprintf(ex1,"НТН_: %s",static_cast_to_string(Frst));
    sprintf(ex2,"_26_");

    sprintf(ex3,"_Служ_");
    SrSmN = 0;
    if (SrN26_sl != 0)    SrSmN=sm26N_sl/SrN26_sl;
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrN26_sl,sm26N_sl,Sm26N_sl[1],Sm26N_sl[2],Sm26N_sl[3],Sm26N_sl[4],Sm26N_sl[5],Sm26N_sl[6],Sm26N_sl[7],Sm26N_sl[8],Sm26N_sl[9],SrSmN);

    sprintf(ex3,"_Раб-е_");
    SrSmN = 0;
    if (SrN26_rb != 0)    SrSmN=sm26N_rb/SrN26_rb;
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrN26_rb,sm26N_rb,Sm26N_rb[1],Sm26N_rb[2],Sm26N_rb[3],Sm26N_rb[4],Sm26N_rb[5],Sm26N_rb[6],Sm26N_rb[7],Sm26N_rb[8],Sm26N_rb[9],SrSmN);

    sprintf(ex3,"_______");
    SrSmN = 0;
    if (SrN26 != 0)    SrSmN=sm26N/SrN26;
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrN26,sm26N,Sm26N[1],Sm26N[2],Sm26N[3],Sm26N[4],Sm26N[5],Sm26N[6],Sm26N[7],Sm26N[8],Sm26N[9],SrSmN);
    SrSmN=0;
  }

  if (sm29N)   {
    sprintf(ex1,"НТН_: %s",static_cast_to_string(Frst));
    sprintf(ex2,"_29_");

    sprintf(ex3,"_Служ_");
    SrSmN = 0;
    if (SrN29_sl != 0)    SrSmN=sm29N_sl/SrN29_sl;
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrN29_sl,sm29N_sl,Sm29N_sl[1],Sm29N_sl[2],Sm29N_sl[3],Sm29N_sl[4],Sm29N_sl[5],Sm29N_sl[6],Sm29N_sl[7],Sm29N_sl[8],Sm29N_sl[9],SrSmN);

    sprintf(ex3,"_Раб-е_");
    SrSmN = 0;
    if (SrN29_rb != 0)    SrSmN=sm29N_rb/SrN29_rb;
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrN29_rb,sm29N_rb,Sm29N_rb[1],Sm29N_rb[2],Sm29N_rb[3],Sm29N_rb[4],Sm29N_rb[5],Sm29N_rb[6],Sm29N_rb[7],Sm29N_rb[8],Sm29N_rb[9],SrSmN);

    sprintf(ex3,"_______");
    SrSmN = 0;
    if (SrN29 != 0)    SrSmN=sm29N/SrN29;
    WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrN29,sm29N,Sm29N[1],Sm29N[2],Sm29N[3],Sm29N[4],Sm29N[5],Sm29N[6],Sm29N[7],Sm29N[8],Sm29N[9],SrSmN);
    SrSmN=0;
  }

  SrSmN=vN/SrVN;
  sprintf(ex1,"НТН_: %s",static_cast_to_string(Frst));
  sprintf(ex2,"всего");
  WritStringEx2(OemToAnsi(ex1),ex2,ex3,SrVN,vN,SmVN[1],SmVN[2],SmVN[3],SmVN[4],SmVN[5],SmVN[6],SmVN[7],SmVN[8],SmVN[9],SrSmN);
  n++;

  SrSN=0;
  SrRN=0;
  SrN23 = SrN25 = SrN26 = SrN29 = 0;
  SrN23_sl = SrN25_sl = SrN26_sl = SrN29_sl = 0;
  SrN23_rb = SrN25_rb = SrN26_rb = SrN29_rb = 0;

  CntStr++;
  CntStr++;
  CntStr++;

  PreSum2();
 }



PrnStr(Frst,ko,zo,po)
 {
  for (int i=2; i<=9; i++)               //for (int i=1; i<=14; i++)
   {
    s += SumS[i];              // сумма по служащим по строке
    r += SumR[i];              // сумма по рабочим  по строке
    sm23 += Sum23[i];          // 20131007
    sm25 += Sum25[i];          // 20131007
    sm26 += Sum26[i];          // 20131007
    sm29 += Sum29[i];          // 20131007

    sm23_sl += Sum23_sl[i];          // 20180119
    sm23_rb += Sum23_rb[i];          // 20180119
    sm25_sl += Sum25_sl[i];          // 20180119
    sm25_rb += Sum25_rb[i];          // 20180119
    sm26_sl += Sum26_sl[i];          // 20180119
    sm26_rb += Sum26_rb[i];          // 20180119
    sm29_sl += Sum29_sl[i];          // 20180119
    sm29_rb += Sum29_rb[i];          // 20180119

    sN += SumS[i];             // сумма по служащим по НТН
    rN += SumR[i];             // сумма по рабочим  по НТН


    sm23N += Sum23[i];        Sm23N[i] += Sum23[i];
    sm25N += Sum25[i];        Sm25N[i] += Sum25[i];
    sm26N += Sum26[i];        Sm26N[i] += Sum26[i];
    sm29N += Sum29[i];        Sm29N[i] += Sum29[i];
    sm23N_sl += Sum23_sl[i];  Sm23N_sl[i] += Sum23_sl[i];       // 20180120     ошибка ?
    sm25N_sl += Sum25_sl[i];  Sm25N_sl[i] += Sum25_sl[i];       // 20180120
    sm26N_sl += Sum26_sl[i];  Sm26N_sl[i] += Sum26_sl[i];       // 20180120
    sm29N_sl += Sum29_sl[i];  Sm29N_sl[i] += Sum29_sl[i];       // 20180120
    sm23N_rb += Sum23_rb[i];  Sm23N_rb[i] += Sum23_rb[i];       // 20180120
    sm25N_rb += Sum25_rb[i];  Sm25N_rb[i] += Sum25_rb[i];       // 20180120
    sm26N_rb += Sum26_rb[i];  Sm26N_rb[i] += Sum26_rb[i];       // 20180120
    sm29N_rb += Sum29_rb[i];  Sm29N_rb[i] += Sum29_rb[i];       // 20180120


    SmSN[i] += SumS[i];            // сумма по служащим по строке для НТН
    SmRN[i] += SumR[i];            // сумма по рабочим  по строке для НТН
    SmVN[i] = SmSN[i] + SmRN[i];   // сумма по столбцу для НТН

    SumV[i] = SumS[i] + SumR[i];   // суммы всего по подраздел по столбцам
    SumIt[i] = SumIt[i] + SumV[i]; // суммы итого по предпр по столбцам

    sIt += SumS[i] + SumR[i];    
    SrV = SrS + SrR;    

    SumIt23[i] = SumIt23[i] + Sum23[i];      // 2014_03_03    для итогов 
    SumIt25[i] = SumIt25[i] + Sum25[i];      // 2014_03_03    по счетам
    SumIt26[i] = SumIt26[i] + Sum26[i];      // 2014_03_03        в 
    SumIt29[i] = SumIt29[i] + Sum29[i];      // 2014_03_03      ИТОГО

    sIt23 = sIt23 + Sum23[i];                       // 2014_03_03    для итогов
    sIt25 = sIt25 + Sum25[i];                       // 2014_03_03    по счетам
    sIt26 = sIt26 + Sum26[i];                       // 2014_03_03        в
    sIt29 = sIt29 + Sum29[i];                       // 2014_03_03      ИТОГО


    if ( ko == 1 )
      {
       SumKP[i] = SumKP[i] + SumV[i];
       SumKPsl[i] = SumKPsl[i] + SumS[i];
       SumKPrb[i] = SumKPrb[i] + SumR[i];

       SumKP23[i] = SumKP23[i] + Sum23[i];
       SumKP25[i] = SumKP25[i] + Sum25[i];
       SumKP26[i] = SumKP26[i] + Sum26[i];
       SumKP29[i] = SumKP29[i] + Sum29[i];
       sItKP = sItKP + Sum23[i] + Sum25[i] + Sum26[i] + Sum29[i];

                                    //  по КП по счетам по служ
       SumKP23_sl[i] += Sum23_sl[i];
       SumKP25_sl[i] += Sum25_sl[i];
       SumKP26_sl[i] += Sum26_sl[i];
       SumKP29_sl[i] += Sum29_sl[i];

       sItKPsl += SumS[i];
       sItKPrb += SumR[i];

       sItKP23 += Sum23[i];
       sItKP25 += Sum25[i];
       sItKP26 += Sum26[i];
       sItKP29 += Sum29[i];

       sItKP23_sl += Sum23_sl[i];
       sItKP25_sl += Sum25_sl[i];
       sItKP26_sl += Sum26_sl[i];
       sItKP29_sl += Sum29_sl[i];
       sItKP23_rb += Sum23_rb[i];
       sItKP25_rb += Sum25_rb[i];
       sItKP26_rb += Sum26_rb[i];
       sItKP29_rb += Sum29_rb[i];
      }

    if ( zo == 1 )
      {
       SumZV[i] = SumZV[i] + SumV[i];
       SumZVsl[i] = SumZVsl[i] + SumS[i];
       SumZVrb[i] = SumZVrb[i] + SumR[i];

       SumZV23[i] = SumZV23[i] + Sum23[i];
       SumZV25[i] = SumZV25[i] + Sum25[i];
       SumZV26[i] = SumZV26[i] + Sum26[i];
       SumZV29[i] = SumZV29[i] + Sum29[i];
       sItZV = sItZV + Sum23[i] + Sum25[i] + Sum26[i] + Sum29[i];

                                    //  по Заводу по счетам по служ
       SumZV23_sl[i] += Sum23_sl[i];
       SumZV25_sl[i] += Sum25_sl[i];
       SumZV26_sl[i] += Sum26_sl[i];
       SumZV29_sl[i] += Sum29_sl[i];

       sItZVsl += SumS[i];
       sItZVrb += SumR[i];

       sItZV23 += Sum23[i];
       sItZV25 += Sum25[i];
       sItZV26 += Sum26[i];
       sItZV29 += Sum29[i];      

       sItZV23_sl += Sum23_sl[i];
       sItZV25_sl += Sum25_sl[i];
       sItZV26_sl += Sum26_sl[i];
       sItZV29_sl += Sum29_sl[i];
       sItZV23_rb += Sum23_rb[i];
       sItZV25_rb += Sum25_rb[i];
       sItZV26_rb += Sum26_rb[i];
       sItZV29_rb += Sum29_rb[i];
      }

    if ( po == 1 )
      {
       SumPR[i] = SumPR[i] + SumV[i];
       SumPRsl[i] = SumPRsl[i] + SumS[i];
       SumPRrb[i] = SumPRrb[i] + SumR[i];

       SumPR23[i] = SumPR23[i] + Sum23[i];
       SumPR25[i] = SumPR25[i] + Sum25[i];
       SumPR26[i] = SumPR26[i] + Sum26[i];
       SumPR29[i] = SumPR29[i] + Sum29[i];
       sItPR = sItPR + Sum23[i] + Sum25[i] + Sum26[i] + Sum29[i];

                                    //  по Предпр по счетам по служ
       SumPR23_sl[i] += Sum23_sl[i];
       SumPR25_sl[i] += Sum25_sl[i];
       SumPR26_sl[i] += Sum26_sl[i];
       SumPR29_sl[i] += Sum29_sl[i];


       sItPRsl += SumS[i];
       sItPRrb += SumR[i];

       sItPR23 += Sum23[i];
       sItPR25 += Sum25[i];
       sItPR26 += Sum26[i];
       sItPR29 += Sum29[i];      

       sItPR23_sl += Sum23_sl[i];
       sItPR25_sl += Sum25_sl[i];
       sItPR26_sl += Sum26_sl[i];
       sItPR29_sl += Sum29_sl[i];
       sItPR23_rb += Sum23_rb[i];
       sItPR25_rb += Sum25_rb[i];
       sItPR26_rb += Sum26_rb[i];
       sItPR29_rb += Sum29_rb[i];
      }
   }

  v=s+r;               // всего по подраздел       //vN = vN + sN + rN;   // всего по НТН
  vN = vN + sm23N + sm25N + sm26N + sm29N;

  SrSN += SrS; 
  SrRN += SrR;
  //SrVN = SrSN + SrRN;
                                                //20131007
  SrN23 += Sr23;
  SrN25 += Sr25;
  SrN26 += Sr26;
  SrN29 += Sr29;
  SrVN = SrN23 + SrN25 + SrN26 + SrN29;

  SrN23_sl += Sr23_sl;
  SrN23_rb += Sr23_rb;
  SrN25_sl += Sr25_sl;
  SrN25_rb += Sr25_rb;
  SrN26_sl += Sr26_sl;
  SrN26_rb += Sr26_rb;
  SrN29_sl += Sr29_sl;
  SrN29_rb += Sr29_rb;




  if (sm23)   {

    if (Sr23_sl)  {
        SrSm=sm23_sl/Sr23_sl;
        sprintf(ex2,"_23_");
        sprintf(ex3,"служащие");
        WritStringEx2(Frst,ex2,ex3,Sr23_sl,sm23_sl,Sum23_sl[1],Sum23_sl[2],Sum23_sl[3],Sum23_sl[4],Sum23_sl[5],Sum23_sl[6],Sum23_sl[7],Sum23_sl[8],Sum23_sl[9],SrSm);
    }
    if (Sr23_rb)  {
        SrSm=sm23_rb/Sr23_rb;
        sprintf(ex2,"_23_");
        sprintf(ex3,"рабочие");
        WritStringEx2(Frst,ex2,ex3,Sr23_rb,sm23_rb,Sum23_rb[1],Sum23_rb[2],Sum23_rb[3],Sum23_rb[4],Sum23_rb[5],Sum23_rb[6],Sum23_rb[7],Sum23_rb[8],Sum23_rb[9],SrSm);
    }

    SrSm=sm23/Sr23;
    sprintf(ex2,"_23_____");
    sprintf(ex3,"по_сч_23");
    WritStringEx2(Frst,ex2,ex3,Sr23,sm23,Sum23[1],Sum23[2],Sum23[3],Sum23[4],Sum23[5],Sum23[6],Sum23[7],Sum23[8],Sum23[9],SrSm);
    sprintf(ex3,"");
  }

  if (sm25)   {

    if (Sr25_sl)  {
        SrSm=sm25_sl/Sr25_sl;
        sprintf(ex2,"_25_");
        sprintf(ex3,"служащие");
        WritStringEx2(Frst,ex2,ex3,Sr25_sl,sm25_sl,Sum25_sl[1],Sum25_sl[2],Sum25_sl[3],Sum25_sl[4],Sum25_sl[5],Sum25_sl[6],Sum25_sl[7],Sum25_sl[8],Sum25_sl[9],SrSm);
    }
    if (Sr25_rb)  {
        SrSm=sm25_rb/Sr25_rb;
        sprintf(ex2,"_25_");
        sprintf(ex3,"рабочие");
        WritStringEx2(Frst,ex2,ex3,Sr25_rb,sm25_rb,Sum25_rb[1],Sum25_rb[2],Sum25_rb[3],Sum25_rb[4],Sum25_rb[5],Sum25_rb[6],Sum25_rb[7],Sum25_rb[8],Sum25_rb[9],SrSm);
    }
    
    SrSm=sm25/Sr25;
    sprintf(ex2,"_25_____");
    sprintf(ex3,"по_сч_25");
    WritStringEx2(Frst,ex2,ex3,Sr25,sm25,Sum25[1],Sum25[2],Sum25[3],Sum25[4],Sum25[5],Sum25[6],Sum25[7],Sum25[8],Sum25[9],SrSm);
      sprintf(ex3,"");
  }

  if (sm26)   {

    if (Sr26_sl)  {
        SrSm=sm26_sl/Sr26_sl;
        sprintf(ex2,"_26_");
        sprintf(ex3,"служащие");
        WritStringEx2(Frst,ex2,ex3,Sr26_sl,sm26_sl,Sum26_sl[1],Sum26_sl[2],Sum26_sl[3],Sum26_sl[4],Sum26_sl[5],Sum26_sl[6],Sum26_sl[7],Sum26_sl[8],Sum26_sl[9],SrSm);
    }
    if (Sr26_rb)  {
        SrSm=sm26_rb/Sr26_rb;
        sprintf(ex2,"_26_");
        sprintf(ex3,"рабочие");
        WritStringEx2(Frst,ex2,ex3,Sr26_rb,sm26_rb,Sum26_rb[1],Sum26_rb[2],Sum26_rb[3],Sum26_rb[4],Sum26_rb[5],Sum26_rb[6],Sum26_rb[7],Sum26_rb[8],Sum26_rb[9],SrSm);
    }

    SrSm=sm26/Sr26;
    sprintf(ex2,"_26_____");
    sprintf(ex3,"по_сч_26");
    WritStringEx2(Frst,ex2,ex3,Sr26,sm26,Sum26[1],Sum26[2],Sum26[3],Sum26[4],Sum26[5],Sum26[6],Sum26[7],Sum26[8],Sum26[9],SrSm);
    sprintf(ex3,"");
  }

  if (sm29)   {

    if (Sr29_sl)  {
        SrSm=sm29_sl/Sr29_sl;
        sprintf(ex2,"_29_");
        sprintf(ex3,"служащие");
        WritStringEx2(Frst,ex2,ex3,Sr29_sl,sm29_sl,Sum29_sl[1],Sum29_sl[2],Sum29_sl[3],Sum29_sl[4],Sum29_sl[5],Sum29_sl[6],Sum29_sl[7],Sum29_sl[8],Sum29_sl[9],SrSm);
    }
    if (Sr29_rb)  {
        SrSm=sm29_rb/Sr29_rb;
        sprintf(ex2,"_29_");
        sprintf(ex3,"рабочие");
        WritStringEx2(Frst,ex2,ex3,Sr29_rb,sm29_rb,Sum29_rb[1],Sum29_rb[2],Sum29_rb[3],Sum29_rb[4],Sum29_rb[5],Sum29_rb[6],Sum29_rb[7],Sum29_rb[8],Sum29_rb[9],SrSm);
    }

    SrSm=sm29/Sr29;
    sprintf(ex2,"_29_____");
    sprintf(ex3,"по_сч_29");
    WritStringEx2(Frst,ex2,ex3,Sr29,sm29,Sum29[1],Sum29[2],Sum29[3],Sum29[4],Sum29[5],Sum29[6],Sum29[7],Sum29[8],Sum29[9],SrSm);
    sprintf(ex3,"");
  }

  //____по подразд
  if (s)  {
    SrSm=s/SrS;
    sprintf(ex2,"");
    sprintf(ex3,"Служащие:");
    WritStringEx2(Frst,ex2,ex3,SrS,s,SumS[1],SumS[2],SumS[3],SumS[4],SumS[5],SumS[6],SumS[7],SumS[8],SumS[9],SrSm);
    SrSm=0;
  }  
  if (r)  {
    SrSm=r/SrR;
    sprintf(ex2,"");
    sprintf(ex3,"Рабочие:");
    WritStringEx2(Frst,ex2,ex3,SrR,r,SumR[1],SumR[2],SumR[3],SumR[4],SumR[5],SumR[6],SumR[7],SumR[8],SumR[9],SrSm);
    SrSm=0;
  }
  //____по подразд


  SrSm=v/SrV;
  sprintf(ex2,"всего");
  sprintf(ex3,"");
  WritStringEx2(Frst,ex2,ex3,SrV,v,SumV[1],SumV[2],SumV[3],SumV[4],SumV[5],SumV[6],SumV[7],SumV[8],SumV[9],SrSm);
   

  CntStr++;
  CntStr++;

  SrSm=0;

  PreSum();
  PreSumBal();

  s=0; r=0; v=0;
  SrS=0; SrR=0;

  sm23=0; sm25=0; sm26=0; sm29=0;      //20131007
  Sr23=0; Sr25=0; Sr26=0; Sr29=0;      //20131007
 }



FillIdxFldTbl(&CTabl)
{
   TblFld[idxP] = CTabl.Find_Name_Fld("FCpodr");
   TblFld[idxK] = CTabl.Find_Name_Fld("FCkat");
   TblFld[idxT] = CTabl.Find_Name_Fld("C_FIO");
   TblFld[idxS] = CTabl.Find_Name_Fld("Spis");

   TblFld[idxS01] = CTabl.Find_Name_Fld("S_Col_58");
   TblFld[idxS02] = CTabl.Find_Name_Fld("Sum_26");
   TblFld[idxS03] = CTabl.Find_Name_Fld("Sum_27");
   TblFld[idxS04] = CTabl.Find_Name_Fld("Sum_28");
   TblFld[idxS05] = CTabl.Find_Name_Fld("Sum_35");
   TblFld[idxS06] = CTabl.Find_Name_Fld("Sum_36");
   TblFld[idxS07] = CTabl.Find_Name_Fld("Sum_44");
   TblFld[idxS08] = CTabl.Find_Name_Fld("Sum_50");
   TblFld[idxS09] = CTabl.Find_Name_Fld("Sum_60");

   TblFld[idxS10] = CTabl.Find_Name_Fld("Sum_52");    //20200429

//
//   TblFld[idxS14] = CTabl.Find_Name_Fld("S_Col_64");

   return 1;
}



SetupExcel()
{

 var File;                             //  привет
 File = CreateObject("CurPrnFile");    //        от 
 File.SetFlagBrowse(0);                //          Вита
 File.SetFlag_Print(0);                //              лия

//   xls=CreateObject("Excel.Application");  // создаем объект Excel.Application, т.е. запускаем Excel, если он установлен конечно

  xls = CreateObject("Excel.Application");
  GetCurrentDirectory(len,Dir);
  nm = "t_razved\\kb063dop.xlt";
  WorkDir = Dir + "\\";
  xls.Caption = OemToAnsi("Приказ 1");
  xls.Workbooks.Add(WorkDir+nm);

  wb = xls.Workbooks(1);
  wsh = wb.Worksheets.Item(1);

  name=xls.Workbooks.Item(1).Name;                  // читаем имя workbook'а, чтобы обращатья потом к нему по имени
  WSheet1=xls.Workbooks.Item(name).Worksheets.Item(1); // создаем ссылку на на наш worksheet чтобы избежать впоследствии длинных записей

  return 0;
}

//  int len = 512;
//  var xls=CreateObject("Excel.Application");  // создаем объект Excel.Application, т.е. запускаем Excel, если он установлен конечно
//  char Dir[1024];                             // строка для текущей директории
//  GetCurrentDirectory(len,Dir);               // получаем текущую директорию (это корень каталога ZPL из которого запустили АМБу)
//  string nm = "t_razved\\kb006.xls";          // имя Excel'евского файла, он должен находиться в каталоге ZPL\TAB_LS
//  var WorkDir = Dir + "\\";                   // получаем рабочий каталог, т.е. из ZPL переходим в TAB_LS
//  xls.Caption = OemToAnsi("Лист 1");          // заголовок
//  xls.Workbooks.Add(WorkDir+nm);              // открываем в Excel'е наш файл prim02.xls

//  string name=xls.Workbooks.Item(1).Name;                  // читаем имя workbook'а, чтобы обращатья потом к нему по имени
//  var WSheet1=xls.Workbooks.Item(name).Worksheets.Item(1); // создаем ссылку на на наш worksheet чтобы избежать впоследствии длинных записей

//  string cell; // в эту строку будем записывать имена ячеек worksheet'а


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

WriteToCell1(WSheet,Cell,str)
// WSheet - ссылка на worksheet
// Cell - имя ячейки
// str - значение, которое требуется записать в ячейку Cell рабочего листа WSheet
{
  WSheet.Range(Cell).Value=static_cast_to_string(str);
  return 0;
}

WritStringEx(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18,x19)
{
  char c1[5], c2[6], c3[9], c4[9];
  char c5[15], c6[15], c7[15], c8[15], c9[15], c10[15], c11[15], c12[15];
  char c13[15], c14[15], c15[15], c16[15], c17[15], c18[15], c19[15];
  sprintf(c1,"B%d",NmLnEx);
  sprintf(c2,"C%d",NmLnEx);
  sprintf(c3,"D%d",NmLnEx);
  sprintf(c4,"E%d",NmLnEx);
  sprintf(c5,"F%d",NmLnEx);
  sprintf(c6,"G%d",NmLnEx);
  sprintf(c7,"H%d",NmLnEx);
  sprintf(c8,"I%d",NmLnEx);
  sprintf(c9,"J%d",NmLnEx);
  sprintf(c10,"K%d",NmLnEx);
  sprintf(c11,"L%d",NmLnEx);
  sprintf(c12,"M%d",NmLnEx);
  sprintf(c13,"N%d",NmLnEx);
  sprintf(c14,"O%d",NmLnEx);
  sprintf(c15,"P%d",NmLnEx);
  sprintf(c16,"Q%d",NmLnEx);
  sprintf(c17,"R%d",NmLnEx);
  sprintf(c18,"S%d",NmLnEx);
  sprintf(c19,"T%d",NmLnEx);

  WriteToCell(c1,x1);
  WriteToCell(c2,OemToAnsi(x2));
  WriteToCell(c3,x3);
  WriteToCell(c4,x4);

  WriteToCell(c5,x5);
  WriteToCell(c6,x6);
  WriteToCell(c7,x7);
  WriteToCell(c8,x8);
  WriteToCell(c9,x9);
  WriteToCell(c10,x10);
  WriteToCell(c11,x11);
  WriteToCell(c12,x12);

  WriteToCell(c13,x13);
  WriteToCell(c14,x14);
  WriteToCell(c15,x15);
  WriteToCell(c16,x16);
  WriteToCell(c17,x17);
  WriteToCell(c18,x18);
  WriteToCell(c19,x19);

  n++;
  NmLnEx++;
}
WritStringEx2(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x20)
{
  char c1[5], c2[6], c3[9], c4[9];
  char c5[15], c6[15], c7[15], c8[15], c9[15], c10[15], c11[15], c12[15];
  char c13[15], c14[15], c15[15], c16[15], c17[15], c18[15], c19[15], c20[15];
  sprintf(c1,"B%d",NmLnEx);
  sprintf(c2,"C%d",NmLnEx);
  sprintf(c3,"D%d",NmLnEx);
  sprintf(c4,"E%d",NmLnEx);
  sprintf(c5,"F%d",NmLnEx);
  sprintf(c6,"G%d",NmLnEx);
  sprintf(c7,"H%d",NmLnEx);
  sprintf(c8,"I%d",NmLnEx);
  sprintf(c9,"J%d",NmLnEx);
  sprintf(c10,"K%d",NmLnEx);
  sprintf(c11,"L%d",NmLnEx);
  sprintf(c12,"M%d",NmLnEx);
  sprintf(c13,"N%d",NmLnEx);
  sprintf(c14,"O%d",NmLnEx);
  sprintf(c15,"P%d",NmLnEx);
  sprintf(c16,"Q%d",NmLnEx);
  sprintf(c17,"R%d",NmLnEx);
  sprintf(c18,"S%d",NmLnEx);
  sprintf(c19,"T%d",NmLnEx);
  sprintf(c20,"U%d",NmLnEx);

  WriteToCell(c1,x1);
  WriteToCell(c2,OemToAnsi(x2));
  WriteToCell(c3,OemToAnsi(x3));
  WriteToCell(c4,x4);

  WriteToCell(c5,x5);
  WriteToCell(c6,x6);
  WriteToCell(c7,x7);
  WriteToCell(c8,x8);
  WriteToCell(c9,x9);
  WriteToCell(c10,x10);
  WriteToCell(c11,x11);
  WriteToCell(c12,x12);

  WriteToCell(c13,x13);
//20200429  WriteToCell(c14,x14);
//  WriteToCell(c15,x15);     // 20180323
//  WriteToCell(c16,x16);     // 20180323
//  WriteToCell(c17,x17);     // 20180323
//  WriteToCell(c18,x18);     // 20180323
//  WriteToCell(c19,x19);     // 20180323
//  WriteToCell(c20,x20);     // 20180323

//20200429  WriteToCell(c15,x20);       // 20180323
  WriteToCell(c14,x14);       // 20200429
  WriteToCell(c15,x14);       // 20200429
  WriteToCell(c16,x20);       // 20200429

  n++;
  NmLnEx++;
}
