|
|
@ -281,28 +281,38 @@ func (f *File) AutoFilter(sheet, hcell, vcell, format string) error {
|
|
|
|
formatSet, _ := parseAutoFilterSet(format)
|
|
|
|
formatSet, _ := parseAutoFilterSet(format)
|
|
|
|
|
|
|
|
|
|
|
|
var cellStart, cellEnd string
|
|
|
|
var cellStart, cellEnd string
|
|
|
|
cellStart, err = CoordinatesToCellName(hcol, hrow)
|
|
|
|
if cellStart, err = CoordinatesToCellName(hcol, hrow); err != nil {
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cellEnd, err = CoordinatesToCellName(vcol, vrow)
|
|
|
|
if cellEnd, err = CoordinatesToCellName(vcol, vrow); err != nil {
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ref := cellStart + ":" + cellEnd
|
|
|
|
ref, filterDB := cellStart+":"+cellEnd, "_xlnm._FilterDatabase"
|
|
|
|
wb := f.workbookReader()
|
|
|
|
wb := f.workbookReader()
|
|
|
|
|
|
|
|
sheetID := f.GetSheetIndex(sheet)
|
|
|
|
|
|
|
|
filterRange := fmt.Sprintf("%s!%s", sheet, ref)
|
|
|
|
d := xlsxDefinedName{
|
|
|
|
d := xlsxDefinedName{
|
|
|
|
Name: "_xlnm._FilterDatabase",
|
|
|
|
Name: filterDB,
|
|
|
|
Hidden: true,
|
|
|
|
Hidden: true,
|
|
|
|
LocalSheetID: intPtr(f.GetSheetIndex(sheet)),
|
|
|
|
LocalSheetID: intPtr(sheetID),
|
|
|
|
Data: fmt.Sprintf("%s!%s", sheet, ref),
|
|
|
|
Data: filterRange,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if wb.DefinedNames != nil {
|
|
|
|
if wb.DefinedNames == nil {
|
|
|
|
wb.DefinedNames.DefinedName = append(wb.DefinedNames.DefinedName, d)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
wb.DefinedNames = &xlsxDefinedNames{
|
|
|
|
wb.DefinedNames = &xlsxDefinedNames{
|
|
|
|
DefinedName: []xlsxDefinedName{d},
|
|
|
|
DefinedName: []xlsxDefinedName{d},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
var definedNameExists bool
|
|
|
|
|
|
|
|
for idx := range wb.DefinedNames.DefinedName {
|
|
|
|
|
|
|
|
definedName := wb.DefinedNames.DefinedName[idx]
|
|
|
|
|
|
|
|
if definedName.Name == filterDB && *definedName.LocalSheetID == sheetID && definedName.Hidden {
|
|
|
|
|
|
|
|
wb.DefinedNames.DefinedName[idx].Data = filterRange
|
|
|
|
|
|
|
|
definedNameExists = true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if !definedNameExists {
|
|
|
|
|
|
|
|
wb.DefinedNames.DefinedName = append(wb.DefinedNames.DefinedName, d)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
refRange := vcol - hcol
|
|
|
|
refRange := vcol - hcol
|
|
|
|
return f.autoFilter(sheet, ref, refRange, hcol, formatSet)
|
|
|
|
return f.autoFilter(sheet, ref, refRange, hcol, formatSet)
|
|
|
|