Esempio n. 1
0
        /// <summary>
        /// Writes the values in an Excel sheet.
        /// </summary>
        /// <param name="target">Excel address, worksheet, range or null to create a new sheet.</param>
        /// <param name="clearFirst">Optional - If true, clears the cells first</param>
        public void ToExcel(object target = null, bool clearFirst = false)
        {
            IRange rg = ExcelExt.GetRange(target);

            if (clearFirst)
            {
                rg[rg.SpecialCells(XlCellType.xlCellTypeLastCell).Row, 1].Clear();
            }

            if (_count == 0)
            {
                return;
            }

            var values = new object[_count, 2];

            int i = 0;

            for (DictionaryItem node = _head; node != null; node = node.next, i++)
            {
                values[i, 0] = node.key;
                values[i, 1] = node.value;
            }

            rg[_count, 2].Value2 = values;
        }
Esempio n. 2
0
        /// <summary>
        ///  Copies the values to Excel. The target can be an address, a worksheet or a range.
        /// </summary>
        /// <param name="target">Excel address, worksheet or range or null to create a new sheet</param>
        /// <param name="clearFirst">Optional - If true, clears the cells first</param>
        public void ToExcel(object target = null, bool clearFirst = false)
        {
            IRange range = ExcelExt.GetRange(target);

            if (clearFirst)
            {
                var lastCell = range.SpecialCells(XlCellType.xlCellTypeLastCell);
                range[lastCell.Row, lastCell.Column].Clear();
            }
            var values = this.Values();
            var rlen   = values.GetLength(0);
            var clen   = values.GetLength(1);

            range[rlen, clen].Value2 = values;
        }
Esempio n. 3
0
        /// <summary>
        /// Copies the values to Excel. The target can be an address, a worksheet or a range.
        /// </summary>
        /// <param name="target">Excel address, worksheet, range or null to create a new sheet.</param>
        /// <param name="title">Optional - Adds a title</param>
        /// <param name="clearFirst">Optional - If true, clears the cells first</param>
        /// <returns>Range</returns>
        /// <example>
        /// Dim lst As New List
        /// lst.Add 43
        /// lst.ToExcel [Sheet1!A1]
        /// </example>
        public IRange ToExcel(object target = null, string title = null, bool clearFirst = false)
        {
            IRange rg = ExcelExt.GetRange(target);

            if (clearFirst)
            {
                rg[rg.SpecialCells(XlCellType.xlCellTypeLastCell).Row, 1].Clear();
            }

            if (_count == 0)
            {
                return(rg);
            }

            object[,] values;
            if (title == null)
            {
                values = new object[_count, 1];
                for (int i = 0; i < _count; i++)
                {
                    values[i, 0] = _items[i];
                }
            }
            else
            {
                _count++;
                values       = new object[_count, 1];
                values[0, 0] = title;
                for (int i = 1; i < _count; i++)
                {
                    values[i, 0] = _items[i - 1];
                }
            }

            rg        = rg[_count, 1]; //Resize range
            rg.Value2 = values;
            return(rg);
        }