Exemplo n.º 1
0
        private Point GetArraySize(KardExportData data)
        {
            var i      = 0;
            var row    = 0;
            var result = new Point();

            while (true)
            {
                if (data.Data[i, 0] == @"Дата/время")
                {
                    row = i;
                }
                if (data.Data[i, 0] == null)
                {
                    result.X = i;
                    break;
                }
                i++;
            }
            var j = 0;

            while (true)
            {
                if (data.Data[row, j] == null)
                {
                    result.Y = j;
                    break;
                }
                j++;
            }
            return(result);
        }
Exemplo n.º 2
0
        private void SetSheetKadr(Workbook workbook, KardExportData data)
        {
            Worksheet kadrSheet;

            //Определяем с какого листа начинать запись
            if (!Action.Info && workbook.Worksheets.Count == 1)
            {
                kadrSheet = workbook.Worksheets[0];
            }
            else
            {
                kadrSheet = workbook.Worksheets.Add();
            }

            kadrSheet.Name = data.Interval;

            var arraySize = GetArraySize(data);
            var x         = arraySize.X;
            var y         = arraySize.Y;

            string columns = GetExcelColumnName(y + 1);
            int    rows    = GetXCount(x);

            kadrSheet[columns + rows].Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            kadrSheet[columns + rows].Alignment.Vertical   = SpreadsheetVerticalAlignment.Center;

            for (int i = 0; i < data.Data.GetLength(0); i++)
            {
                for (int j = 0; j < data.Data.GetLength(1); j++)
                {
                    var val = data.Data[i, j];
                    if (val is DateTime)
                    {
                        kadrSheet.Cells[i, j].NumberFormat = "dd.MM.yyyy HH:mm";
                        kadrSheet.Cells[i, j].SetValue((DateTime)val);
                    }
                    if (val is int)
                    {
                        kadrSheet.Cells[i, j].SetValue((int)val);
                    }

                    if (val is Double)
                    {
                        kadrSheet.Cells[i, j].SetValue((Double)val);
                    }

                    if (!(val is int) && !(val is Double) && !(val is DateTime))
                    {
                        kadrSheet.Cells[i, j].SetValue(val);
                    }

                    if (i < x && j < y)
                    {
                        kadrSheet.Cells[i, j].Borders.SetOutsideBorders(Color.Black, BorderLineStyle.Thin);
                    }
                }
            }
            kadrSheet.Columns.AutoFit(0, y);
        }