Beispiel #1
0
        private void btnReport_Click(object sender, EventArgs e)
        {
            if (dtData.DefaultView.Count == 0)
            {
                return;
            }
            ExcelUnLoad rep = new ExcelUnLoad();

            int crow   = 1;
            int maxCol = 4;

            rep.SetColumnWidth(1, 1, 1, 1, 10);
            rep.SetColumnWidth(2, 2, 2, 2, 15);
            rep.SetColumnWidth(3, 3, 3, 3, 40);
            rep.SetColumnWidth(4, 4, 4, 4, 20);

            rep.AddSingleValue("Отчет о загрузке картинок", crow, 1);
            rep.Merge(crow, 1, crow, maxCol);
            rep.SetCellAlignmentToCenter(crow, 1, crow, maxCol);
            rep.SetCellAlignmentToJustify(crow, 1, crow, maxCol);
            rep.SetFontBold(crow, 1, crow, 1);

            crow += 2;

            rep.AddFilter("EAN", tbEan, ref crow);
            rep.AddFilter("Наименование", tbName, ref crow);
            rep.AddFilter("Артикул", tbIdTovar, ref crow);
            rep.AddFilter("Выбран вариант", chbIsNotFount, ref crow);
            rep.AddFilter("Выбран вариант", chbIsUpdated, ref crow);
            rep.AddFilter("Выбран вариант", chbNoImage, ref crow);

            crow++;
            int startRow = crow;
            int col      = 1;

            foreach (DataGridViewColumn dc in dgvData.Columns)
            {
                rep.AddSingleValue(dc.HeaderText, crow, col);
                rep.SetFontBold(crow, col, crow, col);
                rep.SetCellAlignmentToCenter(crow, col, crow, col);
                rep.SetCellAlignmentToJustify(crow, col, crow, col);
                rep.SetWrapText(crow, col, crow, col);
                col++;
            }

            foreach (DataRowView row in dtData.DefaultView)
            {
                crow++;
                col = 1;
                foreach (DataGridViewColumn dc in dgvData.Columns)
                {
                    rep.AddSingleValue(row[dc.DataPropertyName].ToString(), crow, col);
                    rep.SetWrapText(crow, col, crow, col);
                    Color color = Color.White;
                    if (row["result"].ToString() == "Обновлено")
                    {
                        color = panel1.BackColor;
                    }
                    else if (row["result"].ToString() == "Картинка не найдена")
                    {
                        color = panel2.BackColor;
                    }
                    else if (row["result"].ToString() == "Товар не найден")
                    {
                        color = panel3.BackColor;
                    }
                    rep.SetCellColor(crow, col, crow, col, color);
                    col++;
                }
            }
            rep.SetBorders(startRow, 1, crow, maxCol);

            rep.Show();
        }