/** * Constructor * * @param esf the external sheet record to copy */ public ExternalSheetRecord(CSharpJExcel.Jxl.Read.Biff.ExternalSheetRecord esf) : base(Type.EXTERNSHEET) { xtis = new ArrayList(esf.getNumRecords()); XTI xti = null; for (int i = 0; i < esf.getNumRecords(); i++) { xti = new XTI(esf.getSupbookIndex(i), esf.getFirstTabIndex(i), esf.getLastTabIndex(i)); xtis.Add(xti); } }
/** * Constructor * * @param l the length of the data * @param os the output stream to write to * @param data the excel data * @param rcf the read compound */ public CompoundFile(ExcelDataOutput data, int l, Stream os, CSharpJExcel.Jxl.Read.Biff.CompoundFile rcf) : base() { size = l; excelData = data; readAdditionalPropertySets(rcf); numRootEntryBlocks = 1; numPropertySets = 4 + (additionalPropertySets != null ? additionalPropertySets.Count : 0); if (additionalPropertySets != null) { numSmallBlockDepotChainBlocks = getBigBlocksRequired(numSmallBlocks * 4); numSmallBlockDepotBlocks = getBigBlocksRequired (numSmallBlocks * SMALL_BLOCK_SIZE); numRootEntryBlocks += getBigBlocksRequired (additionalPropertySets.Count * PROPERTY_STORAGE_BLOCK_SIZE); } int blocks = getBigBlocksRequired(l); // First pad the data outStream so that it fits nicely into a whole number // of blocks if (l < SMALL_BLOCK_THRESHOLD) requiredSize = SMALL_BLOCK_THRESHOLD; else requiredSize = blocks * BIG_BLOCK_SIZE; outStream = os; // Do the calculations excelDataBlocks = requiredSize / BIG_BLOCK_SIZE; numBigBlockDepotBlocks = 1; int blockChainLength = (BIG_BLOCK_SIZE - BIG_BLOCK_DEPOT_BLOCKS_POS) / 4; int startTotalBlocks = excelDataBlocks + 8 + // summary block 8 + // document information additionalPropertyBlocks + numSmallBlockDepotBlocks + numSmallBlockDepotChainBlocks + numRootEntryBlocks; int totalBlocks = startTotalBlocks + numBigBlockDepotBlocks; // Calculate the number of BBD blocks needed to hold this info numBigBlockDepotBlocks = (int)Math.Ceiling((double)totalBlocks / (double)(BIG_BLOCK_SIZE / 4)); // Does this affect the total? totalBlocks = startTotalBlocks + numBigBlockDepotBlocks; // And recalculate numBigBlockDepotBlocks = (int)Math.Ceiling((double)totalBlocks / (double)(BIG_BLOCK_SIZE / 4)); // Does this affect the total? totalBlocks = startTotalBlocks + numBigBlockDepotBlocks; // See if the excel bbd chain can fit into the header block. // Remember to allow for the end of chain indicator if (numBigBlockDepotBlocks > blockChainLength - 1) { // Sod it - we need an extension block. We have to go through // the whole tiresome calculation again extensionBlock = 0; // Compute the number of extension blocks int bbdBlocksLeft = numBigBlockDepotBlocks - blockChainLength + 1; numExtensionBlocks = (int)Math.Ceiling((double)bbdBlocksLeft / (double)(BIG_BLOCK_SIZE / 4 - 1)); // Modify the total number of blocks required and recalculate the // the number of bbd blocks totalBlocks = startTotalBlocks + numExtensionBlocks + numBigBlockDepotBlocks; numBigBlockDepotBlocks = (int)Math.Ceiling((double)totalBlocks / (double)(BIG_BLOCK_SIZE / 4)); // The final total totalBlocks = startTotalBlocks + numExtensionBlocks + numBigBlockDepotBlocks; } else { extensionBlock = -2; numExtensionBlocks = 0; } // Set the excel data start block to be after the header (and // its extensions) excelDataStartBlock = numExtensionBlocks; // Set the start block of the small block depot sbdStartBlock = -2; if (additionalPropertySets != null && numSmallBlockDepotBlocks != 0) { sbdStartBlock = excelDataStartBlock + excelDataBlocks + additionalPropertyBlocks + 16; } // Set the sbd chain start block to be after the excel data and the // small block depot sbdStartBlockChain = -2; if (sbdStartBlock != -2) { sbdStartBlockChain = sbdStartBlock + numSmallBlockDepotBlocks; } // Set the bbd start block to be after all the excel data if (sbdStartBlockChain != -2) { bbdStartBlock = sbdStartBlockChain + numSmallBlockDepotChainBlocks; } else { bbdStartBlock = excelDataStartBlock + excelDataBlocks + additionalPropertyBlocks + 16; } // Set the root start block to be after all the big block depot blocks rootStartBlock = bbdStartBlock + numBigBlockDepotBlocks; if (totalBlocks != rootStartBlock + numRootEntryBlocks) { //logger.warn("Root start block and total blocks are inconsistent " + // " generated file may be corrupt"); //logger.warn("RootStartBlock " + rootStartBlock + " totalBlocks " + totalBlocks); } }
/** * Constructor used when importing a sheet from another * spreadsheet * * @param col the column number * @param cir the column info record read in */ public ColumnInfoRecord(CSharpJExcel.Jxl.Read.Biff.ColumnInfoRecord cir,int col) : base(Type.COLINFO) { column = col; width = cir.getWidth(); xfIndex = cir.getXFIndex(); outlineLevel = cir.getOutlineLevel(); collapsed = cir.getCollapsed(); }
/** * Constructor - used when copying sheets * * @param index the index into the name table */ public NameRecord(CSharpJExcel.Jxl.Read.Biff.NameRecord sr, int ind) : base(Type.NAME) { data = sr.getData(); name = sr.getName(); sheetRef = sr.getSheetRef(); index = ind; modified = false; // Copy the ranges CSharpJExcel.Jxl.Read.Biff.NameRecord.NameRange[] r = sr.getRanges(); ranges = new NameRange[r.Length]; for (int i = 0; i < ranges.Length; i++) { ranges[i] = new NameRange(r[i]); } }
public CountryRecord(CSharpJExcel.Jxl.Read.Biff.CountryRecord cr) : base(Type.COUNTRY) { language = cr.getLanguageCode(); regionalSettings = cr.getRegionalSettingsCode(); }
/** * Constructor * * @param os the output stream * @param ws the configuration settings for this workbook * @param rcf the rea compound file * @exception IOException */ public File(Stream os, WorkbookSettings ws, CSharpJExcel.Jxl.Read.Biff.CompoundFile rcf) { outputStream = os; workbookSettings = ws; readCompoundFile = rcf; createDataOutput(); }
/** * Creates internal class of the appropriate type * * @param c the contents to copy * @return the new contents */ protected override CSharpJExcel.Jxl.Biff.HeaderFooter.Contents createContents(CSharpJExcel.Jxl.Biff.HeaderFooter.Contents c) { return new Contents((Contents)c); }
public NameRange(CSharpJExcel.Jxl.Read.Biff.NameRecord.NameRange nr) { columnFirst = nr.getFirstColumn(); rowFirst = nr.getFirstRow(); columnLast = nr.getLastColumn(); rowLast = nr.getLastRow(); externalSheet = nr.getExternalSheet(); }
/** * Initializes an internal supbook record * * @param sr the read supbook record to copy from */ private void initInternal(CSharpJExcel.Jxl.Read.Biff.SupbookRecord sr) { numSheets = sr.getNumberOfSheets(); initInternal(); }
/** * Constructor used when copying from an external workbook */ public SupbookRecord(CSharpJExcel.Jxl.Read.Biff.SupbookRecord sr, WorkbookSettings ws) : base(Type.SUPBOOK) { workbookSettings = ws; if (sr.getType() == SupbookRecord.INTERNAL) { type = INTERNAL; numSheets = sr.getNumberOfSheets(); } else if (sr.getType() == SupbookRecord.EXTERNAL) { type = EXTERNAL; numSheets = sr.getNumberOfSheets(); fileName = sr.getFileName(); sheetNames = new string[numSheets]; for (int i = 0; i < numSheets; i++) sheetNames[i] = sr.getSheetName(i); } if (sr.getType() == SupbookRecord.ADDIN) { //logger.warn("Supbook type is addin"); } }
/** * Removes a drawing from this workbook * * @param d the drawing to remove */ public void removeDrawing(CSharpJExcel.Jxl.Biff.Drawing.Drawing d) { Assert.verify(drawingGroup != null); drawingGroup.remove(d); }
/** * Dummy override * @param cf dummy */ public void setCellFormat(CSharpJExcel.Jxl.Format.CellFormat cf) { }
/** * Publicly available copy constructor * * @param the font to copy */ protected WritableFontRecord(CSharpJExcel.Jxl.Format.Font f) : base(f) { }
/** * Constructor * * @param p the palette record */ public PaletteRecord(CSharpJExcel.Jxl.Read.Biff.PaletteRecord p) : base(Type.PALETTE) { data = p.getData(); }
/** * Reads the additional property sets from the read in compound file * * @param readCompoundFile the file read in * @exception CopyAdditionalPropertySetsException * @exception IOException */ private void readAdditionalPropertySets(CSharpJExcel.Jxl.Read.Biff.CompoundFile readCompoundFile) { if (readCompoundFile == null) { return; } additionalPropertySets = new ArrayList(); standardPropertySets = new Dictionary<string, ReadPropertyStorage>(); int blocksRequired = 0; int numPropertySets = readCompoundFile.getNumberOfPropertySets(); for (int i = 0; i < numPropertySets; i++) { PropertyStorage ps = readCompoundFile.getPropertySet(i); bool standard = false; if (System.String.Compare(ps.name,ROOT_ENTRY_NAME) == 0) { standard = true; ReadPropertyStorage rps = new ReadPropertyStorage(ps, null, i); standardPropertySets.Add(ROOT_ENTRY_NAME, rps); } // See if it is a standard property set for (int j = 0; j < STANDARD_PROPERTY_SETS.Length && !standard; j++) { if (System.String.Compare(ps.name,STANDARD_PROPERTY_SETS[j]) == 0) { // See if it comes directly off the root entry PropertyStorage ps2 = readCompoundFile.findPropertyStorage(ps.name); Assert.verify(ps2 != null); if (ps2 == ps) { standard = true; ReadPropertyStorage rps = new ReadPropertyStorage(ps, null, i); standardPropertySets.Add(STANDARD_PROPERTY_SETS[j], rps); } } } if (!standard) { try { byte[] data = null; if (ps.size > 0) { data = readCompoundFile.getStream(i); } else { data = new byte[0]; } ReadPropertyStorage rps = new ReadPropertyStorage(ps, data, i); additionalPropertySets.Add(rps); if (data.Length > SMALL_BLOCK_THRESHOLD) { int blocks = getBigBlocksRequired(data.Length); blocksRequired += blocks; } else { int blocks = getSmallBlocksRequired(data.Length); numSmallBlocks += blocks; } } catch (CSharpJExcel.Jxl.Read.Biff.BiffException e) { //logger.error(e); throw new CopyAdditionalPropertySetsException(); } } } additionalPropertyBlocks = blocksRequired; }
/** * Constructor */ public ButtonPropertySetRecord(CSharpJExcel.Jxl.Read.Biff.ButtonPropertySetRecord bps) : base(Type.BUTTONPROPERTYSET) { data = bps.getData(); }
/** * Consructor invoked when copying a spreadsheet * * @param hr the read header record */ public PLSRecord(CSharpJExcel.Jxl.Read.Biff.PLSRecord hr) : base(Type.PLS) { data = hr.getData(); }
/** * Publicly available copy constructor * * @param f the font to copy */ public WritableFont(CSharpJExcel.Jxl.Format.Font f) : base(f) { }
/** * Writes out the biff record * @param r * @exception IOException if an error occurs */ private bool writeRecord(CSharpJExcel.Jxl.Read.Biff.Record r, TextWriter os) { bool cont = true; int pos = reader.getPos(); int code = r.getCode(); if (bofs == 0) { cont = (r.getType() == CSharpJExcel.Jxl.Biff.Type.BOF); } if (!cont) { return cont; } if (r.getType() == CSharpJExcel.Jxl.Biff.Type.BOF) { bofs++; } if (r.getType() == CSharpJExcel.Jxl.Biff.Type.EOF) { bofs--; } StringBuilder buf = new StringBuilder(); // Write out the record header writeSixDigitValue(pos, buf); buf.Append(" ["); buf.Append(recordNames[r.getType()]); buf.Append("]"); buf.Append(" (0x"); buf.Append(code.ToString("x")); buf.Append(")"); if (code == CSharpJExcel.Jxl.Biff.Type.XF.value) { buf.Append(" (0x"); buf.Append(xfIndex.ToString("x")); buf.Append(")"); xfIndex++; } if (code == CSharpJExcel.Jxl.Biff.Type.FONT.value) { if (fontIndex == 4) { fontIndex++; } buf.Append(" (0x"); buf.Append(fontIndex.ToString("x")); buf.Append(")"); fontIndex++; } os.Write(buf.ToString()); os.WriteLine(); byte[] standardData = new byte[4]; standardData[0] = (byte)(code & 0xff); standardData[1] = (byte)((code & 0xff00) >> 8); standardData[2] = (byte)(r.getLength() & 0xff); standardData[3] = (byte)((r.getLength() & 0xff00) >> 8); byte[] recordData = r.getData(); byte[] data = new byte[standardData.Length + recordData.Length]; Array.Copy(standardData, 0, data, 0, standardData.Length); Array.Copy(recordData, 0, data, standardData.Length, recordData.Length); int byteCount = 0; int lineBytes = 0; while (byteCount < data.Length) { buf = new StringBuilder(); writeSixDigitValue(pos + byteCount, buf); buf.Append(" "); lineBytes = Math.Min(bytesPerLine, data.Length - byteCount); for (int i = 0; i < lineBytes; i++) { writeByte(data[i + byteCount], buf); buf.Append(' '); } // Perform any padding if (lineBytes < bytesPerLine) { for (int i = 0; i < bytesPerLine - lineBytes; i++) { buf.Append(" "); } } buf.Append(" "); for (int i = 0; i < lineBytes; i++) { char c = (char)data[i + byteCount]; if (c < ' ' || c > 'z') c = '.'; buf.Append(c); } byteCount += lineBytes; os.Write(buf.ToString()); os.WriteLine(); } return cont; }