private static string tryParseAndSetLemmaDictionaryCell(int rowNumber, Vocabulary_entry vocabularyEntry, Microsoft.Office.Interop.Excel.Worksheet worksheet) { string columnNumber = ExcelDictionaryColumn.LEMMA.Column; string cellValue = parseStringValue(rowNumber, columnNumber, worksheet); if (String.IsNullOrEmpty(cellValue)) { return(null); } vocabularyEntry.Lemma = cellValue; return(cellValue); }
public static IList <Vocabulary_entry> ReadDictionaryEntriesFromExcelFile(string path) { Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application(); excelApp.Visible = false; Microsoft.Office.Interop.Excel.Workbook excelAppWorkbook = excelApp.Workbooks.Open(path); Microsoft.Office.Interop.Excel.Worksheet worksheet = excelAppWorkbook.Sheets[ACTIVE_SHEET]; if (worksheet == null) { return(null); } int totalColumns = worksheet.UsedRange.Columns.Count; int totalRows = worksheet.UsedRange.Rows.Count; SortedList <int, Vocabulary_entry> entries = new SortedList <int, Vocabulary_entry>(); for (int row = FIRST_ROW; row < totalRows; row++) { int curEntryNumber = tryParseEntryNumberDictionaryCell(row, worksheet); if (curEntryNumber == 0) { // invalid value continue; } Vocabulary_entry vocabularyEntry = null; if (!entries.ContainsKey(curEntryNumber)) { vocabularyEntry = new Vocabulary_entry(); vocabularyEntry.Number_vocabulary_entry = curEntryNumber; entries.Add(curEntryNumber, vocabularyEntry); } else { vocabularyEntry = entries[curEntryNumber]; } // parse entry conponents in order of appearance if (vocabularyEntry != null) { // entry line number Dictionary_conformity dictionaryConformity = tryGetNewDictionaryConformity(row, worksheet); if (dictionaryConformity == null) { continue; } // lemma - may be absent, it appears one time for each vocabilary entry tryParseAndSetLemmaDictionaryCell(curEntryNumber, vocabularyEntry, worksheet); // language Language language = tryParseAndSetLanguageDictionaryCell(curEntryNumber, dictionaryConformity, worksheet); if (language == null) { continue; } string reconstructedForm = tryParseAndSetReconstructedFormDictionaryCell(curEntryNumber, dictionaryConformity, worksheet); if (String.IsNullOrEmpty(reconstructedForm)) { continue; } tryParseAndSetVariantDictionaryCell(curEntryNumber, dictionaryConformity, worksheet); tryParseAndSetZeroPositionDictionaryCell(curEntryNumber, dictionaryConformity, worksheet); tryParseAndSetPosition1DictionaryCell(curEntryNumber, dictionaryConformity, worksheet); tryParseAndSetPosition2DictionaryCell(curEntryNumber, dictionaryConformity, worksheet); tryParseAndSetPosition3DictionaryCell(curEntryNumber, dictionaryConformity, worksheet); tryParseAndSetPosition4DictionaryCell(curEntryNumber, dictionaryConformity, worksheet); tryParseAndSetPosition5DictionaryCell(curEntryNumber, dictionaryConformity, worksheet); tryParseAndSetPosition6DictionaryCell(curEntryNumber, dictionaryConformity, worksheet); tryParseAndSetPosition7DictionaryCell(curEntryNumber, dictionaryConformity, worksheet); tryParseAndSetPosition8DictionaryCell(curEntryNumber, dictionaryConformity, worksheet); tryParseAndSetPosition9DictionaryCell(curEntryNumber, dictionaryConformity, worksheet); tryParseAndSetPosition10DictionaryCell(curEntryNumber, dictionaryConformity, worksheet); tryParseAndSetPosition11DictionaryCell(curEntryNumber, dictionaryConformity, worksheet); tryParseAndSetPosition_0DictionaryCell(curEntryNumber, dictionaryConformity, worksheet); tryParseAndSetReconstructedMeaningDictionaryCell(curEntryNumber, dictionaryConformity, worksheet); tryParseAndSetCommentDictionaryCell(curEntryNumber, dictionaryConformity, worksheet); tryParseAndSetLinkDictionaryCell(curEntryNumber, dictionaryConformity, worksheet); vocabularyEntry.Dictionary_conformity.Add(dictionaryConformity); } } excelAppWorkbook.Close(); excelApp.Quit(); return(entries.Values); }