コード例 #1
0
ファイル: Comment.cs プロジェクト: ferrinsp/kbellfireapp
        /**
         * Writes out the additional comment records
         *
         * @param outputFile the output file
         * @exception IOException
         */
        public virtual void writeAdditionalRecords(File outputFile)
        {
            if (origin == Origin.READ)
            {
                outputFile.write(objRecord);

                if (mso != null)
                {
                    outputFile.write(mso);
                }
                outputFile.write(txo);
                outputFile.write(text);
                if (formatting != null)
                {
                    outputFile.write(formatting);
                }
                return;
            }

            // Create the obj record
            ObjRecord objrec = new ObjRecord(objectId, ObjRecord.EXCELNOTE);

            outputFile.write(objrec);

            // Create the mso data record.  Write the text box record again,
            // although it is already included in the SpContainer
            ClientTextBox    textBox = new ClientTextBox();
            MsoDrawingRecord msod    = new MsoDrawingRecord(textBox.getData());

            outputFile.write(msod);

            TextobjectRecord txorec = new TextobjectRecord(getText());

            outputFile.write(txorec);

            // Data for the first continue record
            byte[] textData = new byte[commentText.Length * 2 + 1];
            textData[0] = 0x1;             // unicode indicator
            StringHelper.getUnicodeBytes(commentText, textData, 1);
            //StringHelper.getBytes(commentText, textData, 1);
            ContinueRecord textContinue = new ContinueRecord(textData);

            outputFile.write(textContinue);

            // Data for the formatting runs

            byte[] frData = new byte[16];

            // First txo run (the user)
            IntegerHelper.getTwoBytes(0, frData, 0);           // index to the first character
            IntegerHelper.getTwoBytes(0, frData, 2);           // index to the font(default)
            // Mandatory last txo run
            IntegerHelper.getTwoBytes(commentText.Length, frData, 8);
            IntegerHelper.getTwoBytes(0, frData, 10);           // index to the font(default)

            ContinueRecord frContinue = new ContinueRecord(frData);

            outputFile.write(frContinue);
        }
コード例 #2
0
ファイル: CheckBox.cs プロジェクト: morninn/PetSof
        /**
         * Copy constructor used to copy drawings from read to write
         *
         * @param dgo the drawing group object
         * @param dg the drawing group
         * @param ws the workbook settings
         */
        public CheckBox(DrawingGroupObject dgo,
                        DrawingGroup dg,
                        WorkbookSettings ws)
        {
            CheckBox d = (CheckBox)dgo;

            Assert.verify(d.origin == Origin.READ);
            msoDrawingRecord = d.msoDrawingRecord;
            objRecord        = d.objRecord;
            initialized      = false;
            origin           = Origin.READ;
            drawingData      = d.drawingData;
            drawingGroup     = dg;
            drawingNumber    = d.drawingNumber;
            drawingGroup.addDrawing(this);
            mso              = d.mso;
            txo              = d.txo;
            text             = d.text;
            formatting       = d.formatting;
            workbookSettings = ws;
        }
コード例 #3
0
ファイル: Comment.cs プロジェクト: ferrinsp/kbellfireapp
        /**
         * Copy constructor used to copy drawings from read to write
         *
         * @param dgo the drawing group object
         * @param dg the drawing group
         * @param ws the workbook settings
         */
        /*protected*/
        public Comment(DrawingGroupObject dgo,
                       DrawingGroup dg,
                       WorkbookSettings ws)
        {
            Comment d = (Comment)dgo;

            Assert.verify(d.origin == Origin.READ);
            msoDrawingRecord = d.msoDrawingRecord;
            objRecord        = d.objRecord;
            initialized      = false;
            origin           = Origin.READ;
            drawingData      = d.drawingData;
            drawingGroup     = dg;
            drawingNumber    = d.drawingNumber;
            drawingGroup.addDrawing(this);
            mso              = d.mso;
            txo              = d.txo;
            text             = d.text;
            formatting       = d.formatting;
            note             = d.note;
            width            = d.width;
            height           = d.height;
            workbookSettings = ws;
        }
コード例 #4
0
ファイル: CheckBox.cs プロジェクト: morninn/PetSof
 /**
  * Sets the text object
  *
  * @param t the text object record
  */
 public virtual void setTextobject(TextobjectRecord t)
 {
     txo = t;
 }
コード例 #5
0
        /**
         * Writes out the additional comment records
         *
         * @param outputFile the output file
         * @exception IOException
         */
        public virtual void writeAdditionalRecords(File outputFile)
        {
            if (origin == Origin.READ)
                {
                outputFile.write(objRecord);

                if (mso != null)
                    outputFile.write(mso);
                outputFile.write(txo);
                outputFile.write(text);
                if (formatting != null)
                    outputFile.write(formatting);
                return;
                }

            // Create the obj record
            ObjRecord objrec = new ObjRecord(objectId,ObjRecord.EXCELNOTE);

            outputFile.write(objrec);

            // Create the mso data record.  Write the text box record again,
            // although it is already included in the SpContainer
            ClientTextBox textBox = new ClientTextBox();
            MsoDrawingRecord msod = new MsoDrawingRecord(textBox.getData());
            outputFile.write(msod);

            TextobjectRecord txorec = new TextobjectRecord(getText());
            outputFile.write(txorec);

            // Data for the first continue record
            byte[] textData = new byte[commentText.Length * 2 + 1];
            textData[0] = 0x1; // unicode indicator
            StringHelper.getUnicodeBytes(commentText,textData,1);
            //StringHelper.getBytes(commentText, textData, 1);
            ContinueRecord textContinue = new ContinueRecord(textData);
            outputFile.write(textContinue);

            // Data for the formatting runs

            byte[] frData = new byte[16];

            // First txo run (the user)
            IntegerHelper.getTwoBytes(0,frData,0); // index to the first character
            IntegerHelper.getTwoBytes(0,frData,2); // index to the font(default)
            // Mandatory last txo run
            IntegerHelper.getTwoBytes(commentText.Length,frData,8);
            IntegerHelper.getTwoBytes(0,frData,10); // index to the font(default)

            ContinueRecord frContinue = new ContinueRecord(frData);
            outputFile.write(frContinue);
        }
コード例 #6
0
 /**
  * Sets the text object
  *
  * @param t the text object
  */
 public virtual void setTextobject(TextobjectRecord t)
 {
     txo = t;
 }
コード例 #7
0
 /**
  * Copy constructor used to copy drawings from read to write
  *
  * @param dgo the drawing group object
  * @param dg the drawing group
  * @param ws the workbook settings
  */
 /*protected*/
 public Comment(DrawingGroupObject dgo,
     DrawingGroup dg,
     WorkbookSettings ws)
 {
     Comment d = (Comment)dgo;
     Assert.verify(d.origin == Origin.READ);
     msoDrawingRecord = d.msoDrawingRecord;
     objRecord = d.objRecord;
     initialized = false;
     origin = Origin.READ;
     drawingData = d.drawingData;
     drawingGroup = dg;
     drawingNumber = d.drawingNumber;
     drawingGroup.addDrawing(this);
     mso = d.mso;
     txo = d.txo;
     text = d.text;
     formatting = d.formatting;
     note = d.note;
     width = d.width;
     height = d.height;
     workbookSettings = ws;
 }
コード例 #8
0
 /**
  * Copy constructor used to copy drawings from read to write
  *
  * @param dgo the drawing group object
  * @param dg the drawing group
  * @param ws the workbook settings
  */
 public Button(DrawingGroupObject dgo,
     DrawingGroup dg,
     WorkbookSettings ws)
 {
     Button d = (Button)dgo;
     Assert.verify(d.origin == Origin.READ);
     msoDrawingRecord = d.msoDrawingRecord;
     objRecord = d.objRecord;
     initialized = false;
     origin = Origin.READ;
     drawingData = d.drawingData;
     drawingGroup = dg;
     drawingNumber = d.drawingNumber;
     drawingGroup.addDrawing(this);
     mso = d.mso;
     txo = d.txo;
     text = d.text;
     formatting = d.formatting;
     workbookSettings = ws;
 }
コード例 #9
0
        /**
         * Reads in the object record
         *
         * @param objRecord the obj record
         * @param msoRecord the mso drawing record read in earlier
         * @param comments the hash map of comments
         */
        private void handleobjectRecord(ObjRecord objRecord,MsoDrawingRecord msoRecord,Dictionary<uint,Comment> comments)
        {
            if (msoRecord == null)
                {
                //logger.warn("object record is not associated with a drawing record - ignoring");
                return;
                }

            try
                {
                // Handle images
                if (objRecord.getType() == ObjRecord.PICTURE)
                    {
                    if (drawingData == null)
                        {
                        drawingData = new DrawingData();
                        }

                    Drawing drawing = new Drawing(msoRecord,
                                                  objRecord,
                                                  drawingData,
                                                  workbook.getDrawingGroup(),
                                                  sheet);
                    drawings.Add(drawing);
                    return;
                    }

                // Handle comments
                if (objRecord.getType() == ObjRecord.EXCELNOTE)
                    {
                    if (drawingData == null)
                        drawingData = new DrawingData();

                    Comment comment = new Comment(msoRecord,
                                                  objRecord,
                                                  drawingData,
                                                  workbook.getDrawingGroup(),
                                                  workbookSettings);

                    // Sometimes Excel writes out Continue records instead of drawing
                    // records, so forcibly hack all of these into a drawing record
                    Record r2 = excelFile.next();
                    if (r2.getType() == Type.MSODRAWING || r2.getType() == Type.CONTINUE)
                        {
                        MsoDrawingRecord mso = new MsoDrawingRecord(r2);
                        comment.addMso(mso);
                        r2 = excelFile.next();
                        }
                    Assert.verify(r2.getType() == Type.TXO);
                    TextobjectRecord txo = new TextobjectRecord(r2);
                    comment.setTextobject(txo);

                    r2 = excelFile.next();
                    Assert.verify(r2.getType() == Type.CONTINUE);
                    ContinueRecord text = new ContinueRecord(r2);
                    comment.setText(text);

                    r2 = excelFile.next();
                    if (r2.getType() == Type.CONTINUE)
                        {
                        ContinueRecord formatting = new ContinueRecord(r2);
                        comment.setFormatting(formatting);
                        }

                    comments.Add(comment.getObjectId(), comment);
                    return;
                    }

                // Handle combo boxes
                if (objRecord.getType() == ObjRecord.COMBOBOX)
                    {
                    if (drawingData == null)
                        {
                        drawingData = new DrawingData();
                        }

                    ComboBox comboBox = new ComboBox(msoRecord,
                                                     objRecord,
                                                     drawingData,
                                                     workbook.getDrawingGroup(),
                                                     workbookSettings);
                    drawings.Add(comboBox);
                    return;
                    }

                // Handle check boxes
                if (objRecord.getType() == ObjRecord.CHECKBOX)
                    {
                    if (drawingData == null)
                        {
                        drawingData = new DrawingData();
                        }

                    CheckBox checkBox = new CheckBox(msoRecord,
                                                     objRecord,
                                                     drawingData,
                                                     workbook.getDrawingGroup(),
                                                     workbookSettings);

                    Record r2 = excelFile.next();
                    Assert.verify(r2.getType() == Type.MSODRAWING ||
                                  r2.getType() == Type.CONTINUE);
                    if (r2.getType() == Type.MSODRAWING || r2.getType() == Type.CONTINUE)
                        {
                        MsoDrawingRecord mso = new MsoDrawingRecord(r2);
                        checkBox.addMso(mso);
                        r2 = excelFile.next();
                        }

                    Assert.verify(r2.getType() == Type.TXO);
                    TextobjectRecord txo = new TextobjectRecord(r2);
                    checkBox.setTextobject(txo);

                    if (txo.getTextLength() == 0)
                        {
                        return;
                        }

                    r2 = excelFile.next();
                    Assert.verify(r2.getType() == Type.CONTINUE);
                    ContinueRecord text = new ContinueRecord(r2);
                    checkBox.setText(text);

                    r2 = excelFile.next();
                    if (r2.getType() == Type.CONTINUE)
                        {
                        ContinueRecord formatting = new ContinueRecord(r2);
                        checkBox.setFormatting(formatting);
                        }

                    drawings.Add(checkBox);

                    return;
                    }

                // Handle form buttons
                if (objRecord.getType() == ObjRecord.BUTTON)
                    {
                    if (drawingData == null)
                        {
                        drawingData = new DrawingData();
                        }

                    Button button = new Button(msoRecord,
                                               objRecord,
                                               drawingData,
                                               workbook.getDrawingGroup(),
                                               workbookSettings);

                    Record r2 = excelFile.next();
                    Assert.verify(r2.getType() == Type.MSODRAWING ||
                                  r2.getType() == Type.CONTINUE);
                    if (r2.getType() == Type.MSODRAWING ||
                        r2.getType() == Type.CONTINUE)
                        {
                        MsoDrawingRecord mso = new MsoDrawingRecord(r2);
                        button.addMso(mso);
                        r2 = excelFile.next();
                        }

                    Assert.verify(r2.getType() == Type.TXO);
                    TextobjectRecord txo = new TextobjectRecord(r2);
                    button.setTextobject(txo);

                    r2 = excelFile.next();
                    Assert.verify(r2.getType() == Type.CONTINUE);
                    ContinueRecord text = new ContinueRecord(r2);
                    button.setText(text);

                    r2 = excelFile.next();
                    if (r2.getType() == Type.CONTINUE)
                        {
                        ContinueRecord formatting = new ContinueRecord(r2);
                        button.setFormatting(formatting);
                        }

                    drawings.Add(button);

                    return;
                    }

                // Non-supported types which have multiple record types
                if (objRecord.getType() == ObjRecord.TEXT)
                    {
                    //logger.warn(objRecord.getType() + " object on sheet \"" +
                    //            sheet.getName() +
                    //            "\" not supported - omitting");

                    // Still need to add the drawing data to preserve the hierarchy
                    if (drawingData == null)
                        {
                        drawingData = new DrawingData();

                        }
                    drawingData.addData(msoRecord.getData());

                    Record r2 = excelFile.next();
                    Assert.verify(r2.getType() == Type.MSODRAWING ||
                                  r2.getType() == Type.CONTINUE);
                    if (r2.getType() == Type.MSODRAWING ||
                        r2.getType() == Type.CONTINUE)
                        {
                        MsoDrawingRecord mso = new MsoDrawingRecord(r2);
                        drawingData.addRawData(mso.getData());
                        r2 = excelFile.next();
                        }

                    Assert.verify(r2.getType() == Type.TXO);

                    if (workbook.getDrawingGroup() != null) // can be null for Excel 95
                        {
                        workbook.getDrawingGroup().setDrawingsOmitted(msoRecord,
                                                                      objRecord);
                        }

                    return;
                    }

                // Handle other types
                if (objRecord.getType() != ObjRecord.CHART)
                    {
                    //logger.warn(objRecord.getType() + " object on sheet \"" +
                    //            sheet.getName() +
                    //            "\" not supported - omitting");

                    // Still need to add the drawing data to preserve the hierarchy
                    if (drawingData == null)
                        {
                        drawingData = new DrawingData();
                        }

                    drawingData.addData(msoRecord.getData());

                    if (workbook.getDrawingGroup() != null) // can be null for Excel 95
                        {
                        workbook.getDrawingGroup().setDrawingsOmitted(msoRecord,
                                                                      objRecord);
                        }

                    return;
                    }
                }
            catch (DrawingDataException e)
                {
                //logger.warn(e.Message + "...disabling drawings for the remainder of the workbook");
                workbookSettings.setDrawingsDisabled(true);
                }
        }