示例#1
0
        public static List <Vocab> LoadAllVocabs(string filePath, bool[] selectedParts)
        {
            var listVocab = new List <Vocab>();

            if (File.Exists(filePath))
            {
                //TODO
                Excel.Application app      = new Excel.Application();
                Excel.Workbook    workbook = app.Workbooks.Open(filePath);
                for (int i = 0; i < selectedParts.Length; i++)
                {
                    if (selectedParts[i])
                    {
                        Excel.Worksheet sheet = workbook.Worksheets[i + 1];
                        Excel.Range     range = sheet.UsedRange;
                        for (int row = 1; row <= range.Rows.Count; row++)
                        {
                            var cell1 = range.Cells[row, 1] as Excel.Range;
                            var cell2 = range.Cells[row, 2] as Excel.Range;
                            var cell3 = range.Cells[row, 3] as Excel.Range;
                            if (cell1 != null && cell1.Value2 != null)
                            {
                                var vocab = new Vocab()
                                {
                                    Word    = cell1.Value2.ToString(),
                                    Kana    = cell2 == null || cell2.Value2 == null?"":cell2.Value2.ToString(),
                                    Meaning = cell3 == null || cell3.Value2 == null?"":cell3.Value2.ToString()
                                };
                                listVocab.Add(vocab);
                            }
                        }
                    }
                }
                //close and release
                workbook.Close();
                Marshal.ReleaseComObject(workbook);

                //quit and release
                app.Quit();
                Marshal.ReleaseComObject(app);
            }
            return(listVocab);
        }
示例#2
0
        //private void ShowWord(string s)
        //{
        //    if (string.IsNullOrWhiteSpace(s))
        //    {
        //        return;
        //    }
        //    var arr = s.Split('\t');
        //    var word = arr[0];
        //    var kana = arr[1];
        //    var mean = arr[2];

        //    if (_isWord)
        //    {
        //        Word.Inlines.Add(new Run($"{word}")
        //        {
        //            FontSize = 25,
        //            FontWeight = FontWeights.Bold
        //        });
        //    }

        //    if (_isKana)
        //    {
        //        Word.Inlines.Add(new LineBreak());
        //        Word.Inlines.Add(new Run($"「{kana}」")
        //        {
        //            FontSize = 18,
        //            FontStyle = FontStyles.Italic,
        //            FontWeight = FontWeights.DemiBold
        //        });
        //    }

        //    if (_isMean)
        //    {
        //        Word.Inlines.Add(new LineBreak());
        //        Word.Inlines.Add(new Run(mean)
        //        {
        //            FontSize = 20,
        //            FontWeight = FontWeights.DemiBold
        //        });
        //    }

        //    Topmost = true;
        //}

        private void ShowVocab(Vocab v)
        {
            if (v == null)
            {
                return;
            }


            if (_isWord)
            {
                Word.Inlines.Add(new Run($"{v.Word}")
                {
                    FontSize   = 25,
                    FontWeight = FontWeights.Bold
                });
            }

            if (_isKana)
            {
                Word.Inlines.Add(new LineBreak());
                Word.Inlines.Add(new Run($"「{v.Kana}」")
                {
                    FontSize   = 18,
                    FontStyle  = FontStyles.Italic,
                    FontWeight = FontWeights.DemiBold
                });
            }

            if (_isMean)
            {
                Word.Inlines.Add(new LineBreak());
                Word.Inlines.Add(new Run(v.Meaning)
                {
                    FontSize   = 20,
                    FontWeight = FontWeights.DemiBold
                });
            }

            Topmost = true;
        }