Example #1
0
        /**
         * Gets the name of the external sheet specified by the index
         *
         * @param index the external sheet index
         * @return the name of the external sheet
         */
        public string getLastExternalSheetName(int index)
        {
            // For biff7, the whole external reference thing works differently
            // Hopefully for our purposes sheet references will all be local
            if (workbookBof.isBiff7())
            {
                BoundsheetRecord br = (BoundsheetRecord)boundsheets[index];

                return(br.getName());
            }

            int           supbookIndex = externSheet.getSupbookIndex(index);
            SupbookRecord sr           = (SupbookRecord)supbooks[supbookIndex];

            int lastTab = externSheet.getLastTabIndex(index);

            if (sr.getType() == SupbookRecord.INTERNAL)
            {
                // It's an internal reference - get the name from the boundsheets list
                if (lastTab == 65535)
                {
                    return("#REF");
                }
                else
                {
                    BoundsheetRecord br = (BoundsheetRecord)boundsheets[lastTab];
                    return(br.getName());
                }
            }
            else if (sr.getType() == SupbookRecord.EXTERNAL)
            {
                // External reference - get the sheet name from the supbook record
                StringBuilder sb = new StringBuilder();
                FileInfo      fl = new FileInfo(sr.getFileName());
                sb.Append("'");
                sb.Append(fl.FullName);                         // getAbsolutePath
                sb.Append("[");
                sb.Append(fl.Name);
                sb.Append("]");
                sb.Append((lastTab == 65535) ? "#REF" : sr.getSheetName(lastTab));
                sb.Append("'");
                return(sb.ToString());
            }

            // An unknown supbook - return unkown
            //logger.warn("Unknown Supbook 4");
            return("[UNKNOWN]");
        }
Example #2
0
        /**
         * Gets the name of the external sheet specified by the index
         *
         * @param index the external sheet index
         * @return the name of the external sheet
         */
        public string getExternalSheetName(int index)
        {
            // For biff7, the whole external reference thing works differently
            // Hopefully for our purposes sheet references will all be local
            if (workbookBof.isBiff7())
            {
                BoundsheetRecord br = (BoundsheetRecord)boundsheets[index];

                return(br.getName());
            }

            int           supbookIndex = externSheet.getSupbookIndex(index);
            SupbookRecord sr           = (SupbookRecord)supbooks[supbookIndex];

            int    firstTab     = externSheet.getFirstTabIndex(index);
            int    lastTab      = externSheet.getLastTabIndex(index);
            string firstTabName = string.Empty;
            string lastTabName  = string.Empty;

            if (sr.getType() == SupbookRecord.INTERNAL)
            {
                // It's an internal reference - get the name from the boundsheets list
                if (firstTab == 65535)
                {
                    firstTabName = "#REF";
                }
                else
                {
                    BoundsheetRecord br = (BoundsheetRecord)boundsheets[firstTab];
                    firstTabName = br.getName();
                }

                if (lastTab == 65535)
                {
                    lastTabName = "#REF";
                }
                else
                {
                    BoundsheetRecord br = (BoundsheetRecord)boundsheets[lastTab];
                    lastTabName = br.getName();
                }

                string sheetName = (firstTab == lastTab) ? firstTabName :
                                   firstTabName + ':' + lastTabName;

                // if the sheet name contains apostrophes then escape them
                sheetName = sheetName.IndexOf('\'') == -1 ? sheetName :
                            StringHelper.replace(sheetName, "\'", "\'\'");


                // if the sheet name contains spaces, then enclose in quotes
                return(sheetName.IndexOf(' ') < 0 ? sheetName : '\'' + sheetName + '\'');
            }
            else if (sr.getType() == SupbookRecord.EXTERNAL)
            {
                // External reference - get the sheet name from the supbook record
                StringBuilder sb = new StringBuilder();
                FileInfo      fl = new FileInfo(sr.getFileName());
                sb.Append("'");
                sb.Append(fl.FullName);                         // .getAbsolutePath
                sb.Append("[");
                sb.Append(fl.Name);
                sb.Append("]");
                sb.Append((firstTab == 65535) ? "#REF" : sr.getSheetName(firstTab));
                if (lastTab != firstTab)
                {
                    sb.Append(sr.getSheetName(lastTab));
                }
                sb.Append("'");
                return(sb.ToString());
            }

            // An unknown supbook - return unkown
            //logger.warn("Unknown Supbook 3");
            return("[UNKNOWN]");
        }