@@ -215,7 +215,7 @@ var (
215215 criteriaL,
216216 criteriaG,
217217 }
218- tableRefRe = regexp.MustCompile(`^(\w+)\[([^\]]+ )\]$`)
218+ tableRefRe = regexp.MustCompile(`^(\w+)\[([^\]]* )\]$`)
219219)
220220
221221// calcContext defines the formula execution context.
@@ -1518,6 +1518,39 @@ func parseRef(ref string) (cellRef, bool, bool, error) {
15181518func pickColumnInTableRef(tblRef tableRef, colName string) (string, error) {
15191519 offset := -1
15201520
1521+ if colName == "#HEADERS" {
1522+ coords, err := rangeRefToCoordinates(tblRef.ref)
1523+ if err != nil {
1524+ return "", err
1525+ }
1526+ headerStart, err := CoordinatesToCellName(coords[0], coords[1])
1527+ if err != nil {
1528+ return "", err
1529+ }
1530+ headerEnd, err := CoordinatesToCellName(coords[2], coords[1])
1531+ if err != nil {
1532+ return "", err
1533+ }
1534+ return fmt.Sprintf("%s!%s:%s", tblRef.sheet, headerStart, headerEnd), nil
1535+ } else if colName == "#ALL" {
1536+ return fmt.Sprintf("%s!%s", tblRef.sheet, tblRef.ref), nil
1537+ } else if colName == "" {
1538+ coords, err := rangeRefToCoordinates(tblRef.ref)
1539+ if err != nil {
1540+ return "", err
1541+ }
1542+ // skip the header row
1543+ dataStart, err := CoordinatesToCellName(coords[0], coords[1]+1)
1544+ if err != nil {
1545+ return "", err
1546+ }
1547+ dataEnd, err := CoordinatesToCellName(coords[2], coords[3])
1548+ if err != nil {
1549+ return "", err
1550+ }
1551+ return fmt.Sprintf("%s!%s:%s", tblRef.sheet, dataStart, dataEnd), nil
1552+ }
1553+
15211554 // Column ID is not reliable for order so we need to iterate through them.
15221555 for i, otherColName := range tblRef.columns {
15231556 if colName == otherColName {
0 commit comments