/** * Writes out the list of integer values. If there are more than three, * a MulRK record is used, otherwise a sequence of Numbers is used * * @exception IOException * @param outputFile the output file * @param integerValues the array of integer values */ private void writeIntegerValues(ArrayList integerValues, File outputFile) { if (integerValues.Count == 0) { return; } if (integerValues.Count >= 3) { // Write out as a MulRK record MulRKRecord mulrk = new MulRKRecord(integerValues); outputFile.write(mulrk); } else { // Write out as number records foreach (CellValue cv in integerValues) { outputFile.write(cv); } } // Clear out the list of integerValues integerValues.Clear(); }
/** * Writes out all the cells in this row. If more than three integer * values occur consecutively, then a MulRK record is used to group the * numbers * * @exception IOException * @param outputFile the output file */ public void writeCells(File outputFile) { // This is the list for integer values ArrayList integerValues = new ArrayList(); bool integerValue = false; // Write out all the records for (int i = 0; i < numColumns; i++) { integerValue = false; if (cells[i] != null) { // See if this cell is a 30-bit integer value (without additional // cell features) if (cells[i].getType() == CellType.NUMBER) { Number nc = (Number)cells[i]; if (nc.getValue() == (int)nc.getValue() && nc.getValue() < maxRKValue && nc.getValue() > minRKValue && nc.getCellFeatures() == null) { integerValue = true; } } if (integerValue) { // This cell is an integer, add it to the list integerValues.Add(cells[i]); } else { // This cell is not an integer. Write out whatever integers we // have, and then write out this cell writeIntegerValues(integerValues, outputFile); outputFile.write(cells[i]); // If the cell is a string formula, write out the string record // immediately afterwards if (cells[i].getType() == CellType.STRING_FORMULA) { StringRecord sr = new StringRecord(cells[i].getContents()); outputFile.write(sr); } } } else { // Cell does not exist. Write out the list of integers that // we have writeIntegerValues(integerValues, outputFile); } } // All done. Write out any remaining integer values writeIntegerValues(integerValues, outputFile); }
/** * Writes out the shared string table * * @param outputFile the binary output file * @exception IOException */ public void write(File outputFile) { // Thanks to Guenther for contributing the ExtSST implementation portion // of this method int charsLeft = 0; string curString = null; SSTRecord sst = new SSTRecord(totalOccurrences, stringList.Count); ExtendedSSTRecord extsst = new ExtendedSSTRecord(stringList.Count); int bucketSize = extsst.getNumberOfStringsPerBucket(); int stringIndex = 0; // CML: this one is nasty.... IEnumerator iterator = stringList.GetEnumerator(); while (iterator.MoveNext() && charsLeft == 0) { curString = (string)iterator.Current; // offset + header bytes int relativePosition = sst.getOffset() + 4; charsLeft = sst.add(curString); if ((stringIndex % bucketSize) == 0) { extsst.addString(outputFile.getPos(), relativePosition); } stringIndex++; } outputFile.write(sst); if (charsLeft != 0 || iterator.MoveNext()) { // Add the remainder of the string to the continue record SSTContinueRecord cont = createContinueRecord(curString, charsLeft, outputFile); // Carry on looping through the array until all the strings are done do { curString = (string)iterator.Current; int relativePosition = cont.getOffset() + 4; charsLeft = cont.add(curString); if ((stringIndex % bucketSize) == 0) { extsst.addString(outputFile.getPos(), relativePosition); } stringIndex++; if (charsLeft != 0) { outputFile.write(cont); cont = createContinueRecord(curString, charsLeft, outputFile); } }while (iterator.MoveNext()); outputFile.write(cont); } outputFile.write(extsst); }
/** * Creates and returns a continue record using the left over bits and * pieces */ private SSTContinueRecord createContinueRecord (string curString, int charsLeft, File outputFile) { // Set up the remainder of the string in the continue record SSTContinueRecord cont = null; while (charsLeft != 0) { cont = new SSTContinueRecord(); if (charsLeft == curString.Length || curString.Length == 0) { charsLeft = cont.setFirstString(curString, true); } else { charsLeft = cont.setFirstString (curString.Substring(curString.Length - charsLeft), false); } if (charsLeft != 0) { outputFile.write(cont); cont = new SSTContinueRecord(); } } return(cont); }
/** * Writes out the data validation * * @exception IOException * @param outputFile the output file */ public void write(File outputFile) { if (filterMode != null) { outputFile.write(filterMode); } if (autoFilterInfo != null) { outputFile.write(autoFilterInfo); } if (autoFilter != null) { outputFile.write(autoFilter); } }
/** * @exception IOException */ public void write(File outputFile) { if (ranges.Count == 0) { return; } WorkbookSettings ws = ((WritableSheetImpl)sheet).getWorkbookSettings(); if (!ws.getMergedCellCheckingDisabled()) { checkIntersections(); checkRanges(); } // If they will all fit into one record, then create a single // record, write them and get out if (ranges.Count < maxRangesPerSheet) { MergedCellsRecord mcr = new MergedCellsRecord(ranges); outputFile.write(mcr); return; } int numRecordsRequired = ranges.Count / maxRangesPerSheet + 1; int pos = 0; for (int i = 0; i < numRecordsRequired; i++) { int numranges = System.Math.Min(maxRangesPerSheet, ranges.Count - pos); ArrayList cells = new ArrayList(numranges); for (int j = 0; j < numranges; j++) { cells.Add(ranges[pos + j]); } MergedCellsRecord mcr = new MergedCellsRecord(cells); outputFile.write(mcr); pos += numranges; } }
/** * Writes out the list of fonts * * @param outputFile the compound file to write the data to * @exception IOException */ public void write(File outputFile) { foreach (FontRecord font in fonts) outputFile.write(font); }
/** * Writes out this sheet. First writes out the standard sheet * information then writes out each row in turn. * Once all the rows have been written out, it retrospectively adjusts * the offset references in the file * * @exception IOException */ public void write() { Assert.verify(rows != null); // This worksheet consists of just one chart, so write it and return if (chartOnly) { drawingWriter.write(outputFile); return; } BOFRecord bof = new BOFRecord(BOFRecord.sheet); outputFile.write(bof); // Compute the number of blocks of 32 rows that will be needed int numBlocks = numRows / 32; if (numRows - numBlocks * 32 != 0) { numBlocks++; } int indexPos = outputFile.getPos(); // Write the index record out now in order to serve as a place holder // The bof passed in is the bof of the workbook, not this sheet IndexRecord indexRecord = new IndexRecord(0, numRows, numBlocks); outputFile.write(indexRecord); if (settings.getAutomaticFormulaCalculation()) { CalcModeRecord cmr = new CalcModeRecord(CalcModeRecord.automatic); outputFile.write(cmr); } else { CalcModeRecord cmr = new CalcModeRecord(CalcModeRecord.manual); outputFile.write(cmr); } CalcCountRecord ccr = new CalcCountRecord(0x64); outputFile.write(ccr); RefModeRecord rmr = new RefModeRecord(); outputFile.write(rmr); IterationRecord itr = new IterationRecord(false); outputFile.write(itr); DeltaRecord dtr = new DeltaRecord(0.001); outputFile.write(dtr); SaveRecalcRecord srr = new SaveRecalcRecord(settings.getRecalculateFormulasBeforeSave()); outputFile.write(srr); PrintHeadersRecord phr = new PrintHeadersRecord(settings.getPrintHeaders()); outputFile.write(phr); PrintGridLinesRecord pglr = new PrintGridLinesRecord(settings.getPrintGridLines()); outputFile.write(pglr); GridSetRecord gsr = new GridSetRecord(true); outputFile.write(gsr); GuttersRecord gutr = new GuttersRecord(); gutr.setMaxColumnOutline(maxColumnOutlineLevel + 1); gutr.setMaxRowOutline(maxRowOutlineLevel + 1); outputFile.write(gutr); DefaultRowHeightRecord drhr = new DefaultRowHeightRecord (settings.getDefaultRowHeight(), settings.getDefaultRowHeight() != SheetSettings.DEFAULT_DEFAULT_ROW_HEIGHT); outputFile.write(drhr); if (maxRowOutlineLevel > 0) { workspaceOptions.setRowOutlines(true); } if (maxColumnOutlineLevel > 0) { workspaceOptions.setColumnOutlines(true); } workspaceOptions.setFitToPages(settings.getFitToPages()); outputFile.write(workspaceOptions); if (rowBreaks.Count > 0) { int[] rb = new int[rowBreaks.Count]; for (int i = 0; i < rb.Length; i++) { rb[i] = (int)rowBreaks[i]; } HorizontalPageBreaksRecord hpbr = new HorizontalPageBreaksRecord(rb); outputFile.write(hpbr); } if (columnBreaks.Count > 0) { int[] rb = new int[columnBreaks.Count]; for (int i = 0; i < rb.Length; i++) { rb[i] = (int)columnBreaks[i]; } VerticalPageBreaksRecord hpbr = new VerticalPageBreaksRecord(rb); outputFile.write(hpbr); } HeaderRecord header = new HeaderRecord(settings.getHeader().ToString()); outputFile.write(header); FooterRecord footer = new FooterRecord(settings.getFooter().ToString()); outputFile.write(footer); HorizontalCentreRecord hcr = new HorizontalCentreRecord(settings.isHorizontalCentre()); outputFile.write(hcr); VerticalCentreRecord vcr = new VerticalCentreRecord(settings.isVerticalCentre()); outputFile.write(vcr); // Write out the margins if they don't equal the default if (settings.getLeftMargin() != settings.getDefaultWidthMargin()) { MarginRecord mr = new LeftMarginRecord(settings.getLeftMargin()); outputFile.write(mr); } if (settings.getRightMargin() != settings.getDefaultWidthMargin()) { MarginRecord mr = new RightMarginRecord(settings.getRightMargin()); outputFile.write(mr); } if (settings.getTopMargin() != settings.getDefaultHeightMargin()) { MarginRecord mr = new TopMarginRecord(settings.getTopMargin()); outputFile.write(mr); } if (settings.getBottomMargin() != settings.getDefaultHeightMargin()) { MarginRecord mr = new BottomMarginRecord(settings.getBottomMargin()); outputFile.write(mr); } if (plsRecord != null) { outputFile.write(plsRecord); } SetupRecord setup = new SetupRecord(settings); outputFile.write(setup); if (settings.isProtected()) { ProtectRecord pr = new ProtectRecord(settings.isProtected()); outputFile.write(pr); ScenarioProtectRecord spr = new ScenarioProtectRecord(settings.isProtected()); outputFile.write(spr); ObjectProtectRecord opr = new ObjectProtectRecord(settings.isProtected()); outputFile.write(opr); if (settings.getPassword() != null) { PasswordRecord pw = new PasswordRecord(settings.getPassword()); outputFile.write(pw); } else if (settings.getPasswordHash() != 0) { PasswordRecord pw = new PasswordRecord(settings.getPasswordHash()); outputFile.write(pw); } } indexRecord.setDataStartPosition(outputFile.getPos()); DefaultColumnWidth dcw = new DefaultColumnWidth(settings.getDefaultColumnWidth()); outputFile.write(dcw); // Get a handle to the normal styles WritableCellFormat normalStyle = sheet.getWorkbook().getStyles().getNormalStyle(); WritableCellFormat defaultDateFormat = sheet.getWorkbook().getStyles().getDefaultDateFormat(); // Write out all the column formats foreach (ColumnInfoRecord cir in columnFormats) { // Writing out the column info with index 0x100 causes excel to crash if (cir.getColumn() < 0x100) { outputFile.write(cir); } XFRecord xfr = cir.getCellFormat(); if (xfr != normalStyle && cir.getColumn() < 0x100) { // Make this the format for every cell in the column Cell[] cells = getColumn(cir.getColumn()); for (int i = 0; i < cells.Length; i++) { if (cells[i] != null && (cells[i].getCellFormat() == normalStyle || cells[i].getCellFormat() == defaultDateFormat)) { // The cell has no overriding format specified, so // set it to the column default ((WritableCell)cells[i]).setCellFormat(xfr); } } } } // Write out the auto filter if (autoFilter != null) { autoFilter.write(outputFile); } DimensionRecord dr = new DimensionRecord(numRows, numCols); outputFile.write(dr); // Write out all the rows, in blocks of 32 for (int block = 0; block < numBlocks; block++) { DBCellRecord dbcell = new DBCellRecord(outputFile.getPos()); int blockRows = System.Math.Min(32, numRows - block * 32); bool firstRow = true; // First write out all the row records for (int i = block * 32; i < block * 32 + blockRows; i++) { if (rows[i] != null) { rows[i].write(outputFile); if (firstRow) { dbcell.setCellOffset(outputFile.getPos()); firstRow = false; } } } // Now write out all the cells for (int i = block * 32; i < block * 32 + blockRows; i++) { if (rows[i] != null) { dbcell.addCellRowPosition(outputFile.getPos()); rows[i].writeCells(outputFile); } } // Now set the current file position in the index record indexRecord.addBlockPosition(outputFile.getPos()); // Set the position of the file pointer and write out the DBCell // record dbcell.setPosition(outputFile.getPos()); outputFile.write(dbcell); } // Do the drawings and charts if enabled if (!workbookSettings.getDrawingsDisabled()) { drawingWriter.write(outputFile); } Window2Record w2r = new Window2Record(settings); outputFile.write(w2r); // Handle the frozen panes if (settings.getHorizontalFreeze() != 0 || settings.getVerticalFreeze() != 0) { PaneRecord pr = new PaneRecord(settings.getHorizontalFreeze(), settings.getVerticalFreeze()); outputFile.write(pr); // Handle the selection record. First, there will always be a top left SelectionRecord sr = new SelectionRecord(SelectionRecord.upperLeft, 0, 0); outputFile.write(sr); // Top right if (settings.getHorizontalFreeze() != 0) { sr = new SelectionRecord(SelectionRecord.upperRight, settings.getHorizontalFreeze(), 0); outputFile.write(sr); } // Bottom left if (settings.getVerticalFreeze() != 0) { sr = new SelectionRecord(SelectionRecord.lowerLeft, 0, settings.getVerticalFreeze()); outputFile.write(sr); } // Bottom right if (settings.getHorizontalFreeze() != 0 && settings.getVerticalFreeze() != 0) { sr = new SelectionRecord(SelectionRecord.lowerRight, settings.getHorizontalFreeze(), settings.getVerticalFreeze()); outputFile.write(sr); } Weird1Record w1r = new Weird1Record(); outputFile.write(w1r); } else { // No frozen panes - just write out the selection record for the // whole sheet SelectionRecord sr = new SelectionRecord(SelectionRecord.upperLeft, 0, 0); outputFile.write(sr); } // Handle the zoom factor if (settings.getZoomFactor() != 100) { SCLRecord sclr = new SCLRecord(settings.getZoomFactor()); outputFile.write(sclr); } // Now write out all the merged cells mergedCells.write(outputFile); // Write out all the hyperlinks foreach (WritableHyperlink hlr in hyperlinks) { outputFile.write(hlr); } if (buttonPropertySet != null) { outputFile.write(buttonPropertySet); } // Write out the data validations if (dataValidation != null || validatedCells.Count > 0) { writeDataValidation(); } // Write out the conditional formats if (conditionalFormats != null && conditionalFormats.Count > 0) { foreach (ConditionalFormat cf in conditionalFormats) { cf.write(outputFile); } } EOFRecord eof = new EOFRecord(); outputFile.write(eof); // Now the various cross reference offsets have been calculated, // retrospectively set the values in the output file outputFile.setData(indexRecord.getData(), indexPos + 4); }
/** * Writes out the row information data (but not the individual cells) * * @exception IOException * @param outputFile the output file */ public void write(File outputFile) { outputFile.write(this); }
/** * Writes out the additional records for a combo box * * @param outputFile the output file * @exception IOException */ public virtual void writeAdditionalRecords(File outputFile) { if (origin == Origin.READ) { outputFile.write(objRecord); return; } // Create the obj record ObjRecord objrec = new ObjRecord(objectId,ObjRecord.COMBOBOX); outputFile.write(objrec); }
/** * Writes out the shared string table * * @param outputFile the binary output file * @exception IOException */ public void write(File outputFile) { // Thanks to Guenther for contributing the ExtSST implementation portion // of this method int charsLeft = 0; string curString = null; SSTRecord sst = new SSTRecord(totalOccurrences, stringList.Count); ExtendedSSTRecord extsst = new ExtendedSSTRecord(stringList.Count); int bucketSize = extsst.getNumberOfStringsPerBucket(); int stringIndex = 0; // CML: this one is nasty.... IEnumerator iterator = stringList.GetEnumerator(); while (iterator.MoveNext() && charsLeft == 0) { curString = (string)iterator.Current; // offset + header bytes int relativePosition = sst.getOffset() + 4; charsLeft = sst.add(curString); if ((stringIndex % bucketSize) == 0) extsst.addString(outputFile.getPos(), relativePosition); stringIndex++; } outputFile.write(sst); if (charsLeft != 0 || iterator.MoveNext()) { // Add the remainder of the string to the continue record SSTContinueRecord cont = createContinueRecord(curString,charsLeft,outputFile); // Carry on looping through the array until all the strings are done do { curString = (string)iterator.Current; int relativePosition = cont.getOffset() + 4; charsLeft = cont.add(curString); if ((stringIndex % bucketSize) == 0) extsst.addString(outputFile.getPos(), relativePosition); stringIndex++; if (charsLeft != 0) { outputFile.write(cont); cont = createContinueRecord(curString, charsLeft, outputFile); } } while (iterator.MoveNext()); outputFile.write(cont); } outputFile.write(extsst); }
/** * Creates and returns a continue record using the left over bits and * pieces */ private SSTContinueRecord createContinueRecord(string curString, int charsLeft, File outputFile) { // Set up the remainder of the string in the continue record SSTContinueRecord cont = null; while (charsLeft != 0) { cont = new SSTContinueRecord(); if (charsLeft == curString.Length || curString.Length == 0) { charsLeft = cont.setFirstString(curString, true); } else { charsLeft = cont.setFirstString (curString.Substring(curString.Length - charsLeft), false); } if (charsLeft != 0) { outputFile.write(cont); cont = new SSTContinueRecord(); } } return cont; }
/** * 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); }
/** * Writes any records that need to be written after all the drawing group * objects have been written * Writes out all the note records * * @param outputFile the output file * @exception IOException */ public virtual void writeTailRecords(File outputFile) { if (origin == Origin.READ) { outputFile.write(note); return; } // The note record NoteRecord noteRecord = new NoteRecord(column,row,objectId); outputFile.write(noteRecord); }
/** * 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); }
/** * Writes out the list of integer values. If there are more than three, * a MulRK record is used, otherwise a sequence of Numbers is used * * @exception IOException * @param outputFile the output file * @param integerValues the array of integer values */ private void writeIntegerValues(ArrayList integerValues, File outputFile) { if (integerValues.Count == 0) { return; } if (integerValues.Count >= 3) { // Write out as a MulRK record MulRKRecord mulrk = new MulRKRecord(integerValues); outputFile.write(mulrk); } else { // Write out as number records foreach (CellValue cv in integerValues) outputFile.write(cv); } // Clear out the list of integerValues integerValues.Clear(); }
/** * Writes out the data validation * * @exception IOException * @param outputFile the output file */ public void write(File outputFile) { if (validitySettings.Count > MAX_NO_OF_VALIDITY_SETTINGS) { //logger.warn("Maximum number of data validations exceeded - truncating..."); ArrayList oldValiditySettings = validitySettings; validitySettings = new ArrayList(MAX_NO_OF_VALIDITY_SETTINGS); for (int count = 0; count < MAX_NO_OF_VALIDITY_SETTINGS; count++) validitySettings[count] = oldValiditySettings[count]; Assert.verify(validitySettings.Count <= MAX_NO_OF_VALIDITY_SETTINGS); } if (validityList == null) { DValParser dvp = new DValParser(comboBoxObjectId,validitySettings.Count); validityList = new DataValidityListRecord(dvp); } if (!validityList.hasDVRecords()) { return; } outputFile.write(validityList); foreach (DataValiditySettingsRecord dvsr in validitySettings) outputFile.write(dvsr); }
/** * Writes out the data validation * * @exception IOException * @param outputFile the output file */ public void write(File outputFile) { outputFile.write(range); foreach (ConditionalFormatRecord cfr in conditions) outputFile.write(cfr); }
/** * 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 additional records for a combo box * * @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.CHECKBOX); outputFile.write(objrec); //logger.warn("Writing of additional records for checkboxes not implemented"); }