Exemplo n.º 1
0
        //private static POILogger log = POILogFactory.GetLogger(typeof(HSSFSheet));

        /// <summary>
        /// Creates new HSSFSheet - called by HSSFWorkbook to create a _sheet from
        /// scratch. You should not be calling this from application code (its protected anyhow).
        /// </summary>
        /// <param name="workbook">The HSSF Workbook object associated with the _sheet.</param>
        /// <see cref="Zephyr.Utils.NPOI.HSSF.UserModel.HSSFWorkbook.CreateSheet()"/>
        public HSSFSheet(HSSFWorkbook workbook)
        {
            _sheet = InternalSheet.CreateSheet();
            rows = new Dictionary<int, Zephyr.Utils.NPOI.SS.UserModel.IRow>();
            this._workbook = workbook;
            this.book = workbook.Workbook;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Cell comment Finder.
        /// Returns cell comment for the specified sheet, row and column.
        /// </summary>
        /// <param name="sheet">The sheet.</param>
        /// <param name="row">The row.</param>
        /// <param name="column">The column.</param>
        /// <returns>cell comment or 
        /// <c>null</c>
        ///  if not found</returns>
        public static HSSFComment FindCellComment(InternalSheet sheet, int row, int column)
        {
            HSSFComment comment = null;
            Dictionary<int, TextObjectRecord> noteTxo = new Dictionary<int, TextObjectRecord>(); //map shapeId and TextObjectRecord
            int i = 0;
            for (IEnumerator it = sheet.Records.GetEnumerator(); it.MoveNext(); )
            {
                RecordBase rec = (RecordBase)it.Current;
                if (rec is NoteRecord)
                {
                    NoteRecord note = (NoteRecord)rec;
                    if (note.Row == row && note.Column == column)
                    {
                        if (i < noteTxo.Count)
                        {
                            TextObjectRecord txo = (TextObjectRecord)noteTxo[note.ShapeId];
                            comment = new HSSFComment(note, txo);
                            comment.Row = note.Row;
                            comment.Column = note.Column;
                            comment.Author = note.Author;
                            comment.Visible = (note.Flags == NoteRecord.NOTE_VISIBLE);
                            comment.String = txo.Str;
                            break;
                        }
                    }
                }
                else if (rec is ObjRecord)
                {
                    ObjRecord obj = (ObjRecord)rec;
                    SubRecord sub = obj.SubRecords[0];
                    if (sub is CommonObjectDataSubRecord)
                    {
                        CommonObjectDataSubRecord cmo = (CommonObjectDataSubRecord)sub;
                        if (cmo.ObjectType == CommonObjectType.COMMENT)
                        {
                            //Find the nearest TextObjectRecord which holds comment's text and map it to its shapeId
                            while (it.MoveNext())
                            {
                                rec = (Record)it.Current;
                                if (rec is TextObjectRecord)
                                {
                                    noteTxo.Add(cmo.ObjectId, (TextObjectRecord)rec);
                                    break;
                                }
                            }

                        }
                    }
                }
            }
            return comment;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Creates an HSSFSheet representing the given Sheet object.  Should only be
 /// called by HSSFWorkbook when reading in an exisiting file.
 /// </summary>
 /// <param name="workbook">The HSSF Workbook object associated with the _sheet.</param>
 /// <param name="sheet">lowlevel Sheet object this _sheet will represent</param>
 /// <see cref="Zephyr.Utils.NPOI.HSSF.UserModel.HSSFWorkbook(Zephyr.Utils.NPOI.POIFS.FileSystem.DirectoryNode, bool)"/>
 public HSSFSheet(HSSFWorkbook workbook, InternalSheet sheet)
 {
     this._sheet = sheet;
     rows = new Dictionary<int, Zephyr.Utils.NPOI.SS.UserModel.IRow>();
     this._workbook = workbook;
     this.book = _workbook.Workbook;
     SetPropertiesFromSheet(_sheet);
 }
Exemplo n.º 4
0
        /// <summary>
        /// used internally to Set the properties given a Sheet object
        /// </summary>
        /// <param name="sheet">The _sheet.</param>
        private void SetPropertiesFromSheet(InternalSheet sheet)
        {

            RowRecord row = _sheet.NextRow;
            bool rowRecordsAlreadyPresent = row != null;

            while (row != null)
            {
                CreateRowFromRecord(row);

                row = sheet.NextRow;
            }

            CellValueRecordInterface[] cvals = sheet.GetValueRecords();
            long timestart = DateTime.Now.Millisecond;

            //if (log.Check(POILogger.DEBUG))
            //    log.Log(DEBUG, "Time at start of cell creating in HSSF _sheet = ",
            //        timestart);
            HSSFRow lastrow = null;

            // Add every cell to its row
            for (int i = 0; i < cvals.Length; i++)
            {
                CellValueRecordInterface cval = cvals[i];
                long cellstart = DateTime.Now.Millisecond;
                HSSFRow hrow = lastrow;

                if ((lastrow == null) || (lastrow.RowNum != cval.Row))
                {
                    hrow = (HSSFRow)GetRow(cval.Row);
                    if (hrow == null)
                    {
                        // Some tools (like Perl module SpReadsheet::WriteExcel - bug 41187) skip the RowRecords 
                        // Excel, OpenOffice.org and GoogleDocs are all OK with this, so POI should be too.
                        if (rowRecordsAlreadyPresent)
                        {
                            // if at least one row record is present, all should be present.
                            throw new Exception("Unexpected missing row when some rows already present");
                        }
                        // Create the row record on the fly now.
                        RowRecord rowRec = new RowRecord(cval.Row);
                        _sheet.AddRow(rowRec);
                        hrow = CreateRowFromRecord(rowRec);
                    }
                }
                if (hrow != null)
                {
                    lastrow = hrow;
                    if (cval is Record)
                    {
                        //if (log.Check(POILogger.DEBUG))
                        //    log.Log(DEBUG, "record id = " + StringUtil.ToHexString(((Record)cval).Sid));
                    }

                    hrow.CreateCellFromRecord(cval);

                    //if (log.Check(POILogger.DEBUG))
                    //    log.Log(DEBUG, "record took ",DateTime.Now.Millisecond - cellstart);
                }
                else
                {
                    cval = null;
                }
            }
            //if (log.Check(POILogger.DEBUG))
            //    log.Log(DEBUG, "total _sheet cell creation took ",
            //        DateTime.Now.Millisecond - timestart);
        }
Exemplo n.º 5
0
            /**
     * Check if the cloned sheet has drawings. If yes, then allocate a new drawing group ID and
     * re-generate shape IDs
     *
     * @param sheet the cloned sheet
     */
        public void CloneDrawings(InternalSheet sheet)
        {

            FindDrawingGroup();

            if (drawingManager == null)
            {
                //this workbook does not have drawings
                return;
            }

            //check if the cloned sheet has drawings
            int aggLoc = sheet.AggregateDrawingRecords(drawingManager, false);
            if (aggLoc != -1)
            {
                EscherAggregate agg = (EscherAggregate)sheet.FindFirstRecordBySid(EscherAggregate.sid);
                EscherContainerRecord escherContainer = agg.GetEscherContainer();
                if (escherContainer == null)
                {
                    return;
                }

                EscherDggRecord dgg = drawingManager.GetDgg();

                //register a new drawing group for the cloned sheet
                int dgId = drawingManager.FindNewDrawingGroupId();
                dgg.AddCluster(dgId, 0);
                dgg.DrawingsSaved = dgg.DrawingsSaved + 1;

                EscherDgRecord dg = null;
                for (IEnumerator it = escherContainer.ChildRecords.GetEnumerator(); it.MoveNext(); )
                {
                    Object er = it.Current;
                    if (er is EscherDgRecord)
                    {
                        dg = (EscherDgRecord)er;
                        //update id of the drawing in the cloned sheet
                        dg.Options = ((short)(dgId << 4));
                    }
                    else if (er is EscherContainerRecord)
                    {
                        //recursively find shape records and re-generate shapeId
                        ArrayList spRecords = new ArrayList();
                        EscherContainerRecord cp = (EscherContainerRecord)er;
                        for (IEnumerator spIt = cp.ChildRecords.GetEnumerator(); spIt.MoveNext(); )
                        {
                            EscherContainerRecord shapeContainer = (EscherContainerRecord)spIt.Current;

                            foreach (EscherRecord shapeChildRecord in shapeContainer.ChildRecords)
                            {
                                int recordId = shapeChildRecord.RecordId;
                                if (recordId == EscherSpRecord.RECORD_ID)
                                {
                                    EscherSpRecord sp = (EscherSpRecord)shapeChildRecord;
                                    int shapeId = drawingManager.AllocateShapeId((short)dgId, dg);
                                    //allocateShapeId increments the number of shapes. roll back to the previous value
                                    dg.NumShapes = (dg.NumShapes - 1);
                                    sp.ShapeId = (shapeId);
                                }
                                else if (recordId == EscherOptRecord.RECORD_ID)
                                {
                                    EscherOptRecord opt = (EscherOptRecord)shapeChildRecord;
                                    EscherSimpleProperty prop = (EscherSimpleProperty)opt.Lookup(
                                            EscherProperties.BLIP__BLIPTODISPLAY);
                                    if (prop != null)
                                    {
                                        int pictureIndex = prop.PropertyValue;
                                        // increment reference count for pictures
                                        EscherBSERecord bse = GetBSERecord(pictureIndex);
                                        bse.Ref = bse.Ref + 1;
                                    }

                                }

                            }
                        }
                    }
                }

            }
        }