Esempio n. 1
0
        private ExcelXml PrepareXL(out List <PrintColumn> cols)
        {
            ExcelXml excel = new ExcelXml();

            excel.AddDefaultStyles();
            excel.AddDefaultWorksheet("Report", "", true, "Список");

            Dictionary <string, PrintColumn> dList = new Dictionary <string, PrintColumn>();

            cols = InitPrintColumn();

            foreach (PrintColumn col in cols)
            {
                excel.AddColumn(col.Width, true, col.GetStyleID());
            }

            excel.AddRow("H3");
            excel.AddRepeatedRows(1, 1);

            foreach (PrintColumn col in cols)
            {
                excel.AddCell(col.ColumnCaption);
            }
            return(excel);
        }
Esempio n. 2
0
        public ExcelXml PrintList <BD, BS>()
            where BS : BaseSet <BD, BS>, new()
            where BD : BaseDat <BD>, new()
        {
            List <PrintColumn> cols;
            ExcelXml           excel = PrepareXL(out cols);

            BS lst = this.GetSelectedSet <BD, BS>();

            if (lst.Count <= 1)
            {
                lst = DataSource as BS;
            }

            foreach (BD dat in lst)
            {
                excel.AddRow();
                foreach (PrintColumn col in cols)
                {
                    string text = "";
                    try
                    {
                        object val = dat.GetDatValue(col.ColumnName);
                        if (val == null)
                        {
                            val = BO.Reports.ExtraRepDataInfo.GetValue(dat, col.ColumnName);
                        }
                        if (val != null)
                        {
                            switch (col.GetCellType())
                            {
                            case CellType.Number:
                                text = (val is decimal) ? ((decimal)val).ToString("###0.#######") : val.ToString();
                                text = text.Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator, ".");
                                break;

                            case CellType.Boolean:
                                text = ((bool)val) ? "+" : "";
                                break;

                            case CellType.Xml:
                                text = ((XmlDocument)val).OuterXml;
                                break;

                            case CellType.DateTime:
                                if (val is DateTime && (DateTime)val != DateTime.MinValue)
                                {
                                    text = ((DateTime)val).ToString("yyyy-MM-dd");
                                }
                                break;

                            default:
                                text = val.ToString();
                                break;
                            }
                        }
                    }
                    catch (Exception exp)
                    {
                        text = "Ошибка: " + Common.ExMessage(exp);
                    }
                    CellType tp = col.GetCellType();
                    if (!(tp == CellType.DateTime && Common.IsNullOrEmpty(text)))
                    {
                        excel.AddCell(tp, text);
                    }
                }
            }
            return(excel);
        }
Esempio n. 3
0
        public ExcelXml PrintList()
        {
            List <PrintColumn> cols;
            ExcelXml           excel = PrepareXL(out cols);

            foreach (DataGridViewRow item in this.SelectedRows)
            {
                excel.AddRow();
                foreach (PrintColumn col in cols)
                {
                    string text = "";
                    try
                    {
                        object val = item.Cells[col.ColumnName].Value;
                        //if (val == null)
                        //    val = BO.Reports.ExtraRepDataInfo.GetValue(dat, col.ColumnName);
                        if (val != null)
                        {
                            switch (col.GetCellType())
                            {
                            case CellType.Number:
                                text = (val is decimal) ? ((decimal)val).ToString("###0.#######") : val.ToString();
                                text = text.Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator, ".");
                                break;

                            case CellType.Boolean:
                                text = ((bool)val) ? "+" : "";
                                break;

                            case CellType.Xml:
                                text = ((XmlDocument)val).OuterXml;
                                break;

                            case CellType.DateTime:
                                if (val is DateTime && (DateTime)val != DateTime.MinValue)
                                {
                                    text = ((DateTime)val).ToString("yyyy-MM-dd");
                                }
                                break;

                            default:
                                text = val.ToString();
                                break;
                            }
                        }
                    }
                    catch (Exception exp)
                    {
                        text = "Ошибка: " + Common.ExMessage(exp);
                    }
                    CellType tp = col.GetCellType();
                    if (!(tp == CellType.DateTime && Common.IsNullOrEmpty(text)))
                    {
                        excel.AddCell(tp, text);
                    }
                }
            }



            return(excel);
        }