public void TestRowValueAggregatesOrder_bug45145() { InternalSheet sheet = InternalSheet.CreateSheet(); RowRecord rr = new RowRecord(5); sheet.AddRow(rr); CellValueRecordInterface cvr = new BlankRecord(); cvr.Column = 0; cvr.Row = (5); sheet.AddValueRecord(5, cvr); int dbCellRecordPos = GetDbCellRecordPos(sheet); if (dbCellRecordPos == 252) { // The overt symptom of the bug // DBCELL record pos is1 calculated wrong if VRA comes before RRA throw new AssertionException("Identified bug 45145"); } Assert.AreEqual(242, dbCellRecordPos); }
public void ProcessRecord(Record record) { _records.Add(record); if (record is MissingRowDummyRecord) { MissingRowDummyRecord mr = (MissingRowDummyRecord)record; log("Got dummy row " + mr.RowNumber); } if (record is MissingCellDummyRecord) { MissingCellDummyRecord mc = (MissingCellDummyRecord)record; log("Got dummy cell " + mc.Row + " " + mc.Column); } if (record is LastCellOfRowDummyRecord) { LastCellOfRowDummyRecord lc = (LastCellOfRowDummyRecord)record; log("Got end-of row, row was " + lc.Row + ", last column was " + lc.LastColumnNumber); } if (record is BOFRecord) { BOFRecord r = (BOFRecord)record; if (r.Type == BOFRecord.TYPE_WORKSHEET) { log("On new sheet"); } } if (record is RowRecord) { RowRecord rr = (RowRecord)record; log("Starting row #" + rr.RowNumber); } }
private void aTwo(UnknownB0 A_0) { UnknownDH dh = A_0.a(VLTOtherValue.TABLE_START) as UnknownDH; for (int i = 0; i < dh.asa1.Length; ++i) { TableEntry @as = dh.asa1[i]; switch (@as.entryType) { case EntryType.ROOT: this.av.am(@as.di1.asRootEntry(), A_0); break; case EntryType.CLASS: this.av.a(@as.di1.asClassEntry(), A_0); break; case EntryType.ROW: RowRecord c = @as.di1.asRowEntry(); if (this.av.genht2 == null) // attempted to load a file with a parent before db.vlt { } VLTClass dq = this.av.genht2[c.ui2]; dq.dqb1.a(c, A_0); break; } } }
public RowRecord Add(IExcelRow row, ISheet sheet, IExcelRowParseResult parseResult) { if (row == null) { throw new ArgumentNullException(nameof(row)); } if (sheet == null) { throw new ArgumentNullException(nameof(sheet)); } var excelFileRecord = sheet.Parent as ExcelFileRecord; if (excelFileRecord == null) { throw new ArgumentException("could not cast container as ExcelFileRecord"); } var sheetRecord = sheet as SheetRecord; if (sheetRecord == null) { throw new ArgumentException("could not cast sheet as SheetRecord"); } var rowRecord = new RowRecord(row, sheetRecord, parseResult); db.Add(rowRecord); return(rowRecord); }
public void TestLastAndFirstColumns_bug46654() { int ROW_IX = 10; int COL_IX = 3; HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = (HSSFSheet)workbook.CreateSheet("Sheet1"); RowRecord rowRec = new RowRecord(ROW_IX); rowRec.FirstCol = ((short)2); rowRec.LastCol = ((short)5); BlankRecord br = new BlankRecord(); br.Row = (ROW_IX); br.Column = ((short)COL_IX); sheet.Sheet.AddValueRecord(ROW_IX, br); HSSFRow row = new HSSFRow(workbook, sheet, rowRec); ICell cell = row.CreateCellFromRecord(br); if (row.FirstCellNum == 2 && row.LastCellNum == 5) { throw new AssertionException("Identified bug 46654a"); } Assert.AreEqual(COL_IX, row.FirstCellNum); Assert.AreEqual(COL_IX + 1, row.LastCellNum); row.RemoveCell(cell); Assert.AreEqual(-1, row.FirstCellNum); Assert.AreEqual(-1, row.LastCellNum); }
/// <summary> /// Creates an HSSFRow from a low level RowRecord object. Only HSSFSheet should do /// this. HSSFSheet uses this when an existing file is Read in. /// </summary> /// <param name="book">low-level Workbook object containing the sheet that Contains this row</param> /// <param name="sheet"> low-level Sheet object that Contains this Row</param> /// <param name="record">the low level api object this row should represent</param> ///<see cref="NPOI.HSSF.UserModel.HSSFSheet.CreateRow(int)"/> public HSSFRow(HSSFWorkbook book, HSSFSheet sheet, RowRecord record) { this.book = book; this.sheet = sheet; row = record; RowNum = (record.RowNumber); }
public void TestMissingRowRecords() { OpenNormal(); // We have rows 0, 1, 2, 20 and 21 int row0 = -1; for (int i = 0; i < r.Length; i++) { if (r[i] is RowRecord) { RowRecord rr = (RowRecord)r[i]; if (rr.RowNumber == 0) { row0 = i; } } } Assert.IsTrue(row0 > -1); // Following row 0, we should have 1, 2, then dummy, then 20+21+22 Assert.IsTrue(r[row0] is RowRecord); Assert.IsTrue(r[row0 + 1] is RowRecord); Assert.IsTrue(r[row0 + 2] is RowRecord); Assert.IsTrue(r[row0 + 3] is MissingRowDummyRecord); Assert.IsTrue(r[row0 + 4] is MissingRowDummyRecord); Assert.IsTrue(r[row0 + 5] is MissingRowDummyRecord); Assert.IsTrue(r[row0 + 6] is MissingRowDummyRecord); // ... Assert.IsTrue(r[row0 + 18] is MissingRowDummyRecord); Assert.IsTrue(r[row0 + 19] is MissingRowDummyRecord); Assert.IsTrue(r[row0 + 20] is RowRecord); Assert.IsTrue(r[row0 + 21] is RowRecord); Assert.IsTrue(r[row0 + 22] is RowRecord); // Check things had the right row numbers RowRecord rr2; rr2 = (RowRecord)r[row0 + 2]; Assert.AreEqual(2, rr2.RowNumber); rr2 = (RowRecord)r[row0 + 20]; Assert.AreEqual(20, rr2.RowNumber); rr2 = (RowRecord)r[row0 + 21]; Assert.AreEqual(21, rr2.RowNumber); MissingRowDummyRecord mr; mr = (MissingRowDummyRecord)r[row0 + 3]; Assert.AreEqual(3, mr.RowNumber); mr = (MissingRowDummyRecord)r[row0 + 4]; Assert.AreEqual(4, mr.RowNumber); mr = (MissingRowDummyRecord)r[row0 + 5]; Assert.AreEqual(5, mr.RowNumber); mr = (MissingRowDummyRecord)r[row0 + 18]; Assert.AreEqual(18, mr.RowNumber); mr = (MissingRowDummyRecord)r[row0 + 19]; Assert.AreEqual(19, mr.RowNumber); }
/// <summary> /// Creates new HSSFRow from scratch. Only HSSFSheet should do this. /// </summary> /// <param name="book">low-level Workbook object containing the sheet that Contains this row</param> /// <param name="sheet">low-level Sheet object that Contains this Row</param> /// <param name="rowNum">the row number of this row (0 based)</param> ///<see cref="NPOI.HSSF.UserModel.HSSFSheet.CreateRow(int)"/> public HSSFRow(HSSFWorkbook book, HSSFSheet sheet, int rowNum) { this.rowNum = rowNum; this.book = book; this.sheet = sheet; row = new RowRecord(rowNum); RowNum = (rowNum); }
/// <summary> /// Creates an HSSFRow from a low level RowRecord object. Only HSSFSheet should do /// this. HSSFSheet uses this when an existing file is Read in. /// </summary> /// <param name="book">low-level Workbook object containing the sheet that Contains this row</param> /// <param name="sheet"> low-level Sheet object that Contains this Row</param> /// <param name="record">the low level api object this row should represent</param> ///<see cref="Chama.Utils.NPOI.HSSF.UserModel.HSSFSheet.CreateRow(int)"/> public HSSFRow(HSSFWorkbook book, HSSFSheet sheet, RowRecord record) { this.book = book; this.sheet = sheet; row = record; RowNum = (record.RowNumber); // Don't trust colIx boundaries as read by other apps // set the RowRecord empty for the moment record.SetEmpty(); }
public int WriteHidden(RowRecord rowRecord, int row, bool hidden) { int level = rowRecord.OutlineLevel; while (rowRecord != null && GetRow(row).OutlineLevel >= level) { rowRecord.ZeroHeight = (hidden); row++; rowRecord = GetRow(row); } return(row - 1); }
public XLSRow(RowRecord record, SheetRecord sheet) { Cells = new Dictionary <uint, ICell>(); foreach (var cell in sheet.Cells.Where(i => i.Row == record.RowNumber)) { if (cell is LabelSstRecord) { (cell as LabelSstRecord).SetValue(sheet.SST); } AddCell(cell); } }
public void InsertRow(RowRecord row) { _rowRecords[row.RowNumber] = row; if ((row.RowNumber < firstrow)) //|| (firstrow == -1)) { firstrow = row.RowNumber; } if ((row.RowNumber > lastrow) || (lastrow == -1)) { lastrow = row.RowNumber; } }
public void TestRowGet() { RowRecordsAggregate rra = new RowRecordsAggregate(); RowRecord rr = new RowRecord(4); rra.InsertRow(rr); rra.InsertRow(new RowRecord(1)); RowRecord rr1 = rra.GetRow(4); Assert.IsNotNull(rr1); Assert.AreEqual(4, rr1.RowNumber, "Row number is1 1"); Assert.IsTrue(rr1 == rr, "Row record retrieved is1 identical"); }
public void InsertRow(RowRecord row) { _rowRecords[row.RowNumber] = row; // Clear the cached values _rowRecordValues = null; if (row.RowNumber < firstrow || firstrow == -1) { firstrow = row.RowNumber; } if (row.RowNumber > lastrow || lastrow == -1) { lastrow = row.RowNumber; } }
public void ExpandRow(int rowNumber) { int idx = rowNumber; if (idx == -1) { return; } // If it is already expanded do nothing. if (!IsRowGroupCollapsed(idx)) { return; } // Find the start of the Group. int startIdx = FindStartOfRowOutlineGroup(idx); RowRecord row = GetRow(startIdx); // Find the end of the Group. int endIdx = FindEndOfRowOutlineGroup(idx); // expand: // collapsed bit must be UnSet // hidden bit Gets UnSet _if_ surrounding Groups are expanded you can determine // this by looking at the hidden bit of the enclosing Group. You will have // to look at the start and the end of the current Group to determine which // is the enclosing Group // hidden bit only is altered for this outline level. ie. don't Un-collapse contained Groups if (!IsRowGroupHiddenByParent(idx)) { for (int i = startIdx; i <= endIdx; i++) { if (row.OutlineLevel == GetRow(i).OutlineLevel) { GetRow(i).ZeroHeight = (false); } else if (!IsRowGroupCollapsed(i)) { GetRow(i).ZeroHeight = (false); } } } // Write collapse field GetRow(endIdx + 1).Colapsed = (false); }
public void RemoveRow(RowRecord row) { int rowIndex = row.RowNumber; _valuesAgg.RemoveAllCellsValuesForRow(rowIndex); int key = rowIndex; RowRecord rr = (RowRecord)_rowRecords[key]; _rowRecords.Remove(key); if (rr == null) { throw new Exception("Invalid row index (" + key + ")"); } if (row != rr) { _rowRecords[key] = rr; throw new Exception("Attempt to remove row that does not belong to this sheet"); } }
public int FindStartOfRowOutlineGroup(int row) { // Find the start of the Group. RowRecord rowRecord = GetRow(row); int level = rowRecord.OutlineLevel; int currentRow = row; while (GetRow(currentRow) != null) { rowRecord = GetRow(currentRow); if (rowRecord.OutlineLevel < level) { return(currentRow + 1); } currentRow--; } return(currentRow + 1); }
/** Returns the physical row number of the end row in a block*/ public int GetEndRowNumberForBlock(int block) { int endIndex = ((block + 1) * DBCellRecord.BLOCK_SIZE) - 1; if (endIndex >= _rowRecords.Count) { endIndex = _rowRecords.Count - 1; } IEnumerator rowIter = _rowRecords.Values.GetEnumerator(); RowRecord row = null; for (int i = 0; i <= endIndex; i++) { rowIter.MoveNext(); row = (RowRecord)rowIter.Current; } return(row.RowNumber); }
public void TestSheetDimensions() { InternalSheet sheet = InternalSheet.CreateSheet(); DimensionsRecord dimensions = (DimensionsRecord)sheet.FindFirstRecordBySid(DimensionsRecord.sid); Assert.AreEqual(0, dimensions.FirstCol); Assert.AreEqual(0, dimensions.FirstRow); Assert.AreEqual(1, dimensions.LastCol); // plus pne Assert.AreEqual(1, dimensions.LastRow); // plus pne RowRecord rr = new RowRecord(0); sheet.AddRow(rr); Assert.AreEqual(0, dimensions.FirstCol); Assert.AreEqual(0, dimensions.FirstRow); Assert.AreEqual(1, dimensions.LastCol); Assert.AreEqual(1, dimensions.LastRow); CellValueRecordInterface cvr; cvr = new BlankRecord(); cvr.Column = ((short)0); cvr.Row = (0); sheet.AddValueRecord(0, cvr); Assert.AreEqual(0, dimensions.FirstCol); Assert.AreEqual(0, dimensions.FirstRow); Assert.AreEqual(1, dimensions.LastCol); Assert.AreEqual(1, dimensions.LastRow); cvr = new BlankRecord(); cvr.Column = ((short)1); cvr.Row = (0); sheet.AddValueRecord(0, cvr); Assert.AreEqual(0, dimensions.FirstCol); Assert.AreEqual(0, dimensions.FirstRow); Assert.AreEqual(2, dimensions.LastCol); //YK: failed until Bugzilla 53414 was fixed Assert.AreEqual(1, dimensions.LastRow); }
/** Returns the physical row number of the first row in a block*/ public int GetStartRowNumberForBlock(int block) { //Given that we basically iterate through the rows in order, //For a performance improvement, it would be better to return an instance of //an iterator and use that instance throughout, rather than recreating one and //having to move it to the right position. int startIndex = block * DBCellRecord.BLOCK_SIZE; IEnumerator rowIter = _rowRecords.Values.GetEnumerator(); RowRecord row = null; //Position the iterator at the start of the block for (int i = 0; i <= startIndex; i++) { rowIter.MoveNext(); row = (RowRecord)rowIter.Current; } return(row.RowNumber); }
public void CollapseRow(int rowNumber) { // Find the start of the Group. int startRow = FindStartOfRowOutlineGroup(rowNumber); RowRecord rowRecord = GetRow(startRow); // Hide all the columns Until the end of the Group int lastRow = WriteHidden(rowRecord, startRow, true); // Write collapse field if (GetRow(lastRow + 1) != null) { GetRow(lastRow + 1).Colapsed = (true); } else { RowRecord row = CreateRow(lastRow + 1); row.Colapsed = (true); InsertRow(row); } }
public async Task <int> test_insert_record_async(string device_id, RowRecord record) { var client = client_lst.Take(); var req = new TSInsertRecordReq(client.sessionId, device_id, record.measurements, record.ToBytes(), record.timestamp); TSStatus status; try{ status = await client.client.testInsertRecordAsync(req); } catch (TException e) { client_lst.Add(client); Console.WriteLine(e); var err_msg = String.Format("Record insertion failed"); throw new TException(err_msg, e); } if (debug_mode) { _logger.Info("insert one record to device {0}, server message: {1}", device_id, status.Message); } client_lst.Add(client); return(util_functions.verify_success(status, SUCCESS_CODE)); }
/// <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); } }
internal Row(Workbook wb, RowRecord row) : base(wb) { _cells = new CellCollection(wb); }
/** * Reads in the contents of this sheet */ public void read() { Record r = null; BaseSharedFormulaRecord sharedFormula = null; bool sharedFormulaAdded = false; bool cont = true; // Set the position within the file excelFile.setPos(startPosition); // Handles to the last drawing and obj records MsoDrawingRecord msoRecord = null; ObjRecord objRecord = null; bool firstMsoRecord = true; // Handle to the last conditional format record ConditionalFormat condFormat = null; // Handle to the autofilter records FilterModeRecord filterMode = null; AutoFilterInfoRecord autoFilterInfo = null; // A handle to window2 record Window2Record window2Record = null; // A handle to printgridlines record PrintGridLinesRecord printGridLinesRecord = null; // A handle to printheaders record PrintHeadersRecord printHeadersRecord = null; // Hash map of comments, indexed on objectId. As each corresponding // note record is encountered, these are removed from the array Dictionary<uint,Comment> comments = new Dictionary<uint,Comment>(); // A list of object ids - used for cross referencing ArrayList objectIds = new ArrayList(); // A handle to a continue record read in ContinueRecord continueRecord = null; while (cont) { r = excelFile.next(); Type type = r.getType(); if (type == Type.UNKNOWN && r.getCode() == 0) { //logger.warn("Biff code zero found"); // Try a dimension record if (r.getLength() == 0xa) { //logger.warn("Biff code zero found - trying a dimension record."); r.setType(Type.DIMENSION); } else { //logger.warn("Biff code zero found - Ignoring."); } } if (type == Type.DIMENSION) { DimensionRecord dr = null; if (workbookBof.isBiff8()) { dr = new DimensionRecord(r); } else { dr = new DimensionRecord(r, DimensionRecord.biff7); } numRows = dr.getNumberOfRows(); numCols = dr.getNumberOfColumns(); cells = new Cell[numRows, numCols]; } else if (type == Type.LABELSST) { LabelSSTRecord label = new LabelSSTRecord(r, sharedStrings, formattingRecords, sheet); addCell(label); } else if (type == Type.RK || type == Type.RK2) { RKRecord rkr = new RKRecord(r, formattingRecords, sheet); if (formattingRecords.isDate(rkr.getXFIndex())) { DateCell dc = new DateRecord (rkr, rkr.getXFIndex(), formattingRecords, nineteenFour, sheet); addCell(dc); } else { addCell(rkr); } } else if (type == Type.HLINK) { HyperlinkRecord hr = new HyperlinkRecord(r, sheet, workbookSettings); hyperlinks.Add(hr); } else if (type == Type.MERGEDCELLS) { MergedCellsRecord mc = new MergedCellsRecord(r, sheet); if (mergedCells == null) { mergedCells = mc.getRanges(); } else { Range[] newMergedCells = new Range[mergedCells.Length + mc.getRanges().Length]; System.Array.Copy(mergedCells, 0, newMergedCells, 0, mergedCells.Length); System.Array.Copy(mc.getRanges(), 0, newMergedCells, mergedCells.Length, mc.getRanges().Length); mergedCells = newMergedCells; } } else if (type == Type.MULRK) { MulRKRecord mulrk = new MulRKRecord(r); // Get the individual cell records from the multiple record int num = mulrk.getNumberOfColumns(); int ixf = 0; for (int i = 0; i < num; i++) { ixf = mulrk.getXFIndex(i); NumberValue nv = new NumberValue (mulrk.getRow(), mulrk.getFirstColumn() + i, RKHelper.getDouble(mulrk.getRKNumber(i)), ixf, formattingRecords, sheet); if (formattingRecords.isDate(ixf)) { DateCell dc = new DateRecord(nv, ixf, formattingRecords, nineteenFour, sheet); addCell(dc); } else { nv.setNumberFormat(formattingRecords.getNumberFormat(ixf)); addCell(nv); } } } else if (type == Type.NUMBER) { NumberRecord nr = new NumberRecord(r, formattingRecords, sheet); if (formattingRecords.isDate(nr.getXFIndex())) { DateCell dc = new DateRecord(nr,nr.getXFIndex(),formattingRecords,nineteenFour, sheet); addCell(dc); } else addCell(nr); } else if (type == Type.BOOLERR) { BooleanRecord br = new BooleanRecord(r, formattingRecords, sheet); if (br.isError()) { ErrorRecord er = new ErrorRecord(br.getRecord(), formattingRecords, sheet); addCell(er); } else { addCell(br); } } else if (type == Type.PRINTGRIDLINES) { printGridLinesRecord = new PrintGridLinesRecord(r); settings.setPrintGridLines(printGridLinesRecord.getPrintGridLines()); } else if (type == Type.PRINTHEADERS) { printHeadersRecord = new PrintHeadersRecord(r); settings.setPrintHeaders(printHeadersRecord.getPrintHeaders()); } else if (type == Type.WINDOW2) { window2Record = null; if (workbookBof.isBiff8()) { window2Record = new Window2Record(r); } else { window2Record = new Window2Record(r, Window2Record.biff7); } settings.setShowGridLines(window2Record.getShowGridLines()); settings.setDisplayZeroValues(window2Record.getDisplayZeroValues()); settings.setSelected(true); settings.setPageBreakPreviewMode(window2Record.isPageBreakPreview()); } else if (type == Type.PANE) { PaneRecord pr = new PaneRecord(r); if (window2Record != null && window2Record.getFrozen()) { settings.setVerticalFreeze(pr.getRowsVisible()); settings.setHorizontalFreeze(pr.getColumnsVisible()); } } else if (type == Type.CONTINUE) { // don't know what this is for, but keep hold of it anyway continueRecord = new ContinueRecord(r); } else if (type == Type.NOTE) { if (!workbookSettings.getDrawingsDisabled()) { NoteRecord nr = new NoteRecord(r); // Get the comment for the object id if (!comments.ContainsKey(nr.getObjectId())) { //logger.warn(" cannot find comment for note id " + nr.getObjectId() + "...ignoring"); } else { Comment comment = comments[nr.getObjectId()]; comments.Remove(nr.getObjectId()); comment.setNote(nr); drawings.Add(comment); addCellComment(comment.getColumn(), comment.getRow(), comment.getText(), comment.getWidth(), comment.getHeight()); } } } else if (type == Type.ARRAY) { ; } else if (type == Type.PROTECT) { ProtectRecord pr = new ProtectRecord(r); settings.setProtected(pr.isProtected()); } else if (type == Type.SHAREDFORMULA) { if (sharedFormula == null) { //logger.warn("Shared template formula is null - " + // "trying most recent formula template"); SharedFormulaRecord lastSharedFormula = (SharedFormulaRecord)sharedFormulas[sharedFormulas.Count - 1]; if (lastSharedFormula != null) sharedFormula = lastSharedFormula.getTemplateFormula(); } SharedFormulaRecord sfr = new SharedFormulaRecord(r, sharedFormula, workbook, workbook, sheet); sharedFormulas.Add(sfr); sharedFormula = null; } else if (type == Type.FORMULA || type == Type.FORMULA2) { FormulaRecord fr = new FormulaRecord(r, excelFile, formattingRecords, workbook, workbook, sheet, workbookSettings); if (fr.isShared()) { BaseSharedFormulaRecord prevSharedFormula = sharedFormula; sharedFormula = (BaseSharedFormulaRecord)fr.getFormula(); // See if it fits in any of the shared formulas sharedFormulaAdded = addToSharedFormulas(sharedFormula); if (sharedFormulaAdded) { sharedFormula = prevSharedFormula; } // If we still haven't added the previous base shared formula, // revert it to an ordinary formula and add it to the cell if (!sharedFormulaAdded && prevSharedFormula != null) { // Do nothing. It's possible for the biff file to contain the // record sequence // FORMULA-SHRFMLA-FORMULA-SHRFMLA-FORMULA-FORMULA-FORMULA // ie. it first lists all the formula templates, then it // lists all the individual formulas addCell(revertSharedFormula(prevSharedFormula)); } } else { Cell cell = fr.getFormula(); try { // See if the formula evaluates to date if (fr.getFormula().getType() == CellType.NUMBER_FORMULA) { NumberFormulaRecord nfr = (NumberFormulaRecord)fr.getFormula(); if (formattingRecords.isDate(nfr.getXFIndex())) { cell = new DateFormulaRecord(nfr, formattingRecords, workbook, workbook, nineteenFour, sheet); } } addCell(cell); } catch (FormulaException e) { // Something has gone wrong trying to read the formula data eg. it // might be unsupported biff7 data //logger.warn(CellReferenceHelper.getCellReference(cell.getColumn(), cell.getRow()) + " " + e.Message); } } } else if (type == Type.LABEL) { LabelRecord lr = null; if (workbookBof.isBiff8()) { lr = new LabelRecord(r, formattingRecords, sheet, workbookSettings); } else { lr = new LabelRecord(r, formattingRecords, sheet, workbookSettings, LabelRecord.biff7); } addCell(lr); } else if (type == Type.RSTRING) { RStringRecord lr = null; // RString records are obsolete in biff 8 Assert.verify(!workbookBof.isBiff8()); lr = new RStringRecord(r, formattingRecords, sheet, workbookSettings, RStringRecord.biff7); addCell(lr); } else if (type == Type.NAME) { ; } else if (type == Type.PASSWORD) { PasswordRecord pr = new PasswordRecord(r); settings.setPasswordHash(pr.getPasswordHash()); } else if (type == Type.ROW) { RowRecord rr = new RowRecord(r); // See if the row has anything funny about it if (!rr.isDefaultHeight() || !rr.matchesDefaultFontHeight() || rr.isCollapsed() || rr.hasDefaultFormat() || rr.getOutlineLevel() != 0) { rowProperties.Add(rr); } } else if (type == Type.BLANK) { if (!workbookSettings.getIgnoreBlanks()) { BlankCell bc = new BlankCell(r, formattingRecords, sheet); addCell(bc); } } else if (type == Type.MULBLANK) { if (!workbookSettings.getIgnoreBlanks()) { MulBlankRecord mulblank = new MulBlankRecord(r); // Get the individual cell records from the multiple record int num = mulblank.getNumberOfColumns(); for (int i = 0; i < num; i++) { int ixf = mulblank.getXFIndex(i); MulBlankCell mbc = new MulBlankCell (mulblank.getRow(), mulblank.getFirstColumn() + i, ixf, formattingRecords, sheet); addCell(mbc); } } } else if (type == Type.SCL) { SCLRecord scl = new SCLRecord(r); settings.setZoomFactor(scl.getZoomFactor()); } else if (type == Type.COLINFO) { ColumnInfoRecord cir = new ColumnInfoRecord(r); columnInfosArray.Add(cir); } else if (type == Type.HEADER) { HeaderRecord hr = null; if (workbookBof.isBiff8()) hr = new HeaderRecord(r, workbookSettings); else hr = new HeaderRecord(r, workbookSettings, HeaderRecord.biff7); HeaderFooter header = new HeaderFooter(hr.getHeader()); settings.setHeader(header); } else if (type == Type.FOOTER) { FooterRecord fr = null; if (workbookBof.isBiff8()) { fr = new FooterRecord(r, workbookSettings); } else { fr = new FooterRecord(r, workbookSettings, FooterRecord.biff7); } HeaderFooter footer = new HeaderFooter(fr.getFooter()); settings.setFooter(footer); } else if (type == Type.SETUP) { SetupRecord sr = new SetupRecord(r); // If the setup record has its not initialized bit set, then // use the sheet settings default values if (sr.getInitialized()) { if (sr.isPortrait()) { settings.setOrientation(PageOrientation.PORTRAIT); } else { settings.setOrientation(PageOrientation.LANDSCAPE); } if (sr.isRightDown()) { settings.setPageOrder(PageOrder.RIGHT_THEN_DOWN); } else { settings.setPageOrder(PageOrder.DOWN_THEN_RIGHT); } settings.setPaperSize(PaperSize.getPaperSize(sr.getPaperSize())); settings.setHeaderMargin(sr.getHeaderMargin()); settings.setFooterMargin(sr.getFooterMargin()); settings.setScaleFactor(sr.getScaleFactor()); settings.setPageStart(sr.getPageStart()); settings.setFitWidth(sr.getFitWidth()); settings.setFitHeight(sr.getFitHeight()); settings.setHorizontalPrintResolution (sr.getHorizontalPrintResolution()); settings.setVerticalPrintResolution(sr.getVerticalPrintResolution()); settings.setCopies(sr.getCopies()); if (workspaceOptions != null) { settings.setFitToPages(workspaceOptions.getFitToPages()); } } } else if (type == Type.WSBOOL) { workspaceOptions = new WorkspaceInformationRecord(r); } else if (type == Type.DEFCOLWIDTH) { DefaultColumnWidthRecord dcwr = new DefaultColumnWidthRecord(r); settings.setDefaultColumnWidth(dcwr.getWidth()); } else if (type == Type.DEFAULTROWHEIGHT) { DefaultRowHeightRecord drhr = new DefaultRowHeightRecord(r); if (drhr.getHeight() != 0) { settings.setDefaultRowHeight(drhr.getHeight()); } } else if (type == Type.CONDFMT) { ConditionalFormatRangeRecord cfrr = new ConditionalFormatRangeRecord(r); condFormat = new ConditionalFormat(cfrr); conditionalFormats.Add(condFormat); } else if (type == Type.CF) { ConditionalFormatRecord cfr = new ConditionalFormatRecord(r); condFormat.addCondition(cfr); } else if (type == Type.FILTERMODE) { filterMode = new FilterModeRecord(r); } else if (type == Type.AUTOFILTERINFO) { autoFilterInfo = new AutoFilterInfoRecord(r); } else if (type == Type.AUTOFILTER) { if (!workbookSettings.getAutoFilterDisabled()) { AutoFilterRecord af = new AutoFilterRecord(r); if (autoFilter == null) { autoFilter = new AutoFilter(filterMode, autoFilterInfo); filterMode = null; autoFilterInfo = null; } autoFilter.add(af); } } else if (type == Type.LEFTMARGIN) { MarginRecord m = new LeftMarginRecord(r); settings.setLeftMargin(m.getMargin()); } else if (type == Type.RIGHTMARGIN) { MarginRecord m = new RightMarginRecord(r); settings.setRightMargin(m.getMargin()); } else if (type == Type.TOPMARGIN) { MarginRecord m = new TopMarginRecord(r); settings.setTopMargin(m.getMargin()); } else if (type == Type.BOTTOMMARGIN) { MarginRecord m = new BottomMarginRecord(r); settings.setBottomMargin(m.getMargin()); } else if (type == Type.HORIZONTALPAGEBREAKS) { HorizontalPageBreaksRecord dr = null; if (workbookBof.isBiff8()) { dr = new HorizontalPageBreaksRecord(r); } else { dr = new HorizontalPageBreaksRecord (r, HorizontalPageBreaksRecord.biff7); } rowBreaks = dr.getRowBreaks(); } else if (type == Type.VERTICALPAGEBREAKS) { VerticalPageBreaksRecord dr = null; if (workbookBof.isBiff8()) { dr = new VerticalPageBreaksRecord(r); } else { dr = new VerticalPageBreaksRecord (r, VerticalPageBreaksRecord.biff7); } columnBreaks = dr.getColumnBreaks(); } else if (type == Type.PLS) { plsRecord = new PLSRecord(r); // Check for Continue records while (excelFile.peek().getType() == Type.CONTINUE) { r.addContinueRecord(excelFile.next()); } } else if (type == Type.DVAL) { if (!workbookSettings.getCellValidationDisabled()) { DataValidityListRecord dvlr = new DataValidityListRecord(r); if (dvlr.getObjectId() == DataValidation.DEFAULT_OBJECT_ID) { if (msoRecord != null && objRecord == null) { // there is a drop down associated with this data validation if (drawingData == null) drawingData = new DrawingData(); Drawing2 d2 = new Drawing2(msoRecord, drawingData, workbook.getDrawingGroup()); drawings.Add(d2); msoRecord = null; dataValidation = new DataValidation(dvlr); } else { // no drop down dataValidation = new DataValidation(dvlr); } } else if (objectIds.Contains(dvlr.getObjectId())) dataValidation = new DataValidation(dvlr); else { //logger.warn("object id " + dvlr.getObjectId() + " referenced " + // " by data validity list record not found - ignoring"); } } } else if (type == Type.HCENTER) { CentreRecord hr = new CentreRecord(r); settings.setHorizontalCentre(hr.isCentre()); } else if (type == Type.VCENTER) { CentreRecord vc = new CentreRecord(r); settings.setVerticalCentre(vc.isCentre()); } else if (type == Type.DV) { if (!workbookSettings.getCellValidationDisabled()) { DataValiditySettingsRecord dvsr = new DataValiditySettingsRecord(r, workbook, workbook, workbook.getSettings()); if (dataValidation != null) { dataValidation.add(dvsr); addCellValidation(dvsr.getFirstColumn(), dvsr.getFirstRow(), dvsr.getLastColumn(), dvsr.getLastRow(), dvsr); } else { //logger.warn("cannot add data validity settings"); } } } else if (type == Type.OBJ) { objRecord = new ObjRecord(r); if (!workbookSettings.getDrawingsDisabled()) { // sometimes excel writes out continue records instead of drawing // records, so forcibly hack the stashed continue record into // a drawing record if (msoRecord == null && continueRecord != null) { //logger.warn("Cannot find drawing record - using continue record"); msoRecord = new MsoDrawingRecord(continueRecord.getRecord()); continueRecord = null; } handleobjectRecord(objRecord, msoRecord, comments); objectIds.Add((objRecord.getObjectId())); } // Save chart handling until the chart BOF record appears if (objRecord.getType() != ObjRecord.CHART) { objRecord = null; msoRecord = null; } } else if (type == Type.MSODRAWING) { if (!workbookSettings.getDrawingsDisabled()) { if (msoRecord != null) { // For form controls, a rogue MSODRAWING record can crop up // after the main one. Add these into the drawing data drawingData.addRawData(msoRecord.getData()); } msoRecord = new MsoDrawingRecord(r); if (firstMsoRecord) { msoRecord.setFirst(); firstMsoRecord = false; } } } else if (type == Type.BUTTONPROPERTYSET) { buttonPropertySet = new ButtonPropertySetRecord(r); } else if (type == Type.CALCMODE) { CalcModeRecord cmr = new CalcModeRecord(r); settings.setAutomaticFormulaCalculation(cmr.isAutomatic()); } else if (type == Type.SAVERECALC) { SaveRecalcRecord cmr = new SaveRecalcRecord(r); settings.setRecalculateFormulasBeforeSave(cmr.getRecalculateOnSave()); } else if (type == Type.GUTS) { GuttersRecord gr = new GuttersRecord(r); maxRowOutlineLevel = gr.getRowOutlineLevel() > 0 ? gr.getRowOutlineLevel() - 1 : 0; maxColumnOutlineLevel = gr.getColumnOutlineLevel() > 0 ? gr.getRowOutlineLevel() - 1 : 0; } else if (type == Type.BOF) { BOFRecord br = new BOFRecord(r); Assert.verify(!br.isWorksheet()); int startpos = excelFile.getPos() - r.getLength() - 4; // Skip to the end of the nested bof // Thanks to Rohit for spotting this Record r2 = excelFile.next(); while (r2.getCode() != Type.EOF.value) r2 = excelFile.next(); if (br.isChart()) { if (!workbook.getWorkbookBof().isBiff8()) { //logger.warn("only biff8 charts are supported"); } else { if (drawingData == null) drawingData = new DrawingData(); if (!workbookSettings.getDrawingsDisabled()) { Chart chart = new Chart(msoRecord, objRecord, drawingData, startpos, excelFile.getPos(), excelFile, workbookSettings); charts.Add(chart); if (workbook.getDrawingGroup() != null) workbook.getDrawingGroup().add(chart); } } // Reset the drawing records msoRecord = null; objRecord = null; } // If this worksheet is just a chart, then the EOF reached // represents the end of the sheet as well as the end of the chart if (sheetBof.isChart()) cont = false; } else if (type == Type.EOF) cont = false; } // Restore the file to its accurate position excelFile.restorePos(); // Add any out of bounds cells if (outOfBoundsCells.Count > 0) handleOutOfBoundsCells(); // Add all the shared formulas to the sheet as individual formulas foreach (SharedFormulaRecord sfr in sharedFormulas) { Cell[] sfnr = sfr.getFormulas(formattingRecords, nineteenFour); for (int sf = 0; sf < sfnr.Length; sf++) addCell(sfnr[sf]); } // If the last base shared formula wasn't added to the sheet, then // revert it to an ordinary formula and add it if (!sharedFormulaAdded && sharedFormula != null) addCell(revertSharedFormula(sharedFormula)); // If there is a stray msoDrawing record, then flag to the drawing group // that one has been omitted if (msoRecord != null && workbook.getDrawingGroup() != null) workbook.getDrawingGroup().setDrawingsOmitted(msoRecord, objRecord); // Check that the comments hash is empty if (comments.Count != 0) { //logger.warn("Not all comments have a corresponding Note record"); } }
private Biff GetCorrectRecord(GenericBiff record, Stream stream, SstRecord sst) { Biff ret = record; switch (record.Id) { case (ushort)RecordType.Bof: BofRecord bof = new BofRecord(record); if (bof.Version < 0x0600) { throw new Exception("Versions below Excel 97/2000 are currently not supported."); } ret = bof; break; case (ushort)RecordType.Boundsheet: ret = new BoundSheetRecord(record); break; case (ushort)RecordType.Index: ret = new IndexRecord(record); break; case (ushort)RecordType.DbCell: ret = new DbCellRecord(record); break; case (ushort)RecordType.Row: ret = new RowRecord(record); break; case (ushort)RecordType.Continue: ret = new ContinueRecord(record); break; case (ushort)RecordType.Blank: ret = new BlankRecord(record); break; case (ushort)RecordType.BoolErr: ret = new BoolErrRecord(record); break; case (ushort)RecordType.Formula: ret = new FormulaRecord(record, stream); break; case (ushort)RecordType.Label: ret = new LabelRecord(record); break; case (ushort)RecordType.LabelSst: ret = new LabelSstRecord(record, sst); break; case (ushort)RecordType.MulBlank: ret = new MulBlankRecord(record); break; case (ushort)RecordType.MulRk: ret = new MulRkRecord(record); break; case (ushort)RecordType.String: ret = new StringValueRecord(record); break; case (ushort)RecordType.Xf: ret = new XfRecord(record); break; case (ushort)RecordType.Rk: ret = new RkRecord(record); break; case (ushort)RecordType.Number: ret = new NumberRecord(record); break; case (ushort)RecordType.Array: ret = new ArrayRecord(record); break; case (ushort)RecordType.ShrFmla: ret = new SharedFormulaRecord(record); break; case (ushort)RecordType.Table: ret = new TableRecord(record); break; case (ushort)RecordType.Sst: ret = new SstRecord(record, stream); break; case (ushort)RecordType.Eof: ret = new EofRecord(record); break; case (ushort)RecordType.Font: ret = new FontRecord(record); break; case (ushort)RecordType.Format: ret = new Net.SourceForge.Koogra.Excel.Records.FormatRecord(record); break; case (ushort)RecordType.Palette: ret = new PaletteRecord(record); break; case (ushort)RecordType.Hyperlink: ret = new HyperLinkRecord(record); break; } return(ret); }
// This is where our problems with Carbon and up appear to stem from. public void a(RowRecord A_0, UnknownB0 A_1) { BinaryReader binaryReader = new BinaryReader(A_1.ms1); BinaryReader binaryReader2 = new BinaryReader(A_1.ms2); UnknownDR dr = new UnknownDR(this.vltClass.classRecord.i2); UnknownA8 a = A_1.a(VLTOtherValue.TABLE_END) as UnknownA8; int num; if (a.genht1.ContainsKey(A_0.position)) { num = a.genht1[A_0.position].i2; } else { // NOTE: THIS IS A BUG, IT SHOULD NOT HAPPEN. // The ONLY reason I'm checking ContainsKey instead of using exception handling, // is because exception handling causes huge slowdowns in Visual Studio debugging. if (BuildConfig.DEBUG) { ++numFails; Console.WriteLine("VLTClass.a(): num fail (num" + numFails + ",b" + b8Fails + ")"); } return; } dr.b01 = A_1; dr.dq1 = this.vltClass; dr.c1 = A_0; for (int i = 0; i < this.vltClass.classRecord.i2; ++i) { VLTClass.aclz1 a2 = this.vltClass.fields[i]; BinaryReader binaryReader3; if (!a2.c()) { binaryReader3 = binaryReader; binaryReader3.BaseStream.Seek(num + a2.us1, SeekOrigin.Begin); } else { binaryReader3 = null; for (int j = 0; j < A_0.i1; ++j) { if (A_0.caa1[j].hash == a2.hash) { if (A_0.caa1[j].a()) { binaryReader3 = binaryReader2; binaryReader3.BaseStream.Seek(A_0.caa1[j].position, SeekOrigin.Begin); } else { binaryReader3 = binaryReader; binaryReader3.BaseStream.Seek(a.genht1[A_0.caa1[j].position].i2, SeekOrigin.Begin); } } } if (binaryReader3 == null) { continue; } } Type type = TypeMap.instance.getTypeForKey(a2.ui2); if (type == null) { type = typeof(VLTRawType); } VLTBaseType bb; if (a2.isArray()) { bb = new VLTArrayType(a2, type); } else { bb = VLTBaseType.a(type); bb.size = a2.len; if (bb is VLTRawType) { (bb as VLTRawType).len = a2.len; } } bb.ui1 = (uint)binaryReader3.BaseStream.Position; bb.isVltOffset = (binaryReader3 == binaryReader2); bb.typeHash = a2.ui2; bb.ui3 = a2.hash; bb.dr1 = dr; bb.read(binaryReader3); dr.a(i, bb); } this.drList.Add(dr); }
public ExcelRowValidateOnTypeRequest(RowRecord row, Type onType, JsonNamingStrategy namingStrategy = JsonNamingStrategy.None) { this.row = row; this.onType = onType; this.NamingStrategy = namingStrategy; }
internal Worksheet(Workbook wb, BoundSheetRecord sheet, SortedList <long, Biff> records) : base(wb) { _name = sheet.Name; int idx = records.IndexOfKey((long)sheet.BofPos); _hyperlinks = new HyperLinkCollection(wb); for (int i = idx + 1; i < records.Count; ++i) { Biff biff = records.Values[i]; if (biff is HyperLinkRecord) { _hyperlinks.Add((HyperLinkRecord)biff); } else if (biff is EofRecord) { break; } } BofRecord bof = (BofRecord)records.Values[idx++]; Biff seeker = records.Values[idx++]; while (!(seeker is IndexRecord)) { seeker = records.Values[idx++]; } IndexRecord index = (IndexRecord)seeker; _rows = new RowCollection(wb); foreach (uint indexPos in index.Rows) { long dbCellPos = indexPos; int dbCellIdx = records.IndexOfKey(dbCellPos); DbCellRecord dbCell = (DbCellRecord)records[dbCellPos]; if (dbCell.RowOffset > 0) { long rowPos = dbCellPos - dbCell.RowOffset; int recIndex = records.IndexOfKey(rowPos); Debug.Assert(recIndex != -1); Biff record = records.Values[recIndex++]; while (record is RowRecord) { RowRecord row = (RowRecord)record; Row currentRow = new Row(Workbook, row); _rows.Add(row.RowNumber, currentRow); record = records.Values[recIndex++]; } while (recIndex <= dbCellIdx) { if (!(record is CellRecord)) { record = records.Values[recIndex++]; continue; } CellRecord thecell = (CellRecord)record; Row currentRow = _rows[thecell.Row]; if (thecell is SingleColCellRecord) { SingleColCellRecord cell = (SingleColCellRecord)thecell; object val = cell.Value; Cell newCell = new Cell(Workbook, val); if (cell is RowColXfCellRecord) { RowColXfCellRecord xfCell = (RowColXfCellRecord)cell; Style style = Workbook.Styles[xfCell.Xf]; Debug.Assert(style != null); newCell.Style = style; } currentRow.Cells.Add((byte)cell.Col, newCell); } else { MultipleColCellRecord cells = (MultipleColCellRecord)thecell; for (ushort i = cells.FirstCol; i <= cells.LastCol; ++i) { object val = cells.GetValue(i); if (val != null) { Cell newCell = null; if (val is RkRec) { RkRec rk = (RkRec)val; newCell = new Cell(Workbook, rk.Value); Style style = Workbook.Styles[rk.Xf]; Debug.Assert(style != null); newCell.Style = style; } else { newCell = new Cell(Workbook, val); } currentRow.Cells.Add((byte)i, newCell); } } } record = records.Values[recIndex++]; } } } }