Exemple #1
0
 /**
  * Adds a new FormatBase to the available formats.
  * 
  * The value that will be passed to the FormatBase's FormatBase method (specified
  * by <c>java.text.FormatBase#FormatBase</c>) will be a double value from a
  * numeric cell. Therefore the code in the FormatBase method should expect a
  * <c>Number</c> value.
  * 
  * @param excelformatStr The data FormatBase string
  * @param FormatBase A FormatBase instance
  */
 public void AddFormat(String excelformatStr, FormatBase format)
 {
     formats[excelformatStr] = format;
 }
Exemple #2
0
 /**
  * 
  * Sets a default number FormatBase to be used when the Excel FormatBase cannot be
  * Parsed successfully. <b>Note:</b> This is a fall back for when an error
  * occurs while parsing an Excel number FormatBase pattern. This will not
  * affect cells with the <em>General</em> FormatBase.
  * 
  * 
  * The value that will be passed to the FormatBase's FormatBase method (specified
  * by <c>java.text.FormatBase#FormatBase</c>) will be a double value from a
  * numeric cell. Therefore the code in the FormatBase method should expect a
  * <c>Number</c> value.
  * 
  *
  * @param FormatBase A FormatBase instance to be used as a default
  * @see java.text.FormatBase#FormatBase
  */
 public void SetDefaultNumberFormat(FormatBase format)
 {
     IEnumerator itr = formats.Keys.GetEnumerator();
     while (itr.MoveNext())
     {
         string key = (string)itr.Current;
         if (formats[key] == generalDecimalNumFormat
                 || formats[key] == generalWholeNumFormat)
         {
             formats[key] = format;
         }
     }
     defaultNumFormat = format;
 }
Exemple #3
0
 /**
  * Creates a new date formatter with the given specification.
  *
  * @param format The format.
  */
 public CellDateFormatter(String format)
     : base(format)
 {
     DatePartHandler partHandler = new DatePartHandler(this);
     StringBuilder descBuf = CellFormatPart.ParseFormat(format,
             CellFormatType.DATE, partHandler);
     partHandler.Finish(descBuf);
     dateFmt = new SimpleDateFormat(descBuf.ToString());
 }
Exemple #4
0
    /**
 * Performs Excel-style date formatting, using the
 *  supplied Date and format
 */
    private String PerformDateFormatting(DateTime d, FormatBase dateFormat)
    {
        if (dateFormat != null)
        {
            return dateFormat.Format(d);
        }
        return d.ToString();
    }
Exemple #5
0
 /**
  * Creates a new date formatter with the given specification.
  *
  * @param format The format.
  */
 public CellDateFormatter(String format)
     : base(format)
 {
     DatePartHandler partHandler = new DatePartHandler(this);
     StringBuilder descBuf = CellFormatPart.ParseFormat(format,
             CellFormatType.DATE, partHandler);
     partHandler.Finish(descBuf);
     dateFmt = new SimpleDateFormat(descBuf.ToString());
     
     //NPOI do not need this
     // tweak the format pattern to pass tests on JDK 1.7,
     // See https://issues.apache.org/bugzilla/show_bug.cgi?id=53369
     //String ptrn = descBuf.toString().replaceAll("((y)(?!y))(?<!yy)", "yy");
     //dateFmt = new SimpleDateFormat(ptrn, LOCALE);
 }