Ejemplo n.º 1
0
        public ExcelSheetPageViewModel(string sheetName, Lumina.Lumina lumina)
        {
            SheetColumns  = new ObservableCollection <SheetColumnInfo>();
            SheetPages    = new ObservableCollection <ExcelPage>();
            Languages     = new ObservableCollection <string>();
            RawRowData    = new ObservableCollection <object>();
            RawColumnData = new ObservableCollection <DataGridColumn>();
            RawData       = new ObservableCollection <object>();

            // get shit
            _lumina   = lumina;
            SheetName = sheetName;

            // break shit
            RawSheet = lumina.Excel.GetSheetRaw(sheetName, Language.English);
            Debug.Assert(RawSheet != null, "somehow the sheet name is null, shit is f****d");

            HeaderFileName = RawSheet.HeaderFile.FilePath;
            Languages.AddRange(RawSheet.Languages.Select(l => l.ToString()));

            for (int i = 0; i < RawSheet.Columns.Length; i++)
            {
                var c   = RawSheet.Columns[i];
                var sci = new SheetColumnInfo
                {
                    Index  = i,
                    Type   = c.Type,
                    Offset = c.Offset
                };

                SheetColumns.Add(sci);
            }

            foreach (var page in RawSheet.DataPages)
            {
                var file    = page.File;
                var rowPtrs = file.RowData;

                var parser = new RowParser(RawSheet, file);

                foreach (var rowPtr in rowPtrs.Values)
                {
                    var row = new object[RawSheet.ColumnCount + 1];
                    row[0] = rowPtr.RowId;

                    parser.SeekToRow(rowPtr.RowId);

                    for (int c = 0; c < RawSheet.ColumnCount; c++)
                    {
                        row[c + 1] = parser.ReadColumnRaw(c);
                    }

                    RawData.Add(row);
                }
            }

            SheetPages.AddRange(RawSheet.DataPages);
        }