Exemplo n.º 1
0
        private async Task ReadFile()
        {
            Progress = "开始读取excel文件...";
            var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Data/data.xlsx"));

            var column = new List <int>();

            for (int i = 1; i < 33; i++)
            {
                column.Add(i);
            }
            Ret = await ExcelService.ReadAllCellsAsync(file.Path, SheetName.Text, 2, column);

            Cells.Clear();
            foreach (var item in Ret)
            {
                Cells.Add(ExcelService.GetCellValue(item));
            }
            await Task.CompletedTask.ConfigureAwait(true);
        }
Exemplo n.º 2
0
        private async void InsectButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            if (SheetName.Text != "insect")
            {
                Progress = "Sheet Name Wrong!";
                return;
            }
            await ReadFile();

            Progress = "开始写入数据库...";
            for (int i = 0; i < Ret.Count; i++)
            {
                var name     = ExcelService.GetCellValue(Ret[i]);
                var number   = ExcelService.GetCellValue(Ret[i + 1]);
                var eng      = ExcelService.GetCellValue(Ret[i + 2]);
                var jap      = ExcelService.GetCellValue(Ret[i + 3]);
                var price    = ExcelService.GetCellValue(Ret[i + 4]);
                var position = ExcelService.GetCellValue(Ret[i + 5]);
                var weather  = ExcelService.GetCellValue(Ret[i + 6]);
                var time     = ExcelService.GetCellValue(Ret[i + 7]);
                //北半球
                var Nappear = new List <string>();
                for (int j = 1; j < 13; j++)
                {
                    var value = ExcelService.GetCellValue(Ret[i + 7 + j]);
                    Nappear.Add(value);
                }
                var Nmonth = new Month {
                    AppearMonth = Nappear
                };
                var north = new North {
                    Month = Nmonth
                };

                //南半球
                var Sappear = new List <string>();
                for (int j = 1; j < 13; j++)
                {
                    var value = ExcelService.GetCellValue(Ret[i + 19 + j]);
                    Sappear.Add(value);
                }
                var Smonth = new Month {
                    AppearMonth = Sappear
                };
                var south = new South {
                    Month = Smonth
                };

                //汇总
                var insect = new Insect {
                    Name = name, Number = Convert.ToInt32(number), English = eng, Japanese = jap, Price = Convert.ToInt32(price), Position = position, Weather = weather, Time = time, Hemisphere = new Hemisphere {
                        North = north, South = south
                    }
                };

                var json = Newtonsoft.Json.JsonConvert.SerializeObject(insect);
                SQLiteService.AddInsectData(name, json);
                i = i + 31;
            }
            Progress = "写入数据完成";
        }