Exemple #1
0
        public Dicts InitializeAreaSheet(DefinitionParserData data)
        {
            Dicts d = new Dicts(true);

            interaction.InsertValue(new ExcelCellAddress(1, 1), "Spreadsheet for zone: " + interaction.currentSheet.Name);

            int[] rowOfEachGroup    = new int[data.groups.Length];
            int[] columnOfEachGroup = new int[data.groups.Length];
            int   groupcounter      = 0;

            foreach (string group in data.groups)
            {
                rowOfEachGroup[groupcounter]    = 2;
                columnOfEachGroup[groupcounter] = groupcounter * columnOffset + 1;
                ExcelCellAddress address = new ExcelCellAddress(rowOfEachGroup[groupcounter], columnOfEachGroup[groupcounter]);
                interaction.currentSheet.Select(new ExcelAddress(address.Row, address.Column, address.Row, address.Column + 2));
                ExcelRange r = interaction.currentSheet.SelectedRange;
                r.Merge = true;
                r.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center;
                interaction.InsertValue(address, group);
                groupcounter += 1;
                SpreadsheetInteraction.Group g = new SpreadsheetInteraction.Group(address, new ExcelCellAddress(address.Row + 1, address.Column),
                                                                                  new ExcelCellAddress(address.Row + 1, address.Column + 1),
                                                                                  new ExcelCellAddress(address.Row + 1, address.Column + 2));
                d.groups.Add(group, g);
            }
            foreach (DefinitionParserData.Item entry in data.entries)
            {
                SpreadsheetInteraction.Group g = d.groups[entry.group];
                g.totalEntries++;
                d.groups[entry.group] = g;
                for (int i = 0; i < data.groups.Length; i++)
                {
                    if (data.groups[i] == entry.group)
                    {
                        groupcounter = i;
                    }
                }
                rowOfEachGroup[groupcounter] += 1;
                ExcelCellAddress nameAddr  = new ExcelCellAddress(rowOfEachGroup[groupcounter], columnOfEachGroup[groupcounter]);
                ExcelCellAddress yangVal   = new ExcelCellAddress(rowOfEachGroup[groupcounter], columnOfEachGroup[groupcounter] + 1);
                ExcelCellAddress collected = new ExcelCellAddress(rowOfEachGroup[groupcounter], columnOfEachGroup[groupcounter] + 2);

                interaction.InsertValue(nameAddr, entry.mainPronounciation);
                interaction.InsertValue(yangVal, entry.yangValue);
                interaction.InsertValue(collected, 0);

                interaction.currentSheet.Cells[yangVal.Address].Style.Numberformat.Format = "###,###,###,###,###";
                d.addresses.Add(entry.mainPronounciation, collected);
            }
            interaction.Save();
            return(d);
        }
Exemple #2
0
        /// <summary>
        /// Parses spreadsheet
        /// </summary>
        /// <param name="book">Current WorkBook</param>
        /// <param name="sheetName">Name of the sheet as it appears in Excel</param>
        /// <param name="type">Spreadsheet type to determine parsing method</param>
        public static Dicts LoadSpreadsheet(ExcelWorkbook book, string sheetName, SpreadsheetTemplates.SpreadsheetPresetType type)
        {
            ExcelWorksheet sheet = book.Worksheets[sheetName];

            switch (type)
            {
            case SpreadsheetTemplates.SpreadsheetPresetType.MAIN: {
                return(default(Dicts));
            }

            case SpreadsheetTemplates.SpreadsheetPresetType.AREA: {
                Dicts d = new Dicts(true);
                DefinitionParserData data = DefinitionParser.instance.currentGrammarFile;
                int[] rowOfEachGroup      = new int[data.groups.Length];
                int[] columnOfEachGroup   = new int[data.groups.Length];
                int   columnOffset        = 4;
                int   groupcounter        = 0;
                foreach (string group in data.groups)
                {
                    rowOfEachGroup[groupcounter]    = 2;
                    columnOfEachGroup[groupcounter] = groupcounter * columnOffset + 1;
                    ExcelCellAddress address = new ExcelCellAddress(rowOfEachGroup[groupcounter], columnOfEachGroup[groupcounter]);
                    groupcounter += 1;
                    SpreadsheetInteraction.Group g = new SpreadsheetInteraction.Group(address, new ExcelCellAddress(address.Row + 1, address.Column),
                                                                                      new ExcelCellAddress(address.Row + 1, address.Column + 1),
                                                                                      new ExcelCellAddress(address.Row + 1, address.Column + 2));
                    d.groups.Add(group, g);
                }
                foreach (DefinitionParserData.Item entry in data.entries)
                {
                    SpreadsheetInteraction.Group g = d.groups[entry.group];
                    g.totalEntries++;
                    d.groups[entry.group] = g;
                    for (int i = 0; i < data.groups.Length; i++)
                    {
                        if (data.groups[i] == entry.group)
                        {
                            groupcounter = i;
                        }
                    }
                    rowOfEachGroup[groupcounter] += 1;
                    ExcelCellAddress collected = new ExcelCellAddress(rowOfEachGroup[groupcounter], columnOfEachGroup[groupcounter] + 2);

                    d.addresses.Add(entry.mainPronounciation, collected);
                }
                return(d);
            }

            case SpreadsheetTemplates.SpreadsheetPresetType.ENEMY: {
                Dicts d = new Dicts(true);
                // First item entry at A2
                ExcelCellAddress baseAddr = new ExcelCellAddress("A2");
                ExcelCellAddress current  = baseAddr;

                bool EOF = false;
                while (!EOF)
                {
                    if (sheet.Cells[current.Row, current.Column].Value == null)
                    {
                        current = new ExcelCellAddress(2, current.Column + 4);
                        if (sheet.Cells[current.Address].Value == null)
                        {
                            EOF = true;
                            continue;
                        }
                    }
                    d.addresses.Add(sheet.Cells[current.Row, current.Column].GetValue <string>(), new ExcelCellAddress(current.Row, current.Column + 2));
                    current = new ExcelCellAddress(current.Row + 1, current.Column);
                }
                return(d);
            }

            default: {
                throw new CustomException("Uncathegorized sheet entered!");
            }
            }
        }