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); }