示例#1
0
        private void btnExportToExcel_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                HandleErrorInUI(); //clear the error from the UI

                var disableControls = ActionExtensions.Create(() =>
                {
                    btnExportToExcel.IsEnabled = false;
                    btnSearch.IsEnabled        = false;
                    btnExportToExcel.Content   = "Exporting..";
                });

                var enableControls1 = ActionExtensions.Create(() => Dispatcher.Invoke(() =>
                {
                    btnSearch.IsEnabled = true;
                }));

                var enableControls2 = ActionExtensions.Create(() => Dispatcher.Invoke(() =>
                {
                    btnExportToExcel.IsEnabled = true;
                    btnExportToExcel.Content   = "Export to Excel";
                }));

                disableControls();

                UIController.ExportToExcel(enableControls1, enableControls2);
            }
            catch (Exception ex)
            {
                HandleErrorInUI(ex);
            }
        }
示例#2
0
        private void InitializeHeaders()
        {
            //Reference:
            //  B : SL No
            //  C : Changeset Id
            //  D : Commiter
            //  E : Check in Date
            //  F : Comment
            //  G : WorkItem Ids

            _xRange = _xlWorkSheet.Range["B:B", Type.Missing];
            _xRange.Columns.ColumnWidth = 10;
            _xRange.Columns.Cells.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;

            _xRange = _xlWorkSheet.Range["C:C", Type.Missing];
            _xRange.Columns.ColumnWidth = 15;
            _xRange.Columns.Cells.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;

            _xRange = _xlWorkSheet.Range["D:D", Type.Missing];
            _xRange.Columns.ColumnWidth = 25;

            _xRange = _xlWorkSheet.Range["E:E", Type.Missing];
            _xRange.Columns.ColumnWidth = 40;

            _xRange = _xlWorkSheet.Range["F:F", Type.Missing];
            _xRange.Columns.ColumnWidth = 100;
            _xRange.Columns.WrapText    = true;

            _xRange = _xlWorkSheet.Range["G:G", Type.Missing];
            _xRange.Columns.ColumnWidth = 15;
            _xRange.Columns.Cells.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;

            var includeCol = FuncExtensions.Create((string col) => string.Format("{0}{1}", col, HeaderRow));

            var headerColumns = new[] { includeCol("B"), includeCol("C"), includeCol("D"), includeCol("E"), includeCol("F"), includeCol("G") };

            var applyFormatToHeader = ActionExtensions.Create((string col) =>
            {
                _xRange = _xlWorkSheet.Range[col, Type.Missing];
                if (_xRange == null)
                {
                    return;
                }
                _xRange.Font.Color     = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);
                _xRange.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
            });

            headerColumns.Iterate(applyFormatToHeader);

            _xlWorkSheet.Cells[HeaderRow, 2] = "SL No";
            _xlWorkSheet.Cells[HeaderRow, 3] = "Id";
            _xlWorkSheet.Cells[HeaderRow, 4] = "Committer";
            _xlWorkSheet.Cells[HeaderRow, 5] = "Check-in Date";
            _xlWorkSheet.Cells[HeaderRow, 6] = "Comment";
            _xlWorkSheet.Cells[HeaderRow, 7] = "Work Item Ids";
        }