Beispiel #1
0
        private Workbook GenerateWorkbook()
        {
            var export = pivot.GenerateExport();

            Workbook workbook = new Workbook();

            workbook.History.IsEnabled = false;

            var worksheet = workbook.Worksheets.Add();

            workbook.SuspendLayoutUpdate();
            int rowCount    = export.RowCount;
            int columnCount = export.ColumnCount;

            var allCells = worksheet.Cells[0, 0, rowCount - 1, columnCount - 1];

            allCells.SetFontFamily(new ThemableFontFamily(pivot.FontFamily));
            allCells.SetFontSize(12);
            allCells.SetFill(GenerateFill(pivot.Background));

            foreach (var cellInfo in export.Cells)
            {
                int rowStartIndex    = cellInfo.Row;
                int rowEndIndex      = rowStartIndex + cellInfo.RowSpan - 1;
                int columnStartIndex = cellInfo.Column;
                int columnEndIndex   = columnStartIndex + cellInfo.ColumnSpan - 1;

                CellSelection cellSelection = worksheet.Cells[rowStartIndex, columnStartIndex];

                var value = cellInfo.Value;
                if (value != null)
                {
                    cellSelection.SetValue(Convert.ToString(value));
                    cellSelection.SetVerticalAlignment(RadVerticalAlignment.Center);
                    cellSelection.SetHorizontalAlignment(GetHorizontalAlignment(cellInfo.TextAlignment));
                    int indent = cellInfo.Indent;
                    if (indent > 0)
                    {
                        cellSelection.SetIndent(indent);
                    }
                }

                cellSelection = worksheet.Cells[rowStartIndex, columnStartIndex, rowEndIndex, columnEndIndex];

                SetCellProperties(cellInfo, cellSelection);
            }

            for (int i = 0; i < columnCount; i++)
            {
                var columnSelection = worksheet.Columns[i];
                columnSelection.AutoFitWidth();

                //NOTE: workaround for incorrect autofit.
                var newWidth = worksheet.Columns[i].GetWidth().Value.Value + 15;
                columnSelection.SetWidth(new ColumnWidth(newWidth, false));
            }

            workbook.ResumeLayoutUpdate();
            return(workbook);
        }
Beispiel #2
0
        private void SetDocumentTitle()
        {
            CellSelection companyNameCells = worksheet.Cells[1, 1, 1, 4];

            companyNameCells.Merge();
            companyNameCells.SetValue("My Company");
            companyNameCells.SetHorizontalAlignment(RadHorizontalAlignment.Left);

            CellSelection expenseReportCells = worksheet.Cells[2, 1, 2, 4];

            expenseReportCells.Merge();
            expenseReportCells.SetValue("Expense Report");
            expenseReportCells.SetHorizontalAlignment(RadHorizontalAlignment.Right);

            CellSelection periodCells = worksheet.Cells[3, 1, 3, 4];

            periodCells.Merge();
            periodCells.SetValue("1 Jan 2014 - 31 Mar 2014");
            periodCells.SetHorizontalAlignment(RadHorizontalAlignment.Right);
        }