Пример #1
0
        protected Workbook createWorkbook()
        {
            Workbook workbook = new Workbook();

            workbook.Sheets.Add(SheetType.Worksheet);
            Worksheet worksheet = workbook.ActiveWorksheet;

            worksheet.Name = "KET " + forDate.ToString("dd-MM-yyyy");
            List <TaskForH> tasks = getTasksForHelpers(forDate);

            prepareDocument(worksheet);
            int         currentRow = 1;
            CellBorder  border     = new CellBorder(CellBorderStyle.Thin, tcBlack);
            CellBorders borders    = new CellBorders(border, border, border, border, null, null, null, null);
            double      fontSize   = 12;

            foreach (TaskForH curTask in tasks)
            {
                worksheet.Cells[currentRow, 0].SetValue(curTask.Count.ToString());
                worksheet.Cells[currentRow, 0].SetFontSize(fontSize);
                worksheet.Cells[currentRow, 0].SetBorders(borders);
                worksheet.Cells[currentRow, 1].SetValue(curTask.Customer);
                worksheet.Cells[currentRow, 1].SetFormat(new CellValueFormat("@"));
                worksheet.Cells[currentRow, 1].SetFontSize(fontSize);
                worksheet.Cells[currentRow, 1].SetBorders(borders);
                worksheet.Cells[currentRow, 2].SetValue(curTask.FromPlace);
                worksheet.Cells[currentRow, 2].SetFormat(new CellValueFormat("@"));
                worksheet.Cells[currentRow, 2].SetFontSize(fontSize);
                worksheet.Cells[currentRow, 2].SetBorders(borders);
                worksheet.Cells[currentRow, 3].SetValue(curTask.FromTime + " - " + curTask.ToTime);
                worksheet.Cells[currentRow, 3].SetFontSize(fontSize);
                worksheet.Cells[currentRow, 3].SetBorders(borders);
                worksheet.Cells[currentRow, 4].SetValue(curTask.Comments);
                worksheet.Cells[currentRow, 4].SetIsWrapped(true);
                worksheet.Cells[currentRow, 4].SetFontSize(fontSize);
                worksheet.Cells[currentRow, 4].SetBorders(borders);
                currentRow++;
            }
            for (int i = 0; i < worksheet.Columns.Count; i++)
            {
                worksheet.Columns[i].AutoFitWidth();
            }
            for (int i = 0; i < worksheet.Columns.Count; i++)
            {
                if (i == 4)
                {
                    worksheet.Columns[i].SetWidth(new ColumnWidth(500, true));
                }
                ColumnSelection columnSelection = worksheet.Columns[i];
                ColumnWidth     columnWidth     = columnSelection.GetWidth().Value;
                double          curColWidth     = columnWidth.Value + 10;
                if (curColWidth > 2000)
                {
                    curColWidth = 2000;
                }
                columnSelection.SetWidth(new ColumnWidth(curColWidth, columnWidth.IsCustom));
            }
            ColumnSelection columnSelection4 = worksheet.Columns[4];
            ColumnWidth     columnWidth4     = columnSelection4.GetWidth().Value;
            double          curColWidth4     = columnWidth4.Value + 10;

            if (curColWidth4 > 2000)
            {
                curColWidth4 = 2000;
            }
            columnSelection4.SetWidth(new ColumnWidth(curColWidth4, columnWidth4.IsCustom));
            return(workbook);
        }
Пример #2
0
        private CellBorders CreateCellBorders(Cell cell)
        {
            var borders = new CellBorders();

            if (cell.BorderTop != null)
            {
                borders.Top = new CellBorder(CellBorderStyle.Thin, new ThemableColor(cell.BorderTop.Color.ToColor()));
            }

            if (cell.BorderBottom != null)
            {
                borders.Bottom = new CellBorder(CellBorderStyle.Thin, new ThemableColor(cell.BorderBottom.Color.ToColor()));
            }

            if (cell.BorderLeft != null)
            {
                borders.Left = new CellBorder(CellBorderStyle.Thin, new ThemableColor(cell.BorderLeft.Color.ToColor()));
            }

            if (cell.BorderRight != null)
            {
                borders.Right = new CellBorder(CellBorderStyle.Thin, new ThemableColor(cell.BorderRight.Color.ToColor()));
            }

            return borders;
        }
Пример #3
0
        private void ImportBorders(CellBorders cellBorders)
        {
            Brush brush = ConvertToBrush(cellBorders[IndividualBorder.Left]);
            Thickness thickness = ConvertToThickness(cellBorders[IndividualBorder.Left]);

            LeftBorder = new Border();

            LeftBorder.BorderBrush = brush;
            LeftBorder.BorderThickness = thickness;
            LeftBorder.Width = thickness.Left;

            LeftBorder.HorizontalAlignment = HorizontalAlignment.Left;
            LeftBorder.VerticalAlignment = VerticalAlignment.Stretch;

            Content = LeftBorder;
            LeftBorder.Child = Label;
        }