コード例 #1
0
        /**
         * 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;
                }
        }
コード例 #2
0
 /**
  * A copy constructor used for copying ranges between sheets
  *
  * @param c the range to copy from
  * @param s the writable sheet
  */
 public SheetRangeImpl(SheetRangeImpl c, Sheet s)
 {
     sheet   = s;
     row1    = c.row1;
     row2    = c.row2;
     column1 = c.column1;
     column2 = c.column2;
 }
コード例 #3
0
        /**
         * Sees whether there are any intersections between this range and the
         * range passed in.  This method is used internally by the WritableSheet to
         * verify the integrity of merged cells, hyperlinks etc.  Ranges are
         * only ever compared for the same sheet
         *
         * @param range the range to compare against
         * @return TRUE if the ranges intersect, FALSE otherwise
         */
        public bool intersects(SheetRangeImpl range)
        {
            if (range == this)
            {
                return(true);
            }

            if (row2 < range.row1 ||
                row1 > range.row2 ||
                column2 < range.column1 ||
                column1 > range.column2)
            {
                return(false);
            }

            return(true);
        }
コード例 #4
0
        /**
         * Standard equals method
         *
         * @param o the object to compare
         * @return TRUE if the two objects are the same, FALSE otherwise
         */
        public override bool Equals(object o)
        {
            if (o == this)
            {
                return(true);
            }

            if (!(o is SheetRangeImpl))
            {
                return(false);
            }

            SheetRangeImpl compare = (SheetRangeImpl)o;

            return(column1 == compare.column1 &&
                   column2 == compare.column2 &&
                   row1 == compare.row1 &&
                   row2 == compare.row2);
        }
コード例 #5
0
        /**
         * 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;
                }
        }
コード例 #6
0
 /**
  * A copy constructor used for copying ranges between sheets
  *
  * @param c the range to copy from
  * @param s the writable sheet
  */
 public SheetRangeImpl(SheetRangeImpl c,Sheet s)
 {
     sheet = s;
     row1 = c.row1;
     row2 = c.row2;
     column1 = c.column1;
     column2 = c.column2;
 }
コード例 #7
0
        /**
         * Sees whether there are any intersections between this range and the
         * range passed in.  This method is used internally by the WritableSheet to
         * verify the integrity of merged cells, hyperlinks etc.  Ranges are
         * only ever compared for the same sheet
         *
         * @param range the range to compare against
         * @return TRUE if the ranges intersect, FALSE otherwise
         */
        public bool intersects(SheetRangeImpl range)
        {
            if (range == this)
                {
                return true;
                }

            if (row2 < range.row1 ||
                row1 > range.row2 ||
                column2 < range.column1 ||
                column1 > range.column2)
                {
                return false;
                }

            return true;
        }