Ejemplo n.º 1
0
        ///<summary>
        /// Add an IEnumerable of data start from cell
        ///</summary>
        ///<param name="sheet">Current worksheet</param>
        ///<param name="excelRange">Starting from cell</param>
        ///<param name="direction">Insert direction</param>
        ///<param name="values">IEnumberable of data</param>
        ///<typeparam name="TValue">Type</typeparam>
        ///<returns>The excelrange with start and ending range</returns>
        /// <example>
        /// // get worksheet
        /// var sheet = package.Workbook.Worksheets["Sheet1"];
        /// // get
        /// </example>
        public static ExcelRange Add <TValue>(this ExcelWorksheet sheet, ExcelRange excelRange, InsertDirection direction, IEnumerable <TValue> values)
        {
            var        rowNumber    = excelRange._fromRow;
            var        columnNumber = excelRange._fromCol;
            ExcelRange endCell      = excelRange;

            foreach (var value in values)
            {
                var cell = sheet.GetCell(rowNumber, columnNumber);
                cell.SetValue(value);
                endCell = cell;
                if (direction == InsertDirection.Across)
                {
                    columnNumber++;
                }
                else
                {
                    rowNumber++;
                }
            }
            return(sheet.GetCell(excelRange._fromRow, excelRange._toCol, endCell._fromRow, endCell._toCol));
        }