Разработка программного изделия «Материальное требование» (раздел курсовой работы "Тексты программ"), страница 5

          covOptional,covTrue,covOptional,covOptional,covOptional,covOptional,covOptional,covOptional,covOptional,covOptional,covOptional,covOptional);         

          sheets =book.GetSheets();

На следующем этапе считывается текст заголовков диалогового окна, представляющего результаты запроса и после удаления лишнего текста, предшествующего символу “:” этот текст переносится в шапку документа Excel.

          sheet = sheets.GetItem(COleVariant((short)2));

          sheet.Activate();

          CString strText;

          char steps[] = ":";

          char *token;

          int Length = 0;

          range = sheet.GetRange(COleVariant("A5"),COleVariant("A5"));

          Header1.GetWindowText(strText);

          token = strtok(strText.GetBuffer(512),steps);

          Length = strlen(token);

          strText = strText.Right(strText.GetLength() - Length - 2);

          range.SetValue(COleVariant(strText));

          range = sheet.GetRange(COleVariant("D5"),COleVariant("D5"));

          Header2.GetWindowText(strText);

          token = strtok(strText.GetBuffer(512),steps);

          Length = strlen(token);

          strText = strText.Right(strText.GetLength() - Length - 2);

          range.SetValue(COleVariant(strText));

          range = sheet.GetRange(COleVariant("G5"),COleVariant("G5"));

          Header3.GetWindowText(strText);

          token = strtok(strText.GetBuffer(512),steps);

          Length = strlen(token);

          strText = strText.Right(strText.GetLength() - Length - 2);

          range.SetValue(COleVariant(strText));

          range = sheet.GetRange(COleVariant("J5"),COleVariant("J5"));

          Header4.GetWindowText(strText);

          token = strtok(strText.GetBuffer(512),steps);

          Length = strlen(token);

          strText = strText.Right(strText.GetLength() - Length - 2);

          range.SetValue(COleVariant(strText));

На заключительном этапе в первом цикле вычисляется количество документов, найденных в результате выполнения запроса. Далее во втором цикле происходит заполнение ячеек таблицы Excel значениями из формы, а также форматирование области вывода (объединение ячеек и формирование табличной рамки).

          int docs_found=0;

          for (int i=1;;i++)              

          {

                    CString str = m_Grid.GetItemText(i,0);

                    if (str == "")

                              break;

                    docs_found++;

          }

          for (i = 8 ;i<docs_found + 8;i++)

          {

                    CString strNumber;

                    strNumber.Format("%i",i);

                    range = sheet.GetRange(COleVariant("A"+strNumber),COleVariant("B"+strNumber));

                    range.Merge(COleVariant(covTrue));

                    borders = range.GetBorders();

                    borders.SetWeight(COleVariant(short(3)));

                    range.SetValue(COleVariant(m_Grid.GetItemText(i-7,0)));

                    range.SetHorizontalAlignment(COleVariant((short)-4108));

                    range = sheet.GetRange(COleVariant("C"+strNumber),COleVariant("D"+strNumber));

                    range.Merge(COleVariant(covTrue));

                    borders = range.GetBorders();

                    borders.SetWeight(COleVariant(short(3)));

                    range.SetValue(COleVariant(m_Grid.GetItemText(i-7,1)));

                    range.SetHorizontalAlignment(COleVariant((short)-4108));

                    range = sheet.GetRange(COleVariant("E"+strNumber),COleVariant("E"+strNumber));

                    borders = range.GetBorders();

                    borders.SetWeight(COleVariant(short(3)));

                    range.SetValue(COleVariant(m_Grid.GetItemText(i-7,2)));

                    range.SetHorizontalAlignment(COleVariant((short)-4108));

                    range = sheet.GetRange(COleVariant("F"+strNumber),COleVariant("G"+strNumber));

                    range.Merge(COleVariant(covTrue));

                    borders = range.GetBorders();

                    borders.SetWeight(COleVariant(short(3)));

                    range.SetValue(COleVariant(m_Grid.GetItemText(i-7,3)));

                    range.SetHorizontalAlignment(COleVariant((short)-4108));

                    range = sheet.GetRange(COleVariant("H"+strNumber),COleVariant("H"+strNumber));

                    borders = range.GetBorders();

                    borders.SetWeight(COleVariant(short(3)));

                    range.SetValue(COleVariant(m_Grid.GetItemText(i-7,4)));

                    range.SetHorizontalAlignment(COleVariant((short)-4108));

                    range = sheet.GetRange(COleVariant("I"+strNumber),COleVariant("J"+strNumber));

                    range.Merge(COleVariant(covTrue));

                    borders = range.GetBorders();

                    borders.SetWeight(COleVariant(short(3)));

                    range.SetValue(COleVariant(m_Grid.GetItemText(i-7,5)));

                    range.SetHorizontalAlignment(COleVariant((short)-4108));

                    range = sheet.GetRange(COleVariant("K"+strNumber),COleVariant("L"+strNumber));

                    range.Merge(COleVariant(covTrue));

                    borders = range.GetBorders();

                    borders.SetWeight(COleVariant(short(3)));

                    range.SetValue(COleVariant(m_Grid.GetItemText(i-7,6)));

                    range.SetHorizontalAlignment(COleVariant((short)-4108));

          }