Exemple #1
0
        /// <summary>
        /// Fills TextBank bank with all of the sheets and left-most cells of an Excel spreadsheet
        /// </summary>
        /// <param name="bank"></param>
        /// <param name="path"></param>
        public static void ImportTextBank(TextBank bank, string path)
        {
            // find & open the excel file in read only mode
            FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            IWorkbook  book   = new XSSFWorkbook(stream);

            // import all sheets
            for (int sheetIndex = 0; sheetIndex < book.NumberOfSheets; sheetIndex++)
            {
                ISheet      s      = book.GetSheetAt(sheetIndex);
                TextBankSet newSet = new TextBankSet();
                newSet.name = s.SheetName;
                // look through each row of this sheet
                for (int rowIndex = 0; rowIndex <= s.LastRowNum; rowIndex++)
                {
                    if (s.GetRow(rowIndex) != null)
                    {
                        if (s.GetRow(rowIndex).GetCell(0) != null)
                        {
                            newSet.textItems.Add(s.GetRow(rowIndex).GetCell(0).StringCellValue);
                        }
                        else
                        {
                            newSet.textItems.Add(" ");
                        }
                    }
                }
                bank.bankSets.Add(newSet);
            }
            stream.Close();
        }
Exemple #2
0
        public string GetBankTextByIndex(int index, string set)
        {
            TextBankSet bankSet = GetBankSetByName(set);

            if (bankSet == null)
            {
                Debug.LogWarning("TextBank " + this.name + " does not have an entry for current set, '" + set + "'");
                return("");
            }
            return(bankSet.textItems[index]);
        }