1package fileio23import (4 "context"5 "path/filepath"6 "strings"7 "testing"89 "github.com/xuri/excelize/v2"10)1112func TestXLSXNotes(t *testing.T) {13 src := build(t, map[string]string{"A1": "Rent", "B1": "1450"})14 src.SetNote(addr(t, "B1"), "Due on\nthe 1st")15 src.SetNote(addr(t, "D9"), "Blank cell")16 book := src.Book()17 other, _ := book.AddSheet("Other", 1)18 other.SetNote(addr(t, "A1"), "_x0041_ stays & <so> do these")19 name := filepath.Join(t.TempDir(), "notes.xlsx")20 if _, err := Export(context.Background(), name, XLSX, SnapBook(src), ExportOptions{}); err != nil {21 t.Fatal(err)22 }23 // excelize reads them as Excel would.24 x, err := excelize.OpenFile(name)25 if err != nil {26 t.Fatal(err)27 }28 cs, err := x.GetComments(x.GetSheetName(0))29 if err != nil || len(cs) != 2 || cs[0].Cell != "B1" || cs[0].Text != "Due on\nthe 1st" {30 t.Errorf("excelize comments %+v, %v", cs, err)31 }32 x.Close()33 got, err := Import(context.Background(), name, Options{})34 if err != nil {35 t.Fatal(err)36 }37 s := got.Sheet38 if s.Note(addr(t, "B1")) != "Due on\nthe 1st" || s.Note(addr(t, "D9")) != "Blank cell" {39 t.Errorf("notes %q %q", s.Note(addr(t, "B1")), s.Note(addr(t, "D9")))40 }41 if n := s.Book().Lookup("Other").Note(addr(t, "A1")); n != "_x0041_ stays & <so> do these" {42 t.Errorf("escaped note %q", n)43 }44}4546func TestXLSXProtectionNote(t *testing.T) {47 x := excelize.NewFile()48 x.SetCellValue("Sheet1", "A1", 1)49 x.ProtectSheet("Sheet1", &excelize.SheetProtectionOptions{})50 name := filepath.Join(t.TempDir(), "protected.xlsx")51 if err := x.SaveAs(name); err != nil {52 t.Fatal(err)53 }54 x.Close()55 got, err := Import(context.Background(), name, Options{})56 if err != nil {57 t.Fatal(err)58 }59 if len(got.Sheet.Protections()) != 0 || !strings.Contains(strings.Join(got.Notes, "; "), "Protection of Sheet1 left out") {60 t.Errorf("protections %+v, notes %q", got.Sheet.Protections(), got.Notes)61 }62}