private static string tryParseAndSetPosition7DictionaryCell(int rowNumber, Dictionary_conformity dictionaryConformity, Microsoft.Office.Interop.Excel.Worksheet worksheet) { string columnNumber = ExcelDictionaryColumn.POSITION_7.Column; string cellValue = parseStringValue(rowNumber, columnNumber, worksheet); if (String.IsNullOrEmpty(cellValue)) { return(null); } dictionaryConformity.p_7 = cellValue; return(cellValue); }
private static Dictionary_conformity tryGetNewDictionaryConformity(int rowNumber, Microsoft.Office.Interop.Excel.Worksheet worksheet) { int lineNumber = 0; string columnNumber = ExcelDictionaryColumn.LINE_NUMBER.Column; Microsoft.Office.Interop.Excel.Range dataRange = worksheet.Cells[rowNumber, columnNumber]; string cellValue = dataRange.Value2.ToString(); bool parsed = Int32.TryParse(cellValue, out lineNumber); if (!parsed) { return(null); } Dictionary_conformity conformity = new Dictionary_conformity(); conformity.Number_string = lineNumber; return(conformity); }
private static Language tryParseAndSetLanguageDictionaryCell(int rowNumber, Dictionary_conformity dictionaryConformity, Microsoft.Office.Interop.Excel.Worksheet worksheet) { string columnNumber = ExcelDictionaryColumn.LANGUAGE.Column; Microsoft.Office.Interop.Excel.Range dataRange = worksheet.Cells[rowNumber, columnNumber]; string cellValue = dataRange.Value2.ToString(); IEnumerable <Language> possibleLanguages = unitOfWork.LanguageRepository.Get(); if (possibleLanguages == null) { return(null); } Language firstSuitable = null; IEnumerator <Language> possibleLangEnumerator = possibleLanguages.GetEnumerator(); if (possibleLangEnumerator.MoveNext()) { firstSuitable = possibleLangEnumerator.Current; } dictionaryConformity.Language = firstSuitable; dictionaryConformity.ID_Language = firstSuitable.ID_Language; return(firstSuitable); }
private static string tryParseAndSetReconstructedMeaningDictionaryCell(int rowNumber, Dictionary_conformity dictionaryConformity, Microsoft.Office.Interop.Excel.Worksheet worksheet) { string columnNumber = ExcelDictionaryColumn.RECONSTRUCTED_MEANING.Column; string cellValue = parseStringValue(rowNumber, columnNumber, worksheet); if (String.IsNullOrEmpty(cellValue)) { return(null); } dictionaryConformity.Meaning = 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); }