/// <summary> Standard equals method. This compares the contents of two /// format records, and not their indexCodes, which are ignored /// /// </summary> /// <param name="o">the object to compare /// </param> /// <returns> TRUE if the two objects are equal, FALSE otherwise /// </returns> public override bool Equals(System.Object o) { if (o == this) { return(true); } if (!(o is FormatRecord)) { return(false); } FormatRecord fr = (FormatRecord)o; // Not interested in uninitialized comparisons if (!initialized || !fr.initialized) { return(false); } // Must be either a number or a date format if (date != fr.date || number != fr.number) { return(false); } return(formatString.Equals(fr.formatString)); }
/// <summary> Copy constructor - can be invoked by public access /// /// </summary> /// <param name="fr">the format to copy /// </param> protected internal FormatRecord(FormatRecord fr) : base(NExcel.Biff.Type.FORMAT) { initialized = false; formatString = fr.formatString; date = fr.date; number = fr.number; // format = (java.text.Format) fr.format.clone(); }
/// <summary> Sees if the extended formatting record at the specified position /// represents a date. First checks against the built in formats, and /// then checks against the hash map of FormatRecords /// /// </summary> /// <param name="pos">the xf format index /// </param> /// <returns> TRUE if this format index is formatted as a Date /// </returns> public bool isDate(int pos) { XFRecord xfr = (XFRecord)xfRecords[pos]; if (xfr.isDate()) { return(true); } FormatRecord fr = (FormatRecord)formats[xfr.FormatRecord]; return(fr == null?false:fr.Date); }
/// <summary> Gets the NumberFormatInfo used to format the cell. /// /// </summary> /// <param name="pos">the xf format index /// </param> /// <returns> the DateFormat object used to format the date in the original /// excel cell /// </returns> public NumberFormatInfo getNumberFormat(int pos) { XFRecord xfr = (XFRecord)xfRecords[pos]; if (xfr.isNumber()) { return(xfr.NumberFormat); } FormatRecord fr = (FormatRecord)formats[xfr.FormatRecord]; if (fr == null) { return(null); } return(fr.Number?fr.NumberFormat:null); }
/// <summary> Gets the DateFormat used to format the cell. /// /// </summary> /// <param name="pos">the xf format index /// </param> /// <returns> the DateFormat object used to format the date in the original /// excel cell /// </returns> public DateTimeFormatInfo getDateFormat(int pos) { XFRecord xfr = (XFRecord)xfRecords[pos]; if (xfr.isDate()) { return(xfr.DateFormat); } FormatRecord fr = (FormatRecord)formats[xfr.FormatRecord]; if (fr == null) { return(null); } return(fr.Date?fr.DateFormat:null); }
/// <summary> A public copy constructor which can be used for copy formats between /// different sheets. Unlike the the other copy constructor, this /// version does a deep copy /// /// </summary> /// <param name="cellFormat">the format to copy /// </param> protected internal XFRecord(CellFormat cellFormat) : base(NExcel.Biff.Type.XF) { Assert.verify(cellFormat is XFRecord); XFRecord fmt = (XFRecord)cellFormat; if (!fmt.formatInfoInitialized) { fmt.initializeFormatInformation(); } locked = fmt.locked; hidden = fmt.hidden; align = fmt.align; valign = fmt.valign; orientation = fmt.orientation; wrap = fmt.wrap; leftBorder = fmt.leftBorder; rightBorder = fmt.rightBorder; topBorder = fmt.topBorder; bottomBorder = fmt.bottomBorder; leftBorderColour = fmt.leftBorderColour; rightBorderColour = fmt.rightBorderColour; topBorderColour = fmt.topBorderColour; bottomBorderColour = fmt.bottomBorderColour; pattern = fmt.pattern; xfFormatType = fmt.xfFormatType; parentFormat = fmt.parentFormat; shrinkToFit = fmt.shrinkToFit; backgroundColour = fmt.backgroundColour; // Deep copy of the font font = new FontRecord(fmt.Font); // Copy the format if (fmt.Format == null) { // format is writable if (fmt.format.isBuiltIn()) { format = fmt.format; } else { // Format is not built in, so do a deep copy format = new FormatRecord((FormatRecord)fmt.format); } } else if (fmt.Format is BuiltInFormat) { // read excel format is built in excelFormat = (BuiltInFormat)fmt.excelFormat; format = (BuiltInFormat)fmt.excelFormat; } else { // read excel format is user defined Assert.verify(fmt.formatInfoInitialized); // in this case FormattingRecords should initialize the excelFormat // field with an instance of FormatRecord Assert.verify(fmt.excelFormat is FormatRecord); // Format is not built in, so do a deep copy FormatRecord fr = new FormatRecord((FormatRecord)fmt.excelFormat); // Set both format fields to be the same object, since // FormatRecord implements all the necessary interfaces excelFormat = fr; format = fr; } biffType = biff8; // The format info should be all OK by virtue of the deep copy formatInfoInitialized = true; // This format was not read in read = false; // Treat this as a new cell record, so set the copied flag to false copied = false; // The font or format indexes need to be set, so set initialized to false initialized = false; }