public void Load(string path, int episode) { m_path = path; m_episodeNo = episode; IWorkbook workbook = Factory.GetWorkbook(path); m_episodes = workbook.Worksheets.Count - 1; IWorksheet worksheet = workbook.Worksheets[m_episodeNo]; ShowTitleOriginal = worksheet.Cells[OriginalTitleCell].Formula; ShowTitleDubbed = worksheet.Cells[TranslatedEpisodeTitleCell].Formula; EpisodeNumber = worksheet.Cells[EpisodeNoCell].Formula; EpisodeTitleOriginal = worksheet.Cells[OriginalEpisodeTitleCell].Formula; EpisodeTitleDubbed = worksheet.Cells[TranslatedEpisodeTitleCell].Formula; EpisodeTranslator = worksheet.Cells[TranslatedByCell].Formula; try { EpisodeTranslationDate = !(worksheet.Cells[TranslationDateCell].Value is double) ? (!(worksheet.Cells[TranslationDateCell].Value is DateTime) ? DateTime.ParseExact(worksheet.Cells[TranslationDateCell].Formula, "MM.dd.yyyy", CultureInfo.InvariantCulture) : (DateTime)worksheet.Cells[TranslationDateCell].Value) : DateTime.FromOADate((double)worksheet.Cells[TranslationDateCell].Value); } catch (ArgumentException ex) { ShowDateParsingError(worksheet); } catch (FormatException ex) { ShowDateParsingError(worksheet); } Resume = worksheet.Cells[SummaryCell].Formula; int scriptStartRow = ScriptStartRow; ScriptLine list = null; ScriptLine scriptLine1 = null; Dictionary <string, ScriptLine> dictionary = new Dictionary <string, ScriptLine>(); while (scriptStartRow <= worksheet.UsedRange.RowCount) { IRange cell1 = worksheet.Cells[scriptStartRow, CharacterColumn]; IRange cell2 = worksheet.Cells[scriptStartRow, TimeColumn]; IRange cell3 = worksheet.Cells[scriptStartRow, LineColumn]; IRange cell4 = worksheet.Cells[scriptStartRow, CheckboxColumn]; string key = cell1.MergeArea.Formula.Trim(); string formula1 = cell2.MergeArea.Formula; string str = cell3.MergeArea.Formula.Trim(); string formula2 = cell4.MergeArea.Formula; if (!string.IsNullOrEmpty(key)) { ScriptLine scriptLine2 = new ScriptLine(); scriptLine2.Character = key; try { scriptLine2.Offset = MidiTime.Parse(formula1); } catch (FormatException ex) { int num = (int)MessageBox.Show("Invalid time code formatting in sheet " + worksheet.Name + " cell " + cell2.GetAddress(false, false, ReferenceStyle.A1, false, null)); scriptLine2.Offset = MidiTime.Zero; } scriptLine2.Line = str; scriptLine2.IsDone = !string.IsNullOrEmpty(formula2); if (list == null) { list = scriptLine2; } scriptLine2.PrevByTime = scriptLine1; if (scriptLine1 != null) { scriptLine1.NextByTime = scriptLine2; } if (dictionary.ContainsKey(key)) { scriptLine2.PrevByCharacter = dictionary[key]; dictionary[key].NextByCharacter = scriptLine2; } scriptLine1 = scriptLine2; dictionary[key] = scriptLine2; } scriptStartRow += cell1.MergeArea.RowCount; } m_lines = new ScriptLineCollection(list); m_lines.Sort(); workbook.Close(); }
public static FileInfo GetFileInfo(string path) { IWorkbook workbook; try { workbook = Factory.GetWorkbook(path); } catch (InvalidOperationException ex) { throw new InvalidDataException("Script not in supported format"); } IWorksheet worksheet = workbook.Worksheets[0]; FileInfo fileInfo = new FileInfo(); fileInfo.Title = worksheet.Cells[ShowInfoCell].Formula; if (string.IsNullOrEmpty(fileInfo.Title)) { throw new InvalidDataException("Script title not found in expected position"); } int length = workbook.Worksheets.Count - 1; fileInfo.Episodes = new EpisodeInfo[length]; for (int columnOffset = 0; columnOffset < length; ++columnOffset) { fileInfo.Episodes[columnOffset] = new EpisodeInfo(); IRange range = worksheet.Cells[EpisodeNoRowStartCell].Offset(0, columnOffset); if (!int.TryParse(range.Formula, out fileInfo.Episodes[columnOffset].Number)) { int num = (int)MessageBox.Show(string.Format("Invalid episode number format in {0}, sheet {1}, cell {2}", path, worksheet.Name, range.GetAddress(false, false, ReferenceStyle.A1, false, null)), "Error parsing episode number", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); throw new InvalidDataException("Episode number format invalid"); } fileInfo.Episodes[columnOffset].Title = workbook.Worksheets[columnOffset + 1].Cells[TranslatedTitleCell].Formula; if (string.IsNullOrEmpty(fileInfo.Episodes[columnOffset].Title)) { throw new InvalidDataException("Episode title not found in expected position"); } fileInfo.Episodes[columnOffset].FullNumber = workbook.Worksheets[columnOffset + 1].Cells[EpisodeNoCell].Formula; fileInfo.Episodes[columnOffset].LinesLeft = worksheet.Cells[LinesTotalRowStartCell].Offset(0, columnOffset).Formula; } fileInfo.LinesLeft = worksheet.Cells[LinesTotalLeftRowCell].Formula; return(fileInfo); }