Skip to content

Pivot tables: colFields "data" field always after user specified colFields #2425

Description

@kekovubicahome

Description

  1. In Go scope :
    file - pivotTable.go
// addPivotColFields create pivot column fields by given pivot table
// definition and option.
func (f *File) addPivotColFields(pt *xlsxPivotTableDefinition, opts *PivotTableOptions) error {
	if len(opts.Columns) == 0 {
		if len(opts.Data) <= 1 {
			return nil
		}
		pt.ColFields = &xlsxColFields{}
		// in order to create pivot table in case there is no input from Columns
		pt.ColFields.Count = 1
		pt.ColFields.Field = append(pt.ColFields.Field, &xlsxField{
			X: -2,
		})
		return nil
	}

	pt.ColFields = &xlsxColFields{}

	// col fields
	colFieldsIndex, err := f.getPivotFieldsIndex(opts.Columns, opts)
	if err != nil {
		return err
	}
	for _, fieldIdx := range colFieldsIndex {
		pt.ColFields.Field = append(pt.ColFields.Field, &xlsxField{
			X: fieldIdx, // here is user defined colFields always before DATA colField (-2) and no opportunity to change order
		})
	}

	// in order to create pivot in case there is many Columns and Data
	if len(opts.Data) > 1 {
		pt.ColFields.Field = append(pt.ColFields.Field, &xlsxField{
			X: -2, // here is -2 always after user defined fields and no opportunity to change order 
		})
	} 

	// count col fields
	pt.ColFields.Count = len(pt.ColFields.Field)
	return err
}

In excelize.PivotTableOptions no way to change order of such colField as Data(-2)

  <colFields count="2">
     <field x="15"></field>
        <field x="-2"></field> // this always after my defined column with 15 idx
    </colFields>

Could u please, dear friend add some option to change order of such fields some way ?

Additional context

No response

Validations

  • Check that there isn't already an issue that requests the same feature to avoid creating a duplicate.

Activity

  1. xuri commented on Sep 22, 2026

    @xuri
    Member

    Thanks for your report this issue. Would you like to create a pull request for this?

  2. kekovubicahome commented on Oct 6, 2026

    @kekovubicahome
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions