1package headless23import (4 "src.rest/cat/012/internal/sheet"5)67// Problem is a cell whose formula shows an error after recalculating.8type Problem struct {9 Sheet string10 Addr sheet.Addr11 Value string // the error as the cell shows it: #DIV/0!12 Why string // what the screen's context line says about it, or ""13 // JEV is set when the error is a JEV function's with nothing to14 // answer it: --jev asks the model.15 JEV bool16}1718// At is the problem's cell with its sheet: Q3!B7.19func (p Problem) At() string {20 return sheet.Qualified(p.Sheet, sheet.Rect{From: p.Addr, To: p.Addr})21}2223// Recalc recomputes every formula of w and returns the cells showing24// errors, sheet by sheet in tab order and row by row, and whether a25// circular reference was found.26func Recalc(w *sheet.Workbook) (problems []Problem, circular bool) {27 w.RecalcAll()28 return Errors(w), w.Circular29}3031// Errors returns the cells of w showing errors, without recalculating.32// A cell an array spilled an error into is its formula's problem, so33// only formulas are listed.34func Errors(w *sheet.Workbook) []Problem {35 var out []Problem36 for _, s := range w.Sheets() {37 for _, a := range s.Addrs() {38 v := s.Value(a)39 if v.Kind != sheet.Error {40 continue41 }42 c := s.Cell(a)43 if c == nil || !c.IsFormula() {44 continue45 }46 out = append(out, Problem{Sheet: s.Name(), Addr: a, Value: v.Str, Why: s.ExplainError(a),47 JEV: len(s.RemoteCalls(a)) > 0 && (v == sheet.ErrNoRemote || sheet.IsPending(v))})48 }49 }50 return out51}