/** * Initialization */ private void initialize() { EscherRecordData er = new EscherRecordData(this, 0); Assert.verify(er.isContainer()); EscherContainer dgContainer = new EscherContainer(er); EscherRecord[] children = dgContainer.getChildren(); children = dgContainer.getChildren(); // Dg dg = (Dg) children[0]; EscherContainer spgrContainer = null; for (int i = 0; i < children.Length && spgrContainer == null; i++) { EscherRecord child = children[i]; if (child.getType() == EscherRecordType.SPGR_CONTAINER) { spgrContainer = (EscherContainer)child; } } Assert.verify(spgrContainer != null); EscherRecord[] spgrChildren = spgrContainer.getChildren(); // See if any of the spgrChildren are SpgrContainer bool nestedContainers = false; for (int i = 0; i < spgrChildren.Length && !nestedContainers; i++) { if (spgrChildren[i].getType() == EscherRecordType.SPGR_CONTAINER) { nestedContainers = true; } } // If there are no nested containers, simply set the spContainer list // to be the list of children if (!nestedContainers) { spContainers = spgrChildren; } else { // Go through the hierarchy and dig out all the Sp containers ArrayList sps = new ArrayList(); getSpContainers(spgrContainer, sps); spContainers = new EscherRecord[sps.Count]; int pos = 0; foreach (EscherRecord record in sps) { spContainers[pos++] = record; } } initialized = true; }
/** * Display the formatted escher stream * * @exception IOException */ public void display() { EscherRecordData er = new EscherRecordData(stream, 0); EscherContainer ec = new EscherContainer(er); displayContainer(ec, 0); }
/** * Initializes the drawing data from the escher record read in */ private void initialize() { EscherRecordData er = new EscherRecordData(this, 0); Assert.verify(er.isContainer()); escherData = new EscherContainer(er); Assert.verify(escherData.getLength() == drawingData.Length); Assert.verify(escherData.getType() == EscherRecordType.DGG_CONTAINER); initialized = true; }
/** * Gets the sp container for the specified drawing number * * @param drawingNum the drawing number for which to return the spContainer * @return the spcontainer */ public EscherContainer getSpContainer(int drawingNum) { if (!initialized) { initialize(); } if ((drawingNum + 1) >= spContainers.Length) { throw new DrawingDataException(); } EscherContainer spContainer = (EscherContainer)spContainers[drawingNum + 1]; Assert.verify(spContainer != null); return(spContainer); }
/** * Gets the sp container from the internal data * * @param spgrContainer the spgr container * @param sps the list of sp records */ private void getSpContainers(EscherContainer spgrContainer, ArrayList sps) { EscherRecord[] spgrChildren = spgrContainer.getChildren(); for (int i = 0; i < spgrChildren.Length; i++) { if (spgrChildren[i].getType() == EscherRecordType.SP_CONTAINER) { sps.Add(spgrChildren[i]); } else if (spgrChildren[i].getType() == EscherRecordType.SPGR_CONTAINER) { getSpContainers((EscherContainer)spgrChildren[i], sps); } else { //logger.warn("Spgr Containers contains a record other than Sp/Spgr containers"); } } }
/** * Initializes the member variables from the Escher stream data */ private void initialize() { readSpContainer = drawingData.getSpContainer(drawingNumber); Assert.verify(readSpContainer != null); EscherRecord[] children = readSpContainer.getChildren(); Sp sp = (Sp)readSpContainer.getChildren()[0]; objectId = objRecord.getObjectId(); shapeId = sp.getShapeId(); type = ShapeType.getType(sp.getShapeType()); if (type == ShapeType.UNKNOWN) { //logger.warn("Unknown shape type"); } ClientAnchor clientAnchor = null; for (int i = 0; i < children.Length && clientAnchor == null; i++) { if (children[i].getType() == EscherRecordType.CLIENT_ANCHOR) { clientAnchor = (ClientAnchor)children[i]; } } if (clientAnchor == null) { //logger.warn("client anchor not found"); } else { column = (int)clientAnchor.getX1() - 1; row = (int)clientAnchor.getY1() + 1; width = clientAnchor.getX2() - clientAnchor.getX1(); height = clientAnchor.getY2() - clientAnchor.getY1(); } initialized = true; }
/** * Creates the main Sp container for the drawing * * @return the SP container */ public EscherContainer getSpContainer() { if (!initialized) { initialize(); } if (origin == Origin.READ) { return(getReadSpContainer()); } if (spContainer == null) { spContainer = new SpContainer(); Sp sp = new Sp(type, shapeId, 2560); spContainer.add(sp); Opt opt = new Opt(); opt.addProperty(344, false, false, 0); // ? opt.addProperty(385, false, false, 134217808); // fill colour opt.addProperty(387, false, false, 134217808); // background colour opt.addProperty(959, false, false, 131074); // hide spContainer.add(opt); ClientAnchor clientAnchor = new ClientAnchor(column + 1.3, System.Math.Max(0, row - 0.6), column + 1.3 + width, row + height, 0x1); spContainer.add(clientAnchor); ClientData clientData = new ClientData(); spContainer.add(clientData); ClientTextBox clientTextBox = new ClientTextBox(); spContainer.add(clientTextBox); } return(spContainer); }
/** * Displays the escher container as text * * @param ec the escher container * @param level the indent level * @exception IOException */ private void displayContainer(EscherContainer ec, int level) { displayRecord(ec, level); // Display the contents of the container level++; EscherRecord[] children = ec.getChildren(); for (int i = 0; i < children.Length; i++) { EscherRecord er = children[i]; if (er.getEscherData().isContainer()) { displayContainer((EscherContainer)er, level); } else { displayRecord(er, level); } } }
/** * Copy constructor * Uses a shallow copy for most things, since as soon as anything * is changed, the drawing group is invalidated and all the data blocks * regenerated * * @param dg the drawing group to copy */ public DrawingGroup(DrawingGroup dg) { drawingData = dg.drawingData; escherData = dg.escherData; bstoreContainer = dg.bstoreContainer; initialized = dg.initialized; drawingData = dg.drawingData; escherData = dg.escherData; bstoreContainer = dg.bstoreContainer; numBlips = dg.numBlips; numCharts = dg.numCharts; drawingGroupId = dg.drawingGroupId; drawingsOmitted = dg.drawingsOmitted; origin = dg.origin; // imageFiles = (HashMap)dg.imageFiles.clone(); imageFiles = new Dictionary <string, Drawing>(dg.imageFiles); maxobjectId = dg.maxobjectId; maxShapeId = dg.maxShapeId; // Create this as empty, because all drawings will get added later // as part of the sheet copy process drawings = new ArrayList(); }
/** * Creates the main Sp container for the drawing * * @return the SP container */ public EscherContainer getSpContainer() { if (!initialized) { initialize(); } if (origin == Origin.READ) { return getReadSpContainer(); } if (spContainer == null) { spContainer = new SpContainer(); Sp sp = new Sp(type,shapeId,2560); spContainer.add(sp); Opt opt = new Opt(); opt.addProperty(344,false,false,0); // ? opt.addProperty(385,false,false,134217808); // fill colour opt.addProperty(387,false,false,134217808); // background colour opt.addProperty(959,false,false,131074); // hide spContainer.add(opt); ClientAnchor clientAnchor = new ClientAnchor(column + 1.3, System.Math.Max(0,row - 0.6), column + 1.3 + width, row + height, 0x1); spContainer.add(clientAnchor); ClientData clientData = new ClientData(); spContainer.add(clientData); ClientTextBox clientTextBox = new ClientTextBox(); spContainer.add(clientTextBox); } return spContainer; }
/** * Initializes the member variables from the Escher stream data */ private void initialize() { readSpContainer = drawingData.getSpContainer(drawingNumber); Assert.verify(readSpContainer != null); EscherRecord[] children = readSpContainer.getChildren(); Sp sp = (Sp)readSpContainer.getChildren()[0]; shapeId = sp.getShapeId(); objectId = objRecord.getObjectId(); type = ShapeType.getType(sp.getShapeType()); if (type == ShapeType.UNKNOWN) { //logger.warn("Unknown shape type"); } Opt opt = (Opt)readSpContainer.getChildren()[1]; if (opt.getProperty(260) != null) blipId = opt.getProperty(260).value; if (opt.getProperty(261) != null) imageFile = new System.IO.FileInfo(opt.getProperty(261).StringValue); else { if (type == ShapeType.PICTURE_FRAME) { //logger.warn("no filename property for drawing"); imageFile = new System.IO.FileInfo(blipId.ToString().Trim()); } } ClientAnchor clientAnchor = null; for (int i = 0; i < children.Length && clientAnchor == null; i++) { if (children[i].getType() == EscherRecordType.CLIENT_ANCHOR) clientAnchor = (ClientAnchor)children[i]; } if (clientAnchor == null) { //logger.warn("client anchor not found"); } else { x = clientAnchor.getX1(); y = clientAnchor.getY1(); width = clientAnchor.getX2() - x; height = clientAnchor.getY2() - y; imageAnchorProperties = ImageAnchorProperties.getImageAnchorProperties(clientAnchor.getProperties()); } if (blipId == 0) { //logger.warn("linked drawings are not supported"); } initialized = true; }
/** * Gets the sp container from the internal data * * @param spgrContainer the spgr container * @param sps the list of sp records */ private void getSpContainers(EscherContainer spgrContainer,ArrayList sps) { EscherRecord[] spgrChildren = spgrContainer.getChildren(); for (int i = 0; i < spgrChildren.Length; i++) { if (spgrChildren[i].getType() == EscherRecordType.SP_CONTAINER) { sps.Add(spgrChildren[i]); } else if (spgrChildren[i].getType() == EscherRecordType.SPGR_CONTAINER) { getSpContainers((EscherContainer)spgrChildren[i],sps); } else { //logger.warn("Spgr Containers contains a record other than Sp/Spgr containers"); } } }
/** * Initialization */ private void initialize() { EscherRecordData er = new EscherRecordData(this,0); Assert.verify(er.isContainer()); EscherContainer dgContainer = new EscherContainer(er); EscherRecord[] children = dgContainer.getChildren(); children = dgContainer.getChildren(); // Dg dg = (Dg) children[0]; EscherContainer spgrContainer = null; for (int i = 0; i < children.Length && spgrContainer == null; i++) { EscherRecord child = children[i]; if (child.getType() == EscherRecordType.SPGR_CONTAINER) { spgrContainer = (EscherContainer)child; } } Assert.verify(spgrContainer != null); EscherRecord[] spgrChildren = spgrContainer.getChildren(); // See if any of the spgrChildren are SpgrContainer bool nestedContainers = false; for (int i = 0; i < spgrChildren.Length && !nestedContainers; i++) { if (spgrChildren[i].getType() == EscherRecordType.SPGR_CONTAINER) { nestedContainers = true; } } // If there are no nested containers, simply set the spContainer list // to be the list of children if (!nestedContainers) spContainers = spgrChildren; else { // Go through the hierarchy and dig out all the Sp containers ArrayList sps = new ArrayList(); getSpContainers(spgrContainer,sps); spContainers = new EscherRecord[sps.Count]; int pos = 0; foreach (EscherRecord record in sps) spContainers[pos++] = record; } initialized = true; }
/** * Gets the SpContainer containing the charts drawing information * * @return the spContainer */ public EscherContainer getSpContainer() { EscherContainer spContainer = drawingData.getSpContainer(drawingNumber); return(spContainer); }
/** * Initializes the member variables from the Escher stream data */ private void initialize() { readSpContainer = drawingData.getSpContainer(drawingNumber); Assert.verify(readSpContainer != null); EscherRecord[] children = readSpContainer.getChildren(); Sp sp = (Sp)readSpContainer.getChildren()[0]; shapeId = sp.getShapeId(); objectId = objRecord.getObjectId(); type = ShapeType.getType(sp.getShapeType()); if (type == ShapeType.UNKNOWN) { //logger.warn("Unknown shape type"); } Opt opt = (Opt)readSpContainer.getChildren()[1]; if (opt.getProperty(260) != null) { blipId = opt.getProperty(260).value; } if (opt.getProperty(261) != null) { imageFile = new System.IO.FileInfo(opt.getProperty(261).StringValue); } else { if (type == ShapeType.PICTURE_FRAME) { //logger.warn("no filename property for drawing"); imageFile = new System.IO.FileInfo(blipId.ToString().Trim()); } } ClientAnchor clientAnchor = null; for (int i = 0; i < children.Length && clientAnchor == null; i++) { if (children[i].getType() == EscherRecordType.CLIENT_ANCHOR) { clientAnchor = (ClientAnchor)children[i]; } } if (clientAnchor == null) { //logger.warn("client anchor not found"); } else { x = clientAnchor.getX1(); y = clientAnchor.getY1(); width = clientAnchor.getX2() - x; height = clientAnchor.getY2() - y; imageAnchorProperties = ImageAnchorProperties.getImageAnchorProperties(clientAnchor.getProperties()); } if (blipId == 0) { //logger.warn("linked drawings are not supported"); } initialized = true; }
/** * Writes out the MsoDrawing records and Obj records for each image * and chart on the sheet * * @param outputFile the output file * @exception IOException */ public void write(File outputFile) { // If there are no drawings or charts on this sheet then exit if (drawings.Count == 0 && charts.Length == 0) { return; } // See if any drawing has been modified bool modified = drawingsModified; int numImages = drawings.Count; foreach (DrawingGroupObject d in drawings) { if (d.getOrigin() != Origin.READ) { modified = true; } } // If the drawing order has been muddled at all, then we'll need // to regenerate the Escher drawing data if (numImages > 0 && !modified) { DrawingGroupObject d2 = (DrawingGroupObject)drawings[0]; if (!d2.isFirst()) { modified = true; } } // Check to see if this sheet consists of just a single chart. If so // there is no MsoDrawingRecord, so write out the data and exit if (numImages == 0 && charts.Length == 1 && charts[0].getMsoDrawingRecord() == null) { modified = false; // this sheet has not been modified } // If no drawing has been modified, then simply write them straight out // again and exit if (!modified) { writeUnmodified(outputFile); return; } object[] spContainerData = new object[numImages + charts.Length]; int length = 0; EscherContainer firstSpContainer = null; // Get all the spContainer byte data from the drawings // and store in an array for (int i = 0; i < numImages; i++) { DrawingGroupObject drawing = (DrawingGroupObject)drawings[i]; EscherContainer spc = drawing.getSpContainer(); if (spc != null) { byte[] data = spc.getData(); spContainerData[i] = data; if (i == 0) { firstSpContainer = spc; } else { length += data.Length; } } } // Get all the spContainer bytes from the charts and add to the array for (int i = 0; i < charts.Length; i++) { EscherContainer spContainer = charts[i].getSpContainer(); byte[] data = spContainer.getBytes(); //use getBytes instead of getData data = spContainer.setHeaderData(data); spContainerData[i + numImages] = data; if (i == 0 && numImages == 0) { firstSpContainer = spContainer; } else { length += data.Length; } } // Put the generalised stuff around the first item DgContainer dgContainer = new DgContainer(); Dg dg = new Dg(numImages + charts.Length); dgContainer.add(dg); SpgrContainer spgrContainer = new SpgrContainer(); SpContainer _spContainer = new SpContainer(); Spgr spgr = new Spgr(); _spContainer.add(spgr); Sp sp = new Sp(ShapeType.MIN, 1024, 5); _spContainer.add(sp); spgrContainer.add(_spContainer); spgrContainer.add(firstSpContainer); dgContainer.add(spgrContainer); byte[] firstMsoData = dgContainer.getData(); // Adjust the length of the DgContainer int len = IntegerHelper.getInt(firstMsoData[4], firstMsoData[5], firstMsoData[6], firstMsoData[7]); IntegerHelper.getFourBytes(len + length, firstMsoData, 4); // Adjust the length of the SpgrContainer len = IntegerHelper.getInt(firstMsoData[28], firstMsoData[29], firstMsoData[30], firstMsoData[31]); IntegerHelper.getFourBytes(len + length, firstMsoData, 28); // Now write out each MsoDrawing record // First MsoRecord // test hack for form objects, to remove the ClientTextBox record // from the end of the SpContainer if (numImages > 0 && ((DrawingGroupObject)drawings[0]).isFormObject()) { byte[] msodata2 = new byte[firstMsoData.Length - 8]; System.Array.Copy(firstMsoData, 0, msodata2, 0, msodata2.Length); firstMsoData = msodata2; } MsoDrawingRecord msoDrawingRecord = new MsoDrawingRecord(firstMsoData); outputFile.write(msoDrawingRecord); if (numImages > 0) { DrawingGroupObject firstDrawing = (DrawingGroupObject)drawings[0]; firstDrawing.writeAdditionalRecords(outputFile); } else { // first image is a chart Chart chart = charts[0]; ObjRecord objRecord = chart.getObjRecord(); outputFile.write(objRecord); outputFile.write(chart); } // Now do all the others for (int i = 1; i < spContainerData.Length; i++) { byte[] bytes = (byte[])spContainerData[i]; // test hack for form objects, to remove the ClientTextBox record // from the end of the SpContainer if (i < numImages && ((DrawingGroupObject)drawings[i]).isFormObject()) { byte[] bytes2 = new byte[bytes.Length - 8]; System.Array.Copy(bytes, 0, bytes2, 0, bytes2.Length); bytes = bytes2; } msoDrawingRecord = new MsoDrawingRecord(bytes); outputFile.write(msoDrawingRecord); if (i < numImages) { // Write anything else the object needs DrawingGroupObject d = (DrawingGroupObject)drawings[i]; d.writeAdditionalRecords(outputFile); } else { Chart chart = charts[i - numImages]; ObjRecord objRecord = chart.getObjRecord(); outputFile.write(objRecord); outputFile.write(chart); } } // Write any tail records that need to be written foreach (DrawingGroupObject dgo2 in drawings) { dgo2.writeTailRecords(outputFile); } }
/** * Initializes the member variables from the Escher stream data */ private void initialize() { readSpContainer = drawingData.getSpContainer(drawingNumber); Assert.verify(readSpContainer != null); EscherRecord[] children = readSpContainer.getChildren(); Sp sp = (Sp)readSpContainer.getChildren()[0]; objectId = objRecord.getObjectId(); shapeId = sp.getShapeId(); type = ShapeType.getType(sp.getShapeType()); if (type == ShapeType.UNKNOWN) { //logger.warn("Unknown shape type"); } ClientAnchor clientAnchor = null; for (int i = 0; i < children.Length && clientAnchor == null; i++) { if (children[i].getType() == EscherRecordType.CLIENT_ANCHOR) clientAnchor = (ClientAnchor)children[i]; } if (clientAnchor == null) { //logger.warn("Client anchor not found"); } else { column = (int)clientAnchor.getX1(); row = (int)clientAnchor.getY1(); } initialized = true; }
/** * Writes out the drawings and the charts if nothing has been modified * * @param outputFile the output file * @exception IOException */ private void writeUnmodified(File outputFile) { if (charts.Length == 0 && drawings.Count == 0) { // No drawings or charts return; } else if (charts.Length == 0 && drawings.Count != 0) { // If there are no charts, then write out the drawings and return foreach (DrawingGroupObject d in drawings) { outputFile.write(d.getMsoDrawingRecord()); d.writeAdditionalRecords(outputFile); } foreach (DrawingGroupObject d in drawings) d.writeTailRecords(outputFile); return; } else if (drawings.Count == 0 && charts.Length != 0) { // If there are no drawings, then write out the charts and return Chart curChart = null; for (int i = 0; i < charts.Length; i++) { curChart = charts[i]; if (curChart.getMsoDrawingRecord() != null) outputFile.write(curChart.getMsoDrawingRecord()); if (curChart.getObjRecord() != null) outputFile.write(curChart.getObjRecord()); outputFile.write(curChart); } return; } // There are both charts and drawings - the output // drawing group records will need // to be re-jigged in order to write the drawings out first, then the // charts int numDrawings = drawings.Count; int length = 0; EscherContainer[] spContainers = new EscherContainer[numDrawings + charts.Length]; bool[] isFormobject = new bool[numDrawings + charts.Length]; for (int i = 0; i < numDrawings; i++) { DrawingGroupObject d = (DrawingGroupObject)drawings[i]; spContainers[i] = d.getSpContainer(); if (i > 0) length += spContainers[i].getLength(); if (d.isFormObject()) isFormobject[i] = true; } for (int i = 0; i < charts.Length; i++) { spContainers[i + numDrawings] = charts[i].getSpContainer(); length += spContainers[i + numDrawings].getLength(); } // Put the generalised stuff around the first item DgContainer dgContainer = new DgContainer(); Dg dg = new Dg(numDrawings + charts.Length); dgContainer.add(dg); SpgrContainer spgrContainer = new SpgrContainer(); SpContainer spContainer = new SpContainer(); Spgr spgr = new Spgr(); spContainer.add(spgr); Sp sp = new Sp(ShapeType.MIN,1024,5); spContainer.add(sp); spgrContainer.add(spContainer); spgrContainer.add(spContainers[0]); dgContainer.add(spgrContainer); byte[] firstMsoData = dgContainer.getData(); // Adjust the length of the DgContainer int len = IntegerHelper.getInt(firstMsoData[4], firstMsoData[5], firstMsoData[6], firstMsoData[7]); IntegerHelper.getFourBytes(len + length,firstMsoData,4); // Adjust the length of the SpgrContainer len = IntegerHelper.getInt(firstMsoData[28], firstMsoData[29], firstMsoData[30], firstMsoData[31]); IntegerHelper.getFourBytes(len + length,firstMsoData,28); // Now write out each MsoDrawing record and object record // Hack to remove the last eight bytes (text box escher record) // from the container if (isFormobject[0] == true) { byte[] cbytes = new byte[firstMsoData.Length - 8]; System.Array.Copy(firstMsoData,0,cbytes,0,cbytes.Length); firstMsoData = cbytes; } // First MsoRecord MsoDrawingRecord msoDrawingRecord = new MsoDrawingRecord(firstMsoData); outputFile.write(msoDrawingRecord); DrawingGroupObject dgo = (DrawingGroupObject)drawings[0]; dgo.writeAdditionalRecords(outputFile); // Now do all the others for (int i = 1; i < spContainers.Length; i++) { byte[] bytes = spContainers[i].getBytes(); byte[] bytes2 = spContainers[i].setHeaderData(bytes); // Hack to remove the last eight bytes (text box escher record) // from the container if (isFormobject[i] == true) { byte[] cbytes = new byte[bytes2.Length - 8]; System.Array.Copy(bytes2,0,cbytes,0,cbytes.Length); bytes2 = cbytes; } msoDrawingRecord = new MsoDrawingRecord(bytes2); outputFile.write(msoDrawingRecord); if (i < numDrawings) { dgo = (DrawingGroupObject)drawings[i]; dgo.writeAdditionalRecords(outputFile); } else { Chart chart = charts[i - numDrawings]; ObjRecord objRecord = chart.getObjRecord(); outputFile.write(objRecord); outputFile.write(chart); } } // Write any tail records that need to be written foreach (DrawingGroupObject dgo2 in drawings) dgo2.writeTailRecords(outputFile); }
/** * Writes out the drawings and the charts if nothing has been modified * * @param outputFile the output file * @exception IOException */ private void writeUnmodified(File outputFile) { if (charts.Length == 0 && drawings.Count == 0) { // No drawings or charts return; } else if (charts.Length == 0 && drawings.Count != 0) { // If there are no charts, then write out the drawings and return foreach (DrawingGroupObject d in drawings) { outputFile.write(d.getMsoDrawingRecord()); d.writeAdditionalRecords(outputFile); } foreach (DrawingGroupObject d in drawings) { d.writeTailRecords(outputFile); } return; } else if (drawings.Count == 0 && charts.Length != 0) { // If there are no drawings, then write out the charts and return Chart curChart = null; for (int i = 0; i < charts.Length; i++) { curChart = charts[i]; if (curChart.getMsoDrawingRecord() != null) { outputFile.write(curChart.getMsoDrawingRecord()); } if (curChart.getObjRecord() != null) { outputFile.write(curChart.getObjRecord()); } outputFile.write(curChart); } return; } // There are both charts and drawings - the output // drawing group records will need // to be re-jigged in order to write the drawings out first, then the // charts int numDrawings = drawings.Count; int length = 0; EscherContainer[] spContainers = new EscherContainer[numDrawings + charts.Length]; bool[] isFormobject = new bool[numDrawings + charts.Length]; for (int i = 0; i < numDrawings; i++) { DrawingGroupObject d = (DrawingGroupObject)drawings[i]; spContainers[i] = d.getSpContainer(); if (i > 0) { length += spContainers[i].getLength(); } if (d.isFormObject()) { isFormobject[i] = true; } } for (int i = 0; i < charts.Length; i++) { spContainers[i + numDrawings] = charts[i].getSpContainer(); length += spContainers[i + numDrawings].getLength(); } // Put the generalised stuff around the first item DgContainer dgContainer = new DgContainer(); Dg dg = new Dg(numDrawings + charts.Length); dgContainer.add(dg); SpgrContainer spgrContainer = new SpgrContainer(); SpContainer spContainer = new SpContainer(); Spgr spgr = new Spgr(); spContainer.add(spgr); Sp sp = new Sp(ShapeType.MIN, 1024, 5); spContainer.add(sp); spgrContainer.add(spContainer); spgrContainer.add(spContainers[0]); dgContainer.add(spgrContainer); byte[] firstMsoData = dgContainer.getData(); // Adjust the length of the DgContainer int len = IntegerHelper.getInt(firstMsoData[4], firstMsoData[5], firstMsoData[6], firstMsoData[7]); IntegerHelper.getFourBytes(len + length, firstMsoData, 4); // Adjust the length of the SpgrContainer len = IntegerHelper.getInt(firstMsoData[28], firstMsoData[29], firstMsoData[30], firstMsoData[31]); IntegerHelper.getFourBytes(len + length, firstMsoData, 28); // Now write out each MsoDrawing record and object record // Hack to remove the last eight bytes (text box escher record) // from the container if (isFormobject[0] == true) { byte[] cbytes = new byte[firstMsoData.Length - 8]; System.Array.Copy(firstMsoData, 0, cbytes, 0, cbytes.Length); firstMsoData = cbytes; } // First MsoRecord MsoDrawingRecord msoDrawingRecord = new MsoDrawingRecord(firstMsoData); outputFile.write(msoDrawingRecord); DrawingGroupObject dgo = (DrawingGroupObject)drawings[0]; dgo.writeAdditionalRecords(outputFile); // Now do all the others for (int i = 1; i < spContainers.Length; i++) { byte[] bytes = spContainers[i].getBytes(); byte[] bytes2 = spContainers[i].setHeaderData(bytes); // Hack to remove the last eight bytes (text box escher record) // from the container if (isFormobject[i] == true) { byte[] cbytes = new byte[bytes2.Length - 8]; System.Array.Copy(bytes2, 0, cbytes, 0, cbytes.Length); bytes2 = cbytes; } msoDrawingRecord = new MsoDrawingRecord(bytes2); outputFile.write(msoDrawingRecord); if (i < numDrawings) { dgo = (DrawingGroupObject)drawings[i]; dgo.writeAdditionalRecords(outputFile); } else { Chart chart = charts[i - numDrawings]; ObjRecord objRecord = chart.getObjRecord(); outputFile.write(objRecord); outputFile.write(chart); } } // Write any tail records that need to be written foreach (DrawingGroupObject dgo2 in drawings) { dgo2.writeTailRecords(outputFile); } }