Beispiel #1
0
        /**
         * @param dateFormat pass <code>null</code> for default YYYYMMDD
         * @return <code>null</code> if timeStr is <code>null</code>
         */
        private static Double ConvertDate(String dateStr, SimpleDateFormat dateFormat)
        {
            if (dateStr == null)
            {
                return(Double.NaN);
            }
            DateTime dateVal;

            if (dateFormat == null)
            {
                dateVal = HSSFDateUtil.ParseYYYYMMDDDate(dateStr);
            }
            else
            {
                try
                {
                    dateVal = DateTime.Parse(dateStr, CultureInfo.CurrentCulture);
                }
                catch (FormatException e)
                {
                    throw new InvalidOperationException("Failed to parse date '" + dateStr
                                                        + "' using specified format '" + dateFormat + "'", e);
                }
            }
            return(HSSFDateUtil.GetExcelDate(dateVal));
        }
Beispiel #2
0
 /**
  * @return <code>null</code> if timeStr is <code>null</code>
  */
 private static Double ConvertTime(String timeStr)
 {
     if (timeStr == null)
     {
         return(Double.NaN);
     }
     return(HSSFDateUtil.ConvertTime(timeStr));
 }
Beispiel #3
0
        /// <summary>
        /// Check if a cell Contains a date, Checking only for internal
        /// excel date formats.
        /// As Excel stores a great many of its dates in "non-internal"
        /// date formats, you will not normally want to use this method.
        /// </summary>
        /// <param name="cell">The cell.</param>
        /// <returns>
        ///     <c>true</c> if [is cell internal date formatted] [the specified cell]; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsCellInternalDateFormatted(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;
                bDate = IsInternalDateFormat(i);
            }
            return(bDate);
        }
Beispiel #4
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);
        }