Giter Club home page Giter Club logo

Comments (3)

xuri avatar xuri commented on May 17, 2024 1

Contributions are welcome. I need some time to clarify exactly how to support this feature.

from excelize.

edwardfward avatar edwardfward commented on May 17, 2024

I made the following adjustments and recommend providing a slice of column indexes where a
filter should be visible.

// xmlTable.go

// Table directly maps the format settings of the table.
type Table struct {
	tID               int
	rID               string
	tableXML          string
	Range             string
	Name              string
	StyleName         string
	ShowColumnStripes bool
	ShowFirstColumn   bool
	ShowHeaderRow     *bool
	ShowLastColumn    bool
	ShowRowStripes    *bool
	FilterColumns     []int  // column indexes to enable filter button
}
        // table.go

	_ = f.setTableColumns(sheet, !hideHeaderRow, x1, y1, x2, &t)
	if hideHeaderRow {
		t.AutoFilter = nil
		t.HeaderRowCount = intPtr(0)
	}

        // add filter columns (ln 371)

	if !hideHeaderRow && opts.FilterColumns != nil {
		width := x2 - x1 + 1
		ff := make([]*xlsxFilterColumn, width)

		cc := make(map[int]bool)
		for _, c := range opts.FilterColumns {
			cc[c] = true
		}

		for i := 0; i < width; i++ {
			showFilter := false
			if cc[i] {
				showFilter = true
			}

			ff[i] = &xlsxFilterColumn{
				ColID:      i,
				HiddenButton: !showFilter,
			}
		}

		t.AutoFilter = &xlsxAutoFilter{
			Ref:          ref,
			FilterColumn: ff,
		}
	}
   // main.go

	// Create table.
	show := true
	if err = f.AddTable("Sheet2", &excelize.Table{
		Name:          "Table1",
		Range:         fmt.Sprintf("%s:%s", firstCell, currentCell),
		ShowHeaderRow: &show,
		FilterColumns: []int{0, 1, 2},
	}); err != nil {
		fmt.Println(err)
	}

Outcome (no corruption errors):

Screenshot 2024-01-27 at 5 12 31 PM

from excelize.

edwardfward avatar edwardfward commented on May 17, 2024

@xuri Happy to take this and submit a PR if you feel it merits an enhancement.

from excelize.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.