/** * Formats the given numeric of date Cell's contents * as a String, in as close as we can to the way * that Excel would do so. * Uses the various format records to manage this. * * TODO - move this to a central class in such a * way that hssf.usermodel can make use of it too */ public String FormatNumberDateCell(CellValueRecordInterface cell) { double value; if (cell is NumberRecord) { value = ((NumberRecord)cell).Value; } else if (cell is FormulaRecord) { value = ((FormulaRecord)cell).Value; } else { throw new ArgumentException("Unsupported CellValue Record passed in " + cell); } // Get the built in format, if there is one int formatIndex = GetFormatIndex(cell); String formatString = GetFormatString(cell); if (formatString == null) { return value.ToString(); } else { // Format, using the nice new // HSSFDataFormatter to do the work for us return formatter.FormatRawCellContents(value, formatIndex, formatString); } }
public void InsertCell(CellValueRecordInterface cell) { int column = cell.Column; int row = cell.Row; if (row >= records.Length) { CellValueRecordInterface[][] oldRecords = records; int newSize = oldRecords.Length * 2; if (newSize < row + 1) newSize = row + 1; records = new CellValueRecordInterface[newSize][]; Array.Copy(oldRecords, 0, records, 0, oldRecords.Length); } object objRowCells = records[row]; if (objRowCells == null) { int newSize = column + 1; if (newSize < 10) newSize = 10; objRowCells = new CellValueRecordInterface[newSize]; records[row] = (CellValueRecordInterface[])objRowCells; } CellValueRecordInterface[] rowCells = (CellValueRecordInterface[])objRowCells; if (column >= rowCells.Length) { CellValueRecordInterface[] oldRowCells = rowCells; int newSize = oldRowCells.Length * 2; if (newSize < column + 1) newSize = column + 1; // if(newSize>257) newSize=257; // activate? rowCells = new CellValueRecordInterface[newSize]; Array.Copy(oldRowCells, 0, rowCells, 0, oldRowCells.Length); records[row] = rowCells; } rowCells[column] = cell; if ((column < firstcell) || (firstcell == -1)) { firstcell = column; } if ((column > lastcell) || (lastcell == -1)) { lastcell = column; } }
/// <summary> /// Formats a number or date cell, be that a real number, or the /// answer to a formula /// </summary> /// <param name="cell">The cell.</param> /// <param name="value">The value.</param> /// <returns></returns> private String FormatNumberDateCell(CellValueRecordInterface cell, double value) { // Get the built in format, if there is one int formatIndex = ft.GetFormatIndex(cell); String formatString = ft.GetFormatString(cell); if (formatString == null) { return(value.ToString(CultureInfo.InvariantCulture)); } else { // Is it a date? if (Npoi.Core.SS.UserModel.DateUtil.IsADateFormat(formatIndex, formatString) && Npoi.Core.SS.UserModel.DateUtil.IsValidExcelDate(value)) { // Java wants M not m for month formatString = formatString.Replace('m', 'M'); // Change \- into -, if it's there formatString = formatString.Replace("\\\\-", "-"); // Format as a date DateTime d = Npoi.Core.SS.UserModel.DateUtil.GetJavaDate(value, false); SimpleDateFormat df = new SimpleDateFormat(formatString); return(df.Format(d, CultureInfo.CurrentCulture)); } else { if (formatString == "General") { // Some sort of wierd default return(value.ToString(CultureInfo.InvariantCulture)); } // Format as a number DecimalFormat df = new DecimalFormat(formatString); return(df.Format(value, CultureInfo.CurrentCulture)); } } }
public CellValueRecordInterface[] GetValueRecords() { ArrayList temp = new ArrayList(); for (int i = 0; i < records.Length; i++) { CellValueRecordInterface[] rowCells = records[i]; if (rowCells == null) { continue; } for (int j = 0; j < rowCells.Length; j++) { CellValueRecordInterface cell = rowCells[j]; if (cell != null) { temp.Add(cell); } } } return((CellValueRecordInterface[])temp.ToArray(typeof(CellValueRecordInterface))); }
public void Construct(CellValueRecordInterface rec, RecordStream rs, SharedValueManager sfh) { if (rec is FormulaRecord) { FormulaRecord formulaRec = (FormulaRecord)rec; // read optional cached text value StringRecord cachedText = null; Type nextClass = rs.PeekNextClass(); if (nextClass == typeof(StringRecord)) { cachedText = (StringRecord)rs.GetNext(); } else { cachedText = null; } InsertCell(new FormulaRecordAggregate(formulaRec, cachedText, sfh)); } else { InsertCell(rec); } }
/** * used internally -- given a cell value record, figure out its type */ private CellType DetermineType(CellValueRecordInterface cval) { if (cval is FormulaRecordAggregate) { return(CellType.Formula); } Record record = (Record)cval; int sid = record.Sid; switch (sid) { case NumberRecord.sid: return(CellType.Numeric); case BlankRecord.sid: return(CellType.Blank); case LabelSSTRecord.sid: return(CellType.String); case FormulaRecordAggregate.sid: return(CellType.Formula); case BoolErrRecord.sid: BoolErrRecord boolErrRecord = (BoolErrRecord)record; return((boolErrRecord.IsBoolean) ? CellType.Boolean : CellType.Error); } throw new Exception("Bad cell value rec (" + cval.GetType().Name + ")"); }
/// <summary> /// Creates an Cell from a CellValueRecordInterface. HSSFSheet uses this when /// reading in cells from an existing sheet. /// </summary> /// <param name="book">Workbook record of the workbook containing this cell</param> /// <param name="sheet">Sheet record of the sheet containing this cell</param> /// <param name="cval">the Cell Value Record we wish to represent</param> public HSSFCell(HSSFWorkbook book, HSSFSheet sheet, CellValueRecordInterface cval) { _record = cval; cellType = DetermineType(cval); stringValue = null; this.book = book; this._sheet = sheet; switch (cellType) { case CellType.String: stringValue = new HSSFRichTextString(book.Workbook, (LabelSSTRecord)cval); break; case CellType.Blank: break; case CellType.Formula: stringValue = new HSSFRichTextString(((FormulaRecordAggregate)cval).StringValue); break; } //ExtendedFormatRecord xf = book.Workbook.GetExFormatAt(cval.XFIndex); //CellStyle = new HSSFCellStyle((short)cval.XFIndex, xf, book); }
public void UpdateFormulasAfterRowShift(FormulaShifter shifter, int currentExternSheetIndex) { for (int i = 0; i < records.Length; i++) { CellValueRecordInterface[] rowCells = records[i]; if (rowCells == null) { continue; } for (int j = 0; j < rowCells.Length; j++) { CellValueRecordInterface cell = rowCells[j]; if (cell is FormulaRecordAggregate) { FormulaRecord fr = ((FormulaRecordAggregate)cell).FormulaRecord; Ptg[] ptgs = fr.ParsedExpression; // needs clone() inside this getter? if (shifter.AdjustFormula(ptgs, currentExternSheetIndex)) { fr.ParsedExpression = (ptgs); } } } } }
private ValueRecordsAggregate(int firstCellIx, int lastCellIx, CellValueRecordInterface[][] pRecords) { firstcell = firstCellIx; lastcell = lastCellIx; records = pRecords; }
public CellValueRecordTreeNode(CellValueRecordInterface record) { this.Record = record; this.Text = record.GetType().Name; this.ImageKey = "Binary"; }
public void Construct(CellValueRecordInterface rec, RecordStream rs, SharedValueManager sfh) { if (rec is FormulaRecord) { FormulaRecord formulaRec = (FormulaRecord)rec; // read optional cached text value StringRecord cachedText=null; Type nextClass = rs.PeekNextClass(); if (nextClass == typeof(StringRecord)) { cachedText = (StringRecord)rs.GetNext(); } else { cachedText = null; } InsertCell(new FormulaRecordAggregate(formulaRec, cachedText, sfh)); } else { InsertCell(rec); } }
public MyEnumerator(ref CellValueRecordInterface[][] _records) { this.records = _records; this.nextRow = 0; this.lastRow = _records.Length - 1; //FindNext(); }
/** * Returns the index of the format string, used by your cell, * or -1 if none found */ public int GetFormatIndex(CellValueRecordInterface cell) { ExtendedFormatRecord xfr = (ExtendedFormatRecord) xfRecords[cell.XFIndex]; if (xfr == null) { Console.Error.WriteLine("Cell " + cell.Row + "," + cell.Column + " uses XF with index " + cell.XFIndex + ", but we don't have that"); return -1; } return xfr.FormatIndex; }
public void RemoveCell(CellValueRecordInterface cvRec) { _valuesAgg.RemoveCell(cvRec); }
/// <summary> /// Create a high level Cell object from an existing low level record. Should /// only be called from HSSFSheet or HSSFRow itself. /// </summary> /// <param name="cell">The low level cell to Create the high level representation from</param> /// <returns> the low level record passed in</returns> public Cell CreateCellFromRecord(CellValueRecordInterface cell) { Cell hcell = new HSSFCell(book, sheet, cell); AddCell(hcell); int colIx = cell.Column; if (row.IsEmpty) { row.FirstCol=(colIx); row.LastCol=(colIx + 1); } else { if (colIx < row.FirstCol) { row.FirstCol = (colIx); } else if (colIx > row.LastCol) { row.LastCol = (colIx + 1); } else { // added cell is within first and last cells } } return hcell; }
public void InsertCell(CellValueRecordInterface cvRec) { _valuesAgg.InsertCell(cvRec); }
public bool IsEqual(CellValueRecordInterface i) { return ((this.Row == i.Row) && (this.Column == i.Column)); }
/** * used internally -- given a cell value record, figure out its type */ private CellType DetermineType(CellValueRecordInterface cval) { if (cval is FormulaRecordAggregate) { return CellType.Formula; } Record record = (Record)cval; int sid = record.Sid; switch (sid) { case NumberRecord.sid: return CellType.Numeric; case BlankRecord.sid: return CellType.Blank; case LabelSSTRecord.sid: return CellType.String; case FormulaRecordAggregate.sid: return CellType.Formula; case BoolErrRecord.sid: BoolErrRecord boolErrRecord = (BoolErrRecord)record; return (boolErrRecord.IsBoolean) ? CellType.Boolean : CellType.Error; } throw new Exception("Bad cell value rec (" + cval.GetType().Name + ")"); }
public bool IsAfter(CellValueRecordInterface i) { if (this.Row < i.Row) { return false; } if ((this.Row == i.Row) && (this.Column < i.Column)) { return false; } if ((this.Row == i.Row) && (this.Column == i.Column)) { return false; } return true; }
public bool IsBefore(CellValueRecordInterface i) { if (this.Row > i.Row) { return false; } if ((this.Row == i.Row) && (this.Column > i.Column)) { return false; } if ((this.Row == i.Row) && (this.Column == i.Column)) { return false; } return true; }
/** * Returns the index of the format string, used by your cell, * or -1 if none found */ public int GetFormatIndex(CellValueRecordInterface cell) { ExtendedFormatRecord xfr = (ExtendedFormatRecord) xfRecords[cell.XFIndex]; if (xfr == null) { logger.Log(POILogger.ERROR, "Cell " + cell.Row + "," + cell.Column + " uses XF with index " + cell.XFIndex + ", but we don't have that"); return -1; } return xfr.FormatIndex; }
/** * used internally -- given a cell value record, figure out its type */ private CellType DetermineType(CellValueRecordInterface cval) { if (cval is FormulaRecordAggregate) { return CellType.FORMULA; } Record record = (Record)cval; int sid = record.Sid; switch (sid) { case NumberRecord.sid: return CellType.NUMERIC; case BlankRecord.sid: return CellType.BLANK; case LabelSSTRecord.sid: return CellType.STRING; case FormulaRecordAggregate.sid: return CellType.FORMULA; case BoolErrRecord.sid: BoolErrRecord boolErrRecord = (BoolErrRecord)record; return (boolErrRecord.IsBoolean) ? CellType.BOOLEAN : CellType.ERROR; } throw new Exception("Bad cell value rec (" + cval.GetType().Name + ")"); }
/// <summary> /// Process an HSSF Record. Called when a record occurs in an HSSF file. /// </summary> /// <param name="record"></param> public void ProcessRecord(Record record) { int thisRow; int thisColumn; CellValueRecordInterface[] expandedRecords = null; if (record is CellValueRecordInterface) { CellValueRecordInterface valueRec = (CellValueRecordInterface)record; thisRow = valueRec.Row; thisColumn = valueRec.Column; } else { thisRow = -1; thisColumn = -1; switch (record.Sid) { // the BOFRecord can represent either the beginning of a sheet or the workbook case BOFRecord.sid: BOFRecord bof = (BOFRecord)record; if (bof.Type == BOFRecord.TYPE_WORKBOOK || bof.Type == BOFRecord.TYPE_WORKSHEET) { // Reset the row and column counts - new workbook / worksheet ResetCounts(); } break; case RowRecord.sid: RowRecord rowrec = (RowRecord)record; //Console.WriteLine("Row " + rowrec.RowNumber + " found, first column at " // + rowrec.GetFirstCol() + " last column at " + rowrec.GetLastCol()); // If there's a jump in rows, fire off missing row records if (lastRowRow + 1 < rowrec.RowNumber) { for (int i = (lastRowRow + 1); i < rowrec.RowNumber; i++) { MissingRowDummyRecord dr = new MissingRowDummyRecord(i); childListener.ProcessRecord(dr); } } // Record this as the last row we saw lastRowRow = rowrec.RowNumber; break; case SharedFormulaRecord.sid: // SharedFormulaRecord occurs after the first FormulaRecord of the cell range. // There are probably (but not always) more cell records after this // - so don't fire off the LastCellOfRowDummyRecord yet childListener.ProcessRecord(record); return; case MulBlankRecord.sid: // These appear in the middle of the cell records, to // specify that the next bunch are empty but styled // Expand this out into multiple blank cells MulBlankRecord mbr = (MulBlankRecord)record; expandedRecords = RecordFactory.ConvertBlankRecords(mbr); break; case MulRKRecord.sid: // This is multiple consecutive number cells in one record // Exand this out into multiple regular number cells MulRKRecord mrk = (MulRKRecord)record; expandedRecords = RecordFactory.ConvertRKRecords(mrk); break; case NoteRecord.sid: NoteRecord nrec = (NoteRecord)record; thisRow = nrec.Row; thisColumn = nrec.Column; break; default: //Console.WriteLine(record.GetClass()); break; } } // First part of expanded record handling if (expandedRecords != null && expandedRecords.Length > 0) { thisRow = expandedRecords[0].Row; thisColumn = expandedRecords[0].Column; } // If we're on cells, and this cell isn't in the same // row as the last one, then fire the // dummy end-of-row records if (thisRow != lastCellRow && lastCellRow > -1) { for (int i = lastCellRow; i < thisRow; i++) { int cols = -1; if (i == lastCellRow) { cols = lastCellColumn; } childListener.ProcessRecord(new LastCellOfRowDummyRecord(i, cols)); } } // If we've just finished with the cells, then fire the // final dummy end-of-row record if (lastCellRow != -1 && lastCellColumn != -1 && thisRow == -1) { childListener.ProcessRecord(new LastCellOfRowDummyRecord(lastCellRow, lastCellColumn)); lastCellRow = -1; lastCellColumn = -1; } // If we've moved onto a new row, the ensure we re-set // the column counter if (thisRow != lastCellRow) { lastCellColumn = -1; } // If there's a gap in the cells, then fire // the dummy cell records if (lastCellColumn != thisColumn - 1) { for (int i = lastCellColumn + 1; i < thisColumn; i++) { childListener.ProcessRecord(new MissingCellDummyRecord(thisRow, i)); } } // Next part of expanded record handling if (expandedRecords != null && expandedRecords.Length > 0) { thisColumn = expandedRecords[expandedRecords.Length - 1].Column; } // Update cell and row counts as needed if (thisColumn != -1) { lastCellColumn = thisColumn; lastCellRow = thisRow; } // Pass along the record(s) if (expandedRecords != null && expandedRecords.Length > 0) { foreach (CellValueRecordInterface r in expandedRecords) { childListener.ProcessRecord((Record)r); } } else { childListener.ProcessRecord(record); } }
/** * Returns the format string, eg $##.##, used * by your cell */ public String GetFormatString(CellValueRecordInterface cell) { int formatIndex = GetFormatIndex(cell); if (formatIndex == -1) { // Not found return null; } return GetFormatString(formatIndex); }
public void RemoveCell(CellValueRecordInterface cell) { if (cell == null) { throw new ArgumentException("cell must not be null"); } int row = cell.Row; if (row >= records.Length) { throw new Exception("cell row is out of range"); } CellValueRecordInterface[] rowCells = records[row]; if (rowCells == null) { throw new Exception("cell row is already empty"); } int column = cell.Column; if (column >= rowCells.Length) { throw new Exception("cell column is out of range"); } rowCells[column] = null; }
/// <summary> /// Creates an Cell from a CellValueRecordInterface. HSSFSheet uses this when /// reading in cells from an existing sheet. /// </summary> /// <param name="book">Workbook record of the workbook containing this cell</param> /// <param name="sheet">Sheet record of the sheet containing this cell</param> /// <param name="cval">the Cell Value Record we wish to represent</param> public HSSFCell(HSSFWorkbook book, HSSFSheet sheet, CellValueRecordInterface cval) { record = cval; cellType = DetermineType(cval); stringValue = null; this.book = book; this.sheet = sheet; switch (cellType) { case CellType.STRING: stringValue = new HSSFRichTextString(book.Workbook, (LabelSSTRecord)cval); break; case CellType.BLANK: break; case CellType.FORMULA: stringValue = new HSSFRichTextString(((FormulaRecordAggregate)cval).StringValue); break; } //ExtendedFormatRecord xf = book.Workbook.GetExFormatAt(cval.XFIndex); //CellStyle = new HSSFCellStyle((short)cval.XFIndex, xf, book); }
/// <summary> /// Sets the cell type. The SetValue flag indicates whether to bother about /// trying to preserve the current value in the new record if one is Created. /// The SetCellValue method will call this method with false in SetValue /// since it will overWrite the cell value later /// </summary> /// <param name="cellType">Type of the cell.</param> /// <param name="setValue">if set to <c>true</c> [set value].</param> /// <param name="row">The row.</param> /// <param name="col">The col.</param> /// <param name="styleIndex">Index of the style.</param> private void SetCellType(CellType cellType, bool setValue, int row, int col, short styleIndex) { if (cellType > CellType.Error) { throw new Exception("I have no idea what type that Is!"); } switch (cellType) { case CellType.Formula: FormulaRecordAggregate frec = null; if (cellType != this.cellType) { frec = _sheet.Sheet.RowsAggregate.CreateFormula(row, col); } else { frec = (FormulaRecordAggregate)_record; } frec.Column = col; if (setValue) { frec.FormulaRecord.Value = NumericCellValue; } frec.XFIndex = styleIndex; frec.Row = row; _record = frec; break; case CellType.Numeric: NumberRecord nrec = null; if (cellType != this.cellType) { nrec = new NumberRecord(); } else { nrec = (NumberRecord)_record; } nrec.Column = col; if (setValue) { nrec.Value = NumericCellValue; } nrec.XFIndex = styleIndex; nrec.Row = row; _record = nrec; break; case CellType.String: LabelSSTRecord lrec = null; if (cellType != this.cellType) { lrec = new LabelSSTRecord(); } else { lrec = (LabelSSTRecord)_record; } lrec.Column = col; lrec.Row = row; lrec.XFIndex = styleIndex; if (setValue) { String str = ConvertCellValueToString(); int sstIndex = book.Workbook.AddSSTString(new UnicodeString(str)); lrec.SSTIndex = (sstIndex); UnicodeString us = book.Workbook.GetSSTString(sstIndex); stringValue = new HSSFRichTextString(); stringValue.UnicodeString = us; } _record = lrec; break; case CellType.Blank: BlankRecord brec = null; if (cellType != this.cellType) { brec = new BlankRecord(); } else { brec = (BlankRecord)_record; } brec.Column = col; // During construction the cellStyle may be null for a Blank cell. brec.XFIndex = styleIndex; brec.Row = row; _record = brec; break; case CellType.Boolean: BoolErrRecord boolRec = null; if (cellType != this.cellType) { boolRec = new BoolErrRecord(); } else { boolRec = (BoolErrRecord)_record; } boolRec.Column = col; if (setValue) { boolRec.SetValue(ConvertCellValueToBoolean()); } boolRec.XFIndex = styleIndex; boolRec.Row = row; _record = boolRec; break; case CellType.Error: BoolErrRecord errRec = null; if (cellType != this.cellType) { errRec = new BoolErrRecord(); } else { errRec = (BoolErrRecord)_record; } errRec.Column = col; if (setValue) { errRec.SetValue((byte)HSSFErrorConstants.ERROR_VALUE); } errRec.XFIndex = styleIndex; errRec.Row = row; _record = errRec; break; } if (cellType != this.cellType && this.cellType != CellType.Unknown) // Special Value to indicate an Uninitialized Cell { _sheet.Sheet.ReplaceValueRecord(_record); } this.cellType = cellType; }
/// <summary> /// Sets the cell type. The SetValue flag indicates whether to bother about /// trying to preserve the current value in the new record if one is Created. /// The SetCellValue method will call this method with false in SetValue /// since it will overWrite the cell value later /// </summary> /// <param name="cellType">Type of the cell.</param> /// <param name="setValue">if set to <c>true</c> [set value].</param> /// <param name="row">The row.</param> /// <param name="col">The col.</param> /// <param name="styleIndex">Index of the style.</param> private void SetCellType(CellType cellType, bool setValue, int row, int col, short styleIndex) { if (cellType > CellType.ERROR) { throw new Exception("I have no idea what type that Is!"); } switch (cellType) { case CellType.FORMULA: FormulaRecordAggregate frec = null; if (cellType != this.cellType) { frec = sheet.Sheet.RowsAggregate.CreateFormula(row, col); } else { frec = (FormulaRecordAggregate)record; } frec.Column = col; if (setValue) { frec.FormulaRecord.Value = NumericCellValue; } frec.XFIndex = styleIndex; frec.Row = row; record = frec; break; case CellType.NUMERIC: NumberRecord nrec = null; if (cellType != this.cellType) { nrec = new NumberRecord(); } else { nrec = (NumberRecord)record; } nrec.Column = col; if (setValue) { nrec.Value = NumericCellValue; } nrec.XFIndex = styleIndex; nrec.Row = row; record = nrec; break; case CellType.STRING: LabelSSTRecord lrec = null; if (cellType != this.cellType) { lrec = new LabelSSTRecord(); } else { lrec = (LabelSSTRecord)record; } lrec.Column = col; lrec.Row = row; lrec.XFIndex = styleIndex; if (setValue) { String str = ConvertCellValueToString(); int sstIndex = book.Workbook.AddSSTString(new UnicodeString(str)); lrec.SSTIndex = (sstIndex); UnicodeString us = book.Workbook.GetSSTString(sstIndex); stringValue = new HSSFRichTextString(); stringValue.UnicodeString = us; } record = lrec; break; case CellType.BLANK: BlankRecord brec = null; if (cellType != this.cellType) { brec = new BlankRecord(); } else { brec = (BlankRecord)record; } brec.Column = col; // During construction the cellStyle may be null for a Blank cell. brec.XFIndex = styleIndex; brec.Row = row; record = brec; break; case CellType.BOOLEAN: BoolErrRecord boolRec = null; if (cellType != this.cellType) { boolRec = new BoolErrRecord(); } else { boolRec = (BoolErrRecord)record; } boolRec.Column = col; if (setValue) { boolRec.SetValue(ConvertCellValueToBoolean()); } boolRec.XFIndex = styleIndex; boolRec.Row = row; record = boolRec; break; case CellType.ERROR: BoolErrRecord errRec = null; if (cellType != this.cellType) { errRec = new BoolErrRecord(); } else { errRec = (BoolErrRecord)record; } errRec.Column = col; if (setValue) { errRec.SetValue((byte)HSSFErrorConstants.ERROR_VALUE); } errRec.XFIndex = styleIndex; errRec.Row = row; record = errRec; break; } if (cellType != this.cellType && this.cellType != CellType.Unknown) // Special Value to indicate an Uninitialized Cell { sheet.Sheet.ReplaceValueRecord(record); } this.cellType = cellType; }
/// <summary> /// Adds a value record to the sheet's contained binary records /// (i.e. LabelSSTRecord or NumberRecord). /// This method is "loc" sensitive. Meaning you need to Set LOC to where you /// want it to start searching. If you don't know do this: SetLoc(GetDimsLoc). /// When Adding several rows you can just start at the last one by leaving loc /// at what this Sets it to. /// </summary> /// <param name="row">the row to Add the cell value to</param> /// <param name="col">the cell value record itself.</param> public void AddValueRecord(int row, CellValueRecordInterface col) { //if (log.Check(POILogger.DEBUG)) //{ // log.Log(POILogger.DEBUG, "Add value record row" + row); //} DimensionsRecord d = _dimensions; if (col.Column >= d.LastCol) { d.LastCol = ((short)(col.Column + 1)); } if (col.Column < d.FirstCol) { d.FirstCol = (col.Column); } _rowsAggregate.InsertCell(col); }
/// <summary> /// Formats a number or date cell, be that a real number, or the /// answer to a formula /// </summary> /// <param name="cell">The cell.</param> /// <param name="value">The value.</param> /// <returns></returns> private String FormatNumberDateCell(CellValueRecordInterface cell, double value) { // Get the built in format, if there is one int formatIndex = ft.GetFormatIndex(cell); String formatString = ft.GetFormatString(cell); if (formatString == null) { return value.ToString(); } else { // Is it a date? if (HSSFDateUtil.IsADateFormat(formatIndex, formatString) && HSSFDateUtil.IsValidExcelDate(value)) { // Java wants M not m for month formatString = formatString.Replace('m', 'M'); // Change \- into -, if it's there formatString = formatString.Replace("\\\\-", "-"); // Format as a date DateTime d = HSSFDateUtil.GetJavaDate(value, false); SimpleDateFormat df = new SimpleDateFormat(formatString); return df.Format(d); } else { if (formatString == "General") { // Some sort of wierd default return value.ToString(); } // Format as a number DecimalFormat df = new DecimalFormat(formatString); return df.Format(value); } } }
/// <summary> /// Remove a value record from the records array. /// This method is not loc sensitive, it Resets loc to = dimsloc so no worries. /// </summary> /// <param name="row">the row of the value record you wish to Remove</param> /// <param name="col">a record supporting the CellValueRecordInterface.</param> public void RemoveValueRecord(int row, CellValueRecordInterface col) { //log.LogFormatted(POILogger.DEBUG, "Remove value record row,dimsloc %,%", // new int[] { row, dimsloc }); _rowsAggregate.RemoveCell(col); }
private MulBlankRecord CreateMBR(CellValueRecordInterface[] cellValues, int startIx, int nBlank) { short[] xfs = new short[nBlank]; for (int i = 0; i < xfs.Length; i++) { xfs[i] = ((BlankRecord)cellValues[startIx + i]).XFIndex; } int rowIx = cellValues[startIx].Row; return new MulBlankRecord(rowIx, startIx, xfs); }
static int CountBlanks(CellValueRecordInterface[] rowCellValues, int startIx) { int i = startIx; while (i < rowCellValues.Length) { CellValueRecordInterface cvr = rowCellValues[i]; if (!(cvr is BlankRecord)) { break; } i++; } return i - startIx; }
/// <summary> /// Create a high level Cell object from an existing low level record. Should /// only be called from HSSFSheet or HSSFRow itself. /// </summary> /// <param name="cell">The low level cell to Create the high level representation from</param> /// <returns> the low level record passed in</returns> public ICell CreateCellFromRecord(CellValueRecordInterface cell) { ICell hcell = new HSSFCell(book, sheet, cell); AddCell(hcell); int colIx = cell.Column; if (row.IsEmpty) { row.FirstCol=(colIx); row.LastCol=(colIx + 1); } else { if (colIx < row.FirstCol) { row.FirstCol = (colIx); } else if (colIx > row.LastCol) { row.LastCol = (colIx + 1); } else { // added cell is within first and last cells } } // TODO - RowRecord column boundaries need to be updated for cell comments too return hcell; }
public MyEnumerator(ref CellValueRecordInterface[][] _records,int firstRow, int lastRow) { this.records = _records; this.nextRow = firstRow; this.lastRow = lastRow; //FindNext(); }
public void RemoveCell(CellValueRecordInterface cvRec) { if (cvRec is FormulaRecordAggregate) { ((FormulaRecordAggregate)cvRec).NotifyFormulaChanging(); } _valuesAgg.RemoveCell(cvRec); }
/// <summary> /// Replace a value record from the records array. /// This method is not loc sensitive, it Resets loc to = dimsloc so no worries. /// </summary> /// <param name="newval">a record supporting the CellValueRecordInterface. this will Replace /// the cell value with the same row and column. If there Isn't one, one will /// be Added.</param> public void ReplaceValueRecord(CellValueRecordInterface newval) { //if (log.Check(POILogger.DEBUG)) // log.Log(POILogger.DEBUG, "ReplaceValueRecord "); //The ValueRecordsAggregate use a tree map Underneath. //The tree Map uses the CellValueRecordInterface as both the //key and the value, if we dont do a Remove, then //the previous instance of the key is retained, effectively using //double the memory _rowsAggregate.RemoveCell(newval); _rowsAggregate.InsertCell(newval); }
/// <summary> /// returns whether this cell represents the same cell (NOT VALUE) /// </summary> /// <param name="i"> record to Compare</param> /// <returns>true if the cells are the same cell (positionally), false if not.</returns> public bool IsEqual(CellValueRecordInterface i) { return _formulaRecord.IsEqual(i); }