Ejemplo n.º 1
0
        public static ExcelReader SharedReader()
        {
            if (excelReader == null)
            {
                excelReader = new ExcelReader();
                excelReader.headers = new List<String>();
                excelReader.rowIdentifierList = new List<String>();
                //excelReader.dataSet = new List<Dictionary<String, String>>();
            }

            excelReader.headers.Clear();
            excelReader.rowIdentifierList.Clear();
            return excelReader;
        }
Ejemplo n.º 2
0
        public async Task<List<SheetData>> ParseSpreadSheetFile(StorageFile _targetFile)
        {
            List<SheetData> allSheetsData = new List<SheetData>();
            List<ZipArchiveEntry> listOfSheets = new List<ZipArchiveEntry>();
           excelReader= ExcelReader.SharedReader();
            // Clearing processing values
            try
            {
                excelReader.headers.Clear();
            }
            catch
            {

            }
            try
            {
                excelReader.rowIdentifierList.Clear();
            }
            catch
            {

            }
            this.targetFile = _targetFile;

            try
            {

                if (_targetFile == null)
                {
                    throw new ArgumentNullException("Target file is empty");
                }
                else
                {
                    Stream fileAsStream = targetFile.OpenStreamForReadAsync().Result;
                    ZipArchive z = new ZipArchive(fileAsStream);

                    var sharedString = z.GetEntry(SHARED_STRING);
                    var listOfSharedStrings = await this.CollectSharedStrings(sharedString);

                    if (_sharedStrings == null)
                    {
                        _sharedStrings = new List<string>();
                    }
                    _sharedStrings.Clear();
                    _sharedStrings = listOfSharedStrings.ToList();

                    var entries = z.Entries;

                    foreach (var anEntry in entries)
                    {
                        if (anEntry.Name.Contains("sheet") && !anEntry.Name.Contains("rels"))
                        {
                            listOfSheets.Add(anEntry);
                        }
                    }

                    foreach (var aSheet in listOfSheets)
                    {
                        var currentSheetData = await this.ReadSheetData(aSheet);
                        SheetData sheetData = new SheetData();
                        sheetData.sheetEntryInArchive = aSheet;
                        sheetData.data = currentSheetData;
                        allSheetsData.Add(sheetData);
                    }
                }
            }
            catch (Exception exception)
            {
                throw exception;
            }

            return allSheetsData;
        }