private static void AbortIfPathIsEmptyAndSaveIsRequired(string path, PostCreationActions postCreationAction)
        {
            switch (postCreationAction)
            {
            case PostCreationActions.SaveAndView:
            case PostCreationActions.SaveAndClose:
                if (string.IsNullOrEmpty(path))
                {
                    throw new ArgumentException($"The {nameof(path)} cannot be null or empty if the file is to be saved.", nameof(path));
                }

                break;

            case PostCreationActions.Open:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(postCreationAction), postCreationAction, null);
            }
        }
        private static void ExecutePostCreationActions(Application app, PostCreationActions postCreationAction, string path)
        {
            switch (postCreationAction)
            {
            case PostCreationActions.Open:
                app.Visible = true;
                break;

            case PostCreationActions.SaveAndView:
                app.ActiveWorkbook.SaveAs(path);
                app.Visible = true;
                break;

            case PostCreationActions.SaveAndClose:
                app.ActiveWorkbook.SaveAs(path);
                app.Quit();
                app.Dispose();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(postCreationAction), postCreationAction, null);
            }
        }
 /// <summary>
 /// Evaluates, expands and exports an <see cref="IEnumerable{T}"/> into Excel. If <see cref="T"/> is a complex type,
 /// all properties and fields are exported into columns. If <see cref="T"/> is a simple type, the data is exported into a
 /// single column.
 /// </summary>
 /// <typeparam name="T">A generic type which is contained within the IEnumerable.</typeparam>
 /// <param name="input">An <see cref="IEnumerable{T}"/> which will be evaluated, expanded and exported into Excel.</param>
 /// <param name="postCreationAction">Determines whether the Excel file will be opened with the data, opened and saved or just saved.</param>
 /// <param name="path">If the path parameter determines where the Excel file will be saved to if a save action is selected from the <see cref="PostCreationActions"/>.</param>
 public static void ToExcel <T>(this IEnumerable <T> input, PostCreationActions postCreationAction, string path)
 {
     ExcelOutputItem.CreateInstance(input, postCreationAction, path).ToExcel();
 }
 /// <summary>
 /// Evaluates, expands and exports an <see cref="IEnumerable"/> of type <see cref="type"/> into Excel. If <see cref="type"/> is a complex type,
 /// all properties and fields are exported into columns. If <see cref="type"/> is a simple type, the data is exported into a
 /// single column.
 /// </summary>
 /// <param name="input">An <see cref="IEnumerable"/> which will be evaluated, expanded and exported into Excel.</param>
 /// <param name="type">The type of the objects contained within the IEnumerable in <see cref="input"/>.</param>
 /// <param name="trim">A parameter which determines whether strings should be trimmed before being written to Excel.</param>
 /// <param name="postCreationAction">Determines whether the Excel file will be opened with the data, opened and saved or just saved.</param>
 /// <param name="path">If the path parameter determines where the Excel file will be saved to if a save action is selected from the <see cref="PostCreationActions"/>.</param>
 /// <param name="worksheetName">The name given to the newly generated worksheet.</param>
 public static void ToExcel(IEnumerable input, Type type, string worksheetName, bool trim, PostCreationActions postCreationAction, string path)
 {
     ExcelOutputItem.CreateInstance(input, type, worksheetName, trim, postCreationAction, path).ToExcel();
 }
 /// <summary>
 /// Evaluates, expands and exports an <see cref="IEnumerable{T}"/> into Excel. If <see cref="T"/> is a complex type,
 /// all properties and fields are exported into columns. If <see cref="T"/> is a simple type, the data is exported into a
 /// single column.
 /// </summary>
 /// <typeparam name="T">A generic type which is contained within the IEnumerable.</typeparam>
 /// <param name="input">An <see cref="IEnumerable{T}"/> which will be evaluated, expanded and exported into Excel.</param>
 /// <param name="trim">A parameter which determines whether strings should be trimmed before being written to Excel.</param>
 /// <param name="postCreationAction">Determines whether the Excel file will be opened with the data, opened and saved or just saved.</param>
 /// <param name="path">If the path parameter determines where the Excel file will be saved to if a save action is selected from the <see cref="PostCreationActions"/>.</param>
 /// <param name="worksheetName">The name given to the newly generated worksheet.</param>
 public static void ToExcel <T>(this IEnumerable <T> input, string worksheetName, bool trim, PostCreationActions postCreationAction, string path)
 {
     ExcelOutputItem.CreateInstance(input, worksheetName, trim, postCreationAction, path).ToExcel();
 }
 /// <summary>
 /// Instantiate an instance of the ExcelOutputCollection
 /// This collection allows for the creation of multiple sheets within a single Workbook.
 /// <param name="postCreationAction">Determines whether the Excel file will be opened with the data, opened and saved or just saved.</param>
 /// <param name="path">If the path parameter determines where the Excel file will be saved to if a save action is selected from the <see cref="PostCreationActions"/>.</param>
 /// </summary>
 public ExcelOutputCollection(PostCreationActions postCreationAction, string path)
 {
     this.collection         = new Collection <ExcelOutputItem>();
     this.PostCreationAction = postCreationAction;
     this.Path = path;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Instantiate an instance of the ExcelOutputItem with a particular <see cref="IEnumerable"/> collection.
 /// This object allows for the creation of a single sheet, or when used in conjunction with <see cref="ExcelOutputCollection"/>,
 /// the creation of multiple sheets within a single Workbook.
 /// <param name="enumerable">An enumerable of type <param name="type"/> which contains data to be exported to Excel.</param>
 /// <param name="type">A type which is contained within the IEnumerable.</param>
 /// <param name="postCreationAction">Determines whether the Excel file will be opened with the data, opened and saved or just saved.</param>
 /// <param name="path">If the path parameter determines where the Excel file will be saved to if a save action is selected from the <see cref="PostCreationActions"/>.</param>
 /// </summary>
 public static ExcelOutputItem CreateInstance(IEnumerable enumerable, Type type, PostCreationActions postCreationAction, string path)
 {
     return(CreateInstance(enumerable, type, "Data", true, postCreationAction, path));
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Instantiate an instance of the ExcelOutputItem with a particular <see cref="IEnumerable"/> collection.
        /// This object allows for the creation of a single sheet, or when used in conjunction with <see cref="ExcelOutputCollection"/>,
        /// the creation of multiple sheets within a single Workbook.
        /// <param name="enumerable">An enumerable of type <param name="type"/> which contains data to be exported to Excel.</param>
        /// <param name="type">A type which is contained within the IEnumerable.</param>
        /// <param name="worksheetName">The name given to the newly generated worksheet.</param>
        /// <param name="trim">A parameter which determines whether strings should be trimmed before being written to Excel.</param>
        /// <param name="postCreationAction">Determines whether the Excel file will be opened with the data, opened and saved or just saved.</param>
        /// <param name="path">If the path parameter determines where the Excel file will be saved to if a save action is selected from the <see cref="PostCreationActions"/>.</param>
        /// </summary>
        public static ExcelOutputItem CreateInstance(IEnumerable enumerable, Type type, string worksheetName, bool trim, PostCreationActions postCreationAction, string path)
        {
            var excelOutputItem = new ExcelOutputItem
            {
                Enumerable          = enumerable,
                Type                = type,
                WorksheetName       = worksheetName,
                Trim                = trim,
                PostCreationActions = postCreationAction,
                Path                = path,
            };

            return(excelOutputItem);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Instantiate an instance of the ExcelOutputItem with a particular <see cref="IEnumerable{T}"/> collection.
 /// This object allows for the creation of a single sheet, or when used in conjunction with <see cref="ExcelOutputCollection"/>,
 /// the creation of multiple sheets within a single Workbook.
 /// <typeparam name="T">A generic type which is contained within the IEnumerable.</typeparam>
 /// <param name="enumerable">An enumerable of type <typeparam name="T"/> which contains data to be exported to Excel.</param>
 /// <param name="worksheetName">The name given to the newly generated worksheet.</param>
 /// <param name="trim">A parameter which determines whether strings should be trimmed before being written to Excel.</param>
 /// <param name="postCreationAction">Determines whether the Excel file will be opened with the data, opened and saved or just saved.</param>
 /// <param name="path">If the path parameter determines where the Excel file will be saved to if a save action is selected from the <see cref="PostCreationActions"/>.</param>
 /// </summary>
 public static ExcelOutputItem CreateInstance <T>(IEnumerable <T> enumerable, string worksheetName, bool trim, PostCreationActions postCreationAction, string path)
 {
     return(CreateInstance(enumerable, typeof(T), worksheetName, trim, postCreationAction, path));
 }