Exemple #1
0
//---------------------------------------------------------------------------
void __fastcall TFormReportForma3::CreateWordDocument(void)
{
    ExcelMacros macros;
    macros.BeginMacros();

// шапка
    AnsiString sheet;
    sheet += "Индекс книги;Регистрационный номер;Фамилия, имя, отчество;Наименование специальности;"
        "Код специальности;Код квалификации;Наименование квалификации;Год окончания вуза;"
        "Диплом с отличием да/нет;Серия диплома;№ диплома;Дата выдачи;Решение ГАК от;"
        "Номер протокола ГАК;Номер приказа об отчислении;Дата приказа об отчислении;Номер группы\n";


// делаем бордюр
    macros.Cells(1, 1, data.size() + 1, 17, "Select");
    macros.InsertLine("Selection.Borders(xlDiagonalDown).LineStyle = xlNone");
    macros.InsertLine("Selection.Borders(xlDiagonalUp).LineStyle = xlNone");
    macros.InsertLine("With Selection.Borders(xlEdgeLeft)");
    macros.InsertLine("    .LineStyle = xlContinuous");
    macros.InsertLine("    .Weight = xlThin");
    macros.InsertLine("    .ColorIndex = xlAutomatic");
    macros.InsertLine("End With");
    macros.InsertLine("With Selection.Borders(xlEdgeTop)");
    macros.InsertLine("    .LineStyle = xlContinuous");
    macros.InsertLine("    .Weight = xlThin");
    macros.InsertLine("    .ColorIndex = xlAutomatic");
    macros.InsertLine("End With");
    macros.InsertLine("With Selection.Borders(xlEdgeBottom)");
    macros.InsertLine("    .LineStyle = xlContinuous");
    macros.InsertLine("    .Weight = xlThin");
    macros.InsertLine("    .ColorIndex = xlAutomatic");
    macros.InsertLine("End With");
    macros.InsertLine("With Selection.Borders(xlEdgeRight)");
    macros.InsertLine("    .LineStyle = xlContinuous");
    macros.InsertLine("    .Weight = xlThin");
    macros.InsertLine("    .ColorIndex = xlAutomatic");
    macros.InsertLine("End With");
    macros.InsertLine("With Selection.Borders(xlInsideVertical)");
    macros.InsertLine("    .LineStyle = xlContinuous");
    macros.InsertLine("    .Weight = xlThin");
    macros.InsertLine("    .ColorIndex = xlAutomatic");
    macros.InsertLine("End With");
    macros.InsertLine("With Selection.Borders(xlInsideHorizontal)");
    macros.InsertLine("    .LineStyle = xlContinuous");
    macros.InsertLine("    .Weight = xlThin");
    macros.InsertLine("    .ColorIndex = xlAutomatic");
    macros.InsertLine("End With");
// задали размеры столбцов
    macros.InsertLine("Columns(\"A:A\").ColumnWidth = 5.86");
    macros.InsertLine("Columns(\"B:B\").ColumnWidth = 13");
    macros.InsertLine("Columns(\"C:C\").ColumnWidth = 13.14");
    macros.InsertLine("Columns(\"D:D\").ColumnWidth = 11.43");
    macros.InsertLine("Columns(\"E:E\").ColumnWidth = 11.71");
    macros.InsertLine("Columns(\"F:F\").ColumnWidth = 10.8");
    macros.InsertLine("Columns(\"G:G\").ColumnWidth = 11");
    macros.InsertLine("Columns(\"H:H\").ColumnWidth = 7.71");
    macros.InsertLine("Columns(\"I:I\").ColumnWidth = 7.3");
    macros.InsertLine("Columns(\"J:J\").ColumnWidth = 7.57");
    macros.InsertLine("Columns(\"P:P\").ColumnWidth = 9");
    macros.InsertLine("Columns(\"K:K\").ColumnWidth = 6.57");
    macros.InsertLine("Columns(\"O:O\").ColumnWidth = 9.29");
// задаем размер шрифта
    macros.Cells(1, 1, data.size() + 1, 17, "Select");
    macros.InsertLine("With Selection.Font");
    macros.InsertLine("    .Size = 8");
    macros.InsertLine("End With");
// задаем выравнивание текста
    macros.Cells(1, 1, data.size() + 1, 17, "Select");
    macros.InsertLine("With Selection");
    macros.InsertLine("    .HorizontalAlignment = xlCenter");
    macros.InsertLine("    .VerticalAlignment = xlCenter");
    macros.InsertLine("    .WrapText = True");
    macros.InsertLine("End With");
// задаем для столбца тип текст
    macros.Cells(2, 2, data.size() + 1, 2, "Select");
    macros.InsertLine("Selection.NumberFormat = \"@\"");

    macros.Cells(2, 5, data.size() + 1, 5, "Select");
    macros.InsertLine("Selection.NumberFormat = \"@\"");

    macros.Cells(2, 11, data.size() + 1, 11, "Select");
    macros.InsertLine("Selection.NumberFormat = \"@\"");
//
    macros.Cells(2, 3, data.size() + 1, 3, "Select");
    macros.InsertLine("Selection.HorizontalAlignment = xlLeft");
// выводим данные
    for (int i = 0; i < data.size(); i++)
    {
       sheet +=
            data[i]->index + ";" +
            /* data[i]->reg_num + */ ";" +
            data[i]->fio + ";" +
            data[i]->namespec + ";" +
            /* data[i]->kod_spec + */ ";" +
            data[i]->kod_kvalif + ";" +
            data[i]->namekvalif + ";" +
            curr_year + ";" +
            data[i]->otl + ";" +
            data[i]->serdip + ";" +
            /* data[i]->numdip + */ ";" +
            data[i]->datavid + ";" +
            data[i]->datagak + ";" +
            data[i]->numprotgak + ";" +
            data[i]->numotch + ";" +
            data[i]->dataotch + ";" +
            data[i]->grp + "\n";

        AnsiString pos_row = IntToStr(i+2);
        macros.Select("B" + pos_row);
        macros.Formula(data[i]->reg_num);
        macros.Select("E" + pos_row);
        macros.Formula(data[i]->kod_spec);
        macros.Select("K" + pos_row);
        macros.Formula(data[i]->numdip);
    }
    macros.InsertLine("ActiveWindow.ScrollRow = 1");
    macros.InsertLine("ActiveWindow.ScrollColumn = 1");

    // получаем текущее положение
    char path_buf[_MAX_PATH];
    char drive[_MAX_DRIVE];
    char dir[_MAX_DIR];

    GetModuleFileName(NULL,path_buf,sizeof(path_buf)-1);
    _splitpath(path_buf,drive,dir,0,0);
    _makepath(path_buf,drive,dir,0,0);

    AnsiString filename = AnsiString(drive) + AnsiString(dir) + "forma3.csv";
    ofstream output_file(filename.c_str(), ios::in|ios::trunc);
    output_file.write(sheet.c_str(), sheet.Length());
    output_file.close();

    macros.EndMacros();
    macros.RunMacros(filename);

}
Exemple #2
0
//---------------------------------------------------------------------------
void    __fastcall  TFormReportUchebKartStud::CreateWordDocument(void)
{
    AnsiString NumZ, SecondName, FirstName, ThirdName, Adres, NumPricas, InDate,
        spec, VipQualifWork, OutDate, Qualific, nGak;
    AnsiString perevodInfo[5];

    GetOchenkiStudenta();
    UpdateView();
    GetInfoStudent(NumZ, SecondName, FirstName, ThirdName, Adres, NumPricas, InDate,
        spec, VipQualifWork, OutDate, Qualific, nGak, perevodInfo);

    ExcelMacros macros;
    macros.BeginMacros();

    // заполянем верхнюю часть катрочки
    macros.Select("L2");
    macros.Formula("     №   " + NumZ);
    macros.Select("A6");
    macros.Formula("1.   " + SecondName + " " + FirstName + " " + ThirdName);
    macros.Select("A8");
    macros.FilterText(Adres);
    macros.Formula("2. Адрес:   " + Adres);
    macros.Select("A10");
    macros.Formula("3. Зачислен в ВУЗ приказом №   " + NumPricas);
    macros.Select("A11");
    macros.Formula("от   " + GetDateAsString(InDate));
    macros.Select("A16");
    macros.Formula("по специальности   " + spec);
    macros.Select("H21");
    macros.FilterText(VipQualifWork);
    macros.Formula("  " + VipQualifWork);
    macros.Select("H27");
    macros.Formula("присвоена квалификация   " + Qualific);
    if (OutDate.Length() > 0)
    {
        macros.Select("H26");
        macros.Formula("от " + GetDateAsString(OutDate, true));
        macros.Select("H23");
        macros.Formula("и защитил " + GetDateAsString(OutDate, true));
    }
    if (nGak.Length() > 0)
    {
        macros.Select("H25");
        macros.Formula(" комиссии  (протокол №    " + nGak);
    }

    // заполняем отметки о переводах
    AnsiString perevodPos[5] = {"A62", "H62", "A96", "H96", "A130"};
    for (int i = 0; i < 5; ++i)
       if (perevodInfo[i] != "")
       {
         macros.Select(perevodPos[i]);
         macros.Formula(perevodInfo[i]);
       }


    // зполняем оценками таблицу

    for (int i = 0; i < mas_ochenka.size(); i++)
    {
        Progress* pr =  mas_ochenka[i];
        if (!(pr->idclass == tdCommon || pr->idclass == tdCourseWork || \
            pr->idclass == tdCourseProject || pr->idclass == tdPraktica))
                continue;

        if (pr->numplansemestr > 12 || pr->numplansemestr < 1)
        {
            AnsiString er = "Предмет \"" + pr->title + "\" записан на " + \
                pr->numplansemestr + " - это неправильно \n" \
                "Отчет не будет выведен";
            Application->MessageBox(er.c_str(), "Ошибка.", MB_OK | MB_ICONEXCLAMATION);
            return;
        }
        if (pr->numplansemestr == 12 )
            pr->numplansemestr = 12;
        AnsiString range = "";
        if (pr->count_line != 0)
        {
            for (int j = 1; j <= 5; j++)
            {
                range = AnsiString(pos_semestr[pr->numplansemestr - 1].col[j]) +
                    IntToStr(pos_semestr[pr->numplansemestr - 1].row);
                range += ":" + AnsiString(pos_semestr[pr->numplansemestr - 1].col[j]) +
                    IntToStr(pos_semestr[pr->numplansemestr - 1].row + pr->count_line);
                macros.Select(range);
                macros.MergeCell();
            }
            pos_semestr[pr->numplansemestr - 1].row += pr->count_line;
         }

         range = AnsiString(pos_semestr[pr->numplansemestr - 1].col[1]) +
             IntToStr(pos_semestr[pr->numplansemestr - 1].row);
         macros.Select(range);
         macros.Formula(pr->title);

         range = AnsiString(pos_semestr[pr->numplansemestr - 1].col[2]) +
             IntToStr(pos_semestr[pr->numplansemestr - 1].row);
         macros.Select(range);
         //macros.Formula((pr->count_hours == "0")?AnsiString(""):pr->count_hours);
         if (pr->idclass == tdCommon)
            if (pr->numplansemestr != 12 && pr->hours[pr->numplansemestr - 1] != "0  ")
                macros.Formula(pr->hours[pr->numplansemestr - 1]);
            else
                macros.Formula((pr->count_hours == "0")?AnsiString(""):pr->count_hours);



         AnsiString pos = "";
         if (pr->estimation < 4)    // экзамен
            pos = AnsiString(pos_semestr[pr->numplansemestr - 1].col[3]);
         else                      // зачет
            pos = AnsiString(pos_semestr[pr->numplansemestr - 1].col[4]);

         range = pos + IntToStr(pos_semestr[pr->numplansemestr - 1].row);
         macros.Select(range);
         macros.Formula(tip_ocenok[pr->estimation]);

         pos_semestr[pr->numplansemestr - 1].row ++;
    }
    // заполнение по междисц испыт
    int pos = 16;  // начиная с 16 строки в екселе
    for (int i = 0; i < mas_ochenka.size(); i++)
    {
        Progress* pr =  mas_ochenka[i];
        if (pr->idclass != tdItogAttest)
            continue;
        macros.Select("J" + IntToStr(pos));
        macros.Formula(pr->dis_shorttitle);
        macros.Select("M" + IntToStr(pos));
        macros.Formula(tip_ocenok[pr->estimation]);
        pos++;
    }
    macros.Select("A4");

    macros.EndMacros();

    // получаем текущее положение
    char path_buf[_MAX_PATH];
    char drive[_MAX_DRIVE];
    char dir[_MAX_DIR];

    GetModuleFileName(NULL,path_buf,sizeof(path_buf)-1);
    _splitpath(path_buf,drive,dir,0,0);
    _makepath(path_buf,drive,dir,0,0);

    AnsiString path_host_template = AnsiString(drive) + AnsiString(dir) + "template.xlt";
    if (FileExists(path_host_template))
        macros.RunMacros(path_host_template);
    else
       macros.RunMacros("c:\\template.xlt");

}