/** * Constructs this object from the raw data * * @param t the raw data * @param s the sheet */ public MergedCellsRecord(Record t, Sheet s) : base(t) { byte[] data = getRecord().getData(); int numRanges = IntegerHelper.getInt(data[0], data[1]); ranges = new Range[numRanges]; int pos = 2; int firstRow = 0; int lastRow = 0; int firstCol = 0; int lastCol = 0; for (int i = 0; i < numRanges; i++) { firstRow = IntegerHelper.getInt(data[pos], data[pos + 1]); lastRow = IntegerHelper.getInt(data[pos + 2], data[pos + 3]); firstCol = IntegerHelper.getInt(data[pos + 4], data[pos + 5]); lastCol = IntegerHelper.getInt(data[pos + 6], data[pos + 7]); ranges[i] = new SheetRangeImpl(s, firstCol, firstRow, lastCol, lastRow); pos += 8; } }
/** * Checks the cell ranges for intersections, or if the merged cells * contains more than one item of data */ private void checkRanges() { try { SheetRangeImpl range = null; // Check all the ranges to make sure they only contain one entry for (int i = 0; i < ranges.Count; i++) { range = (SheetRangeImpl)ranges[i]; // Get the cell in the top left Cell tl = range.getTopLeft(); Cell br = range.getBottomRight(); bool found = false; for (int c = tl.getColumn(); c <= br.getColumn(); c++) { for (int r = tl.getRow(); r <= br.getRow(); r++) { Cell cell = sheet.getCell(c, r); if (cell.getType() != CellType.EMPTY) { if (!found) { found = true; } else { //logger.warn("Range " + range + // " contains more than one data cell. " + // "Setting the other cells to blank."); Blank b = new Blank(c, r); sheet.addCell(b); } } } } } } catch (WriteException e) { // This should already have been checked - bomb out Assert.verify(false); } }
/// <summary> Constructs this object from the raw data /// /// </summary> /// <param name="t">the raw data /// </param> /// <param name="s">the sheet /// </param> /// <param name="ws">the workbook settings /// </param> internal HyperlinkRecord(Record t, Sheet s, WorkbookSettings ws) : base(t) { linkType = unknown; sbyte[] data = getRecord().Data; // Build up the range of cells occupied by this hyperlink firstRow = IntegerHelper.getInt(data[0], data[1]); lastRow = IntegerHelper.getInt(data[2], data[3]); firstColumn = IntegerHelper.getInt(data[4], data[5]); lastColumn = IntegerHelper.getInt(data[6], data[7]); range = new SheetRangeImpl(s, firstColumn, firstRow, lastColumn, lastRow); // Try and determine the type if ((data[28] & 0x3) == 0x03) { linkType = urlLink; bool description = (data[28] & 0x14) != 0; string urlString = null; try { int startpos = 32; if (description) { int descbytes = IntegerHelper.getInt(data[startpos], data[startpos + 1], data[startpos + 2], data[startpos + 3]); startpos += descbytes * 2 + 4; } startpos += 16; // Get the url, ignoring the 0 char at the end int bytes = IntegerHelper.getInt(data[startpos], data[startpos + 1], data[startpos + 2], data[startpos + 3]); urlString = StringHelper.getUnicodeString(data, bytes / 2 - 1, startpos + 4); url = new Uri(urlString); } catch (Exception e) { System.Text.StringBuilder sb1 = new System.Text.StringBuilder(); System.Text.StringBuilder sb2 = new System.Text.StringBuilder(); NExcel.CellReferenceHelper.getCellReference(firstColumn, firstRow, sb1); NExcel.CellReferenceHelper.getCellReference(lastColumn, lastRow, sb2); sb1.Insert(0, "Exception when parsing URL "); sb1.Append('\"').Append(sb2.ToString()).Append("\". Using default."); logger.warn(sb1, e); url = new Uri("http://www.sourceforge.net/projects/nexcel"); } } else if ((data[28] & 0x01) != 0) { linkType = fileLink; // boolean description = (data[28] & 0x14) != 0; try { int startpos = 48; // Get the name of the local file, ignoring the zero character at the // end int upLevelCount = IntegerHelper.getInt(data[startpos], data[startpos + 1]); int chars = IntegerHelper.getInt(data[startpos + 2], data[startpos + 3], data[startpos + 4], data[startpos + 5]); string fileName = StringHelper.getString(data, chars - 1, startpos + 6, ws); System.Text.StringBuilder sb = new System.Text.StringBuilder(); for (int i = 0; i < upLevelCount; i++) { sb.Append("..\\"); } sb.Append(fileName); file = new System.IO.FileInfo(sb.ToString()); } catch (System.Exception e) { logger.warn("Exception when parsing file " + e.GetType().FullName + "."); file = new System.IO.FileInfo("."); } } else if ((data[28] & 0x08) != 0) { linkType = workbookLink; int chars = IntegerHelper.getInt(data[32], data[33], data[34], data[35]); location = StringHelper.getUnicodeString(data, chars - 1, 36); } else { // give up logger.warn("Cannot determine link type"); return; } }
/** * Constructs this object from the raw data * * @param t the raw data * @param s the sheet * @param ws the workbook settings */ public HyperlinkRecord(Record t, Sheet s, WorkbookSettings ws) : base(t) { linkType = unknown; byte[] data = getRecord().getData(); // Build up the range of cells occupied by this hyperlink firstRow = IntegerHelper.getInt(data[0], data[1]); lastRow = IntegerHelper.getInt(data[2], data[3]); firstColumn = IntegerHelper.getInt(data[4], data[5]); lastColumn = IntegerHelper.getInt(data[6], data[7]); range = new SheetRangeImpl(s, firstColumn, firstRow, lastColumn, lastRow); int options = IntegerHelper.getInt(data[28], data[29], data[30], data[31]); bool description = (options & 0x14) != 0; int startpos = 32; int descbytes = 0; if (description) { int descchars = IntegerHelper.getInt(data[startpos], data[startpos + 1], data[startpos + 2], data[startpos + 3]); descbytes = descchars * 2 + 4; } startpos += descbytes; bool targetFrame = (options & 0x80) != 0; int targetbytes = 0; if (targetFrame) { int targetchars = IntegerHelper.getInt(data[startpos], data[startpos + 1], data[startpos + 2], data[startpos + 3]); targetbytes = targetchars * 2 + 4; } startpos += targetbytes; // Try and determine the type if ((options & 0x3) == 0x03) { linkType = urlLink; // check the guid monicker if (data[startpos] == 0x03) { linkType = fileLink; } } else if ((options & 0x01) != 0) { linkType = fileLink; // check the guid monicker if (data[startpos] == (byte)0xe0) { linkType = urlLink; } } else if ((options & 0x08) != 0) { linkType = workbookLink; } // Try and determine the type if (linkType == urlLink) { string urlString = null; try { startpos += 16; // Get the url, ignoring the 0 char at the end int bytes = IntegerHelper.getInt(data[startpos], data[startpos + 1], data[startpos + 2], data[startpos + 3]); urlString = StringHelper.getUnicodeString(data, bytes / 2 - 1, startpos + 4); url = new Uri(urlString); } catch (UriFormatException e) { //logger.warn("URL " + urlString + " is malformed. Trying a file"); try { linkType = fileLink; file = new FileInfo(urlString); } catch (Exception e3) { //logger.warn("Cannot set to file. Setting a default URL"); // Set a default URL try { linkType = urlLink; url = new Uri("http://www.andykhan.com/jexcelapi/index.html"); } catch (UriFormatException e2) { // fail silently } } } catch (Exception e) { //StringBuilder sb1 = new StringBuilder(); //StringBuilder sb2 = new StringBuilder(); //CellReferenceHelper.getCellReference(firstColumn,firstRow,sb1); //CellReferenceHelper.getCellReference(lastColumn,lastRow,sb2); //sb1.Insert(0,"Exception when parsing URL "); //sb1.Append('\"').Append(sb2.ToString()).Append("\". Using default."); //logger.warn(sb1,e); // Set a default URL try { url = new Uri("http://www.andykhan.com/jexcelapi/index.html"); } catch (UriFormatException e2) { // fail silently } } } else if (linkType == fileLink) { try { startpos += 16; // Get the name of the local file, ignoring the zero character at the // end int upLevelCount = IntegerHelper.getInt(data[startpos], data[startpos + 1]); int chars = IntegerHelper.getInt(data[startpos + 2], data[startpos + 3], data[startpos + 4], data[startpos + 5]); string fileName = StringHelper.getString(data, chars - 1, startpos + 6, ws); StringBuilder sb = new StringBuilder(); for (int i = 0; i < upLevelCount; i++) { sb.Append("..\\"); } sb.Append(fileName); file = new FileInfo(sb.ToString()); } catch (Exception e) { //logger.warn("Exception when parsing file " + e.getClass().getName() + "."); file = new FileInfo("."); } } else if (linkType == workbookLink) { int chars = IntegerHelper.getInt(data[32], data[33], data[34], data[35]); location = StringHelper.getUnicodeString(data, chars - 1, 36); } else { // give up //logger.warn("Cannot determine link type"); return; } }