protected ILinksAnalysis ExtendFromWorkbookList(Range range) { if (range == null) { return(null); } StatusAvailable?.Invoke(this, new EventArgs <string>("Loading background processor ...")); var nameList = range.GetNameList(); using (var newExcel = WorkbookProcessor.New(range.Application, true)) { foreach (var item in nameList) { if (item is string path) { if (!File.Exists(path)) { AddFileAccessError(path, "File not found."); continue; } StatusAvailable?.Invoke(this, new EventArgs <string>($"Processing {path} ...")); try { newExcel.DoOnWorkbook(item, wb => ExtendFromWorkbook(wb)); } catch (IOException ex) { AddFileAccessError(path, $"IOException: '{ex.Message}'"); } finally { StatusAvailable?.Invoke(this, new EventArgs <string>("Ready")); } } } } return(this); }
protected ILinksAnalysis ExtendFromWorksheet(Worksheet ws) { if (ws == null) { return(null); } var usedRange = ws.UsedRange; for (var colNo = 1; colNo <= usedRange.Columns.Count; colNo++) { var percentage = 100 * colNo / usedRange.Columns.Count; StatusAvailable?.Invoke(this, new EventArgs <string>($"Searching {ws.Parent.Name}[{ws.Name}] ... ({percentage,3}%)")); var lastRowNo = ws.Cells[ws.Rows.Count, colNo].End(Excel.XlDirection.xlUp).Row; for (long rowNo = 1; rowNo <= lastRowNo; rowNo++) { var cell = usedRange[rowNo, colNo]; if (cell.Formula is string formula && formula.Length > 0 && formula[0] == '=') { var cellRef = ws.NewCellRef(cell as Range); ParseFormula(cellRef, formula); } } } return(this); }
protected static void OnStatusAvailable(object sender, string message) => StatusAvailable?.Invoke(sender, new EventArgs <string>(message));