Exemple #1
0
        /// <summary>
        /// Clones all the style information from another
        /// HSSFCellStyle, onto this one. This
        /// HSSFCellStyle will then have all the same
        /// properties as the source, but the two may
        /// be edited independently.
        /// Any stylings on this HSSFCellStyle will be lost!
        /// The source HSSFCellStyle could be from another
        /// HSSFWorkbook if you like. This allows you to
        /// copy styles from one HSSFWorkbook to another.
        /// </summary>
        /// <param name="source">The source.</param>
        public void CloneStyleFrom(HSSFCellStyle source)
        {
            // First we need to clone the extended format
            //  record
            _format.CloneStyleFrom(source._format);

            // Handle matching things if we cross workbooks
            if (_workbook != source._workbook)
            {
                lastDateFormat           = short.MinValue;
                lastFormats              = null;
                getDataFormatStringCache = null;
                // Then we need to clone the format string,
                //  and update the format record for this
                short fmt = (short)_workbook.CreateFormat(
                    source.GetDataFormatString()
                    );
                this.DataFormat = (fmt);

                // Finally we need to clone the font,
                //  and update the format record for this
                FontRecord fr = _workbook.CreateNewFont();
                fr.CloneStyleFrom(
                    source._workbook.GetFontRecordAt(
                        source.FontIndex
                        )
                    );

                HSSFFont font = new HSSFFont(
                    (short)_workbook.GetFontIndex(fr), fr
                    );
                this.SetFont(font);
            }
        }
Exemple #2
0
        /// <summary>
        /// Check if a cell Contains a date
        /// Since dates are stored internally in Excel as double values
        /// we infer it Is a date if it Is formatted as such.
        /// </summary>
        /// <param name="cell">The cell.</param>
        /// <returns>
        ///     <c>true</c> if [is cell date formatted] [the specified cell]; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsCellDateFormatted(HSSFCell cell)
        {
            if (cell == null)
            {
                return(false);
            }
            bool bDate = false;

            double d = cell.NumericCellValue;

            if (HSSFDateUtil.IsValidExcelDate(d))
            {
                HSSFCellStyle style = cell.CellStyle;
                int           i     = style.DataFormat;
                String        f     = style.GetDataFormatString(cell.BoundWorkbook);
                bDate = IsADateFormat(i, f);
            }
            return(bDate);
        }
        /// <summary>
        /// Clones all the style information from another
        /// HSSFCellStyle, onto this one. This
        /// HSSFCellStyle will then have all the same
        /// properties as the source, but the two may
        /// be edited independently.
        /// Any stylings on this HSSFCellStyle will be lost!
        /// The source HSSFCellStyle could be from another
        /// HSSFWorkbook if you like. This allows you to
        /// copy styles from one HSSFWorkbook to another.
        /// </summary>
        /// <param name="source">The source.</param>
        public void CloneStyleFrom(HSSFCellStyle source)
        {
            // First we need to clone the extended format
            //  record
            format.CloneStyleFrom(source.format);

            // Handle matching things if we cross workbooks
            if (workbook != source.workbook)
            {
                // Then we need to clone the format string,
                //  and update the format record for this
                short fmt = workbook.CreateFormat(
                        source.GetDataFormatString()
                );
                this.DataFormat=(fmt);

                // Finally we need to clone the font,
                //  and update the format record for this
                FontRecord fr = workbook.CreateNewFont();
                fr.CloneStyleFrom(
                        source.workbook.GetFontRecordAt(
                                source.FontIndex
                        )
                );

                HSSFFont font = new HSSFFont(
                        (short)workbook.GetFontIndex(fr), fr
                );
                this.SetFont(font);
            }
        }