/** * 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); } }