Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pivot table error: Repaired Records: PivotTable report from /xl/pivotTables/pivotTable1.xml part #1240

Closed
msilvoso opened this issue May 30, 2022 · 4 comments
Labels
duplicate This issue or pull request already exists

Comments

@msilvoso
Copy link

Pivot table xml does not seem to contain any value and provides a correct output after repair by Excel

<code>
package main

import (
	"bytes"
	"fmt"
	"github.com/xuri/excelize/v2"
	"os"
)

func main() {
	xl := excelize.NewFile()
	// count unique data
	dates := []string{"01/04/2022", "01/04/2022", "01/04/2022", "01/04/2022", "01/04/2022", "01/04/2022", "01/04/2022",
		"01/04/2022", "01/04/2022", "01/04/2022", "01/04/2022", "01/04/2022", "01/04/2022", "01/04/2022", "01/04/2022",
		"01/04/2022", "01/04/2022", "02/04/2022", "02/04/2022", "02/04/2022", "03/04/2022", "03/04/2022", "03/04/2022",
		"03/04/2022", "03/04/2022", "03/04/2022", "03/04/2022", "03/04/2022", "03/04/2022", "03/04/2022", "03/04/2022",
		"03/04/2022", "04/04/2022", "04/04/2022", "04/04/2022", "04/04/2022", "04/04/2022", "04/04/2022", "04/04/2022",
		"04/04/2022", "04/04/2022", "04/04/2022", "04/04/2022", "04/04/2022", "05/04/2022", "05/04/2022", "05/04/2022",
		"05/04/2022", "05/04/2022", "05/04/2022", "05/04/2022", "05/04/2022", "05/04/2022", "05/04/2022", "05/04/2022",
		"05/04/2022", "05/04/2022", "05/04/2022", "05/04/2022", "05/04/2022", "05/04/2022", "05/04/2022", "05/04/2022",
		"05/04/2022", "05/04/2022", "05/04/2022", "06/04/2022", "06/04/2022", "06/04/2022", "06/04/2022", "06/04/2022",
		"06/04/2022", "06/04/2022", "06/04/2022", "06/04/2022", "06/04/2022", "06/04/2022", "06/04/2022", "06/04/2022",
		"06/04/2022", "06/04/2022", "06/04/2022", "06/04/2022", "07/04/2022", "07/04/2022", "07/04/2022", "07/04/2022",
		"07/04/2022", "07/04/2022", "07/04/2022", "07/04/2022", "07/04/2022", "07/04/2022", "07/04/2022", "07/04/2022",
		"08/04/2022", "08/04/2022", "08/04/2022", "08/04/2022", "08/04/2022", "08/04/2022", "08/04/2022", "08/04/2022",
		"08/04/2022", "08/04/2022", "08/04/2022", "08/04/2022", "09/04/2022", "09/04/2022", "09/04/2022", "09/04/2022",
		"10/04/2022", "10/04/2022", "10/04/2022", "10/04/2022", "10/04/2022", "11/04/2022", "11/04/2022", "11/04/2022",
		"11/04/2022", "11/04/2022", "11/04/2022", "11/04/2022", "11/04/2022", "11/04/2022", "11/04/2022", "11/04/2022",
		"11/04/2022", "11/04/2022", "11/04/2022", "12/04/2022", "12/04/2022", "12/04/2022", "12/04/2022", "12/04/2022",
		"12/04/2022", "12/04/2022", "13/04/2022", "13/04/2022", "13/04/2022", "13/04/2022", "13/04/2022", "13/04/2022",
		"13/04/2022", "13/04/2022", "13/04/2022", "13/04/2022", "13/04/2022", "13/04/2022", "13/04/2022", "13/04/2022",
	}
	xl.NewSheet("Sheet1")
	xl.SetCellValue("Sheet1", "A1", "DATE")
	row := 1
	for _, v := range dates {
		row++
		xl.SetCellValue("Sheet1", fmt.Sprintf("A%d", row), v)
	}
	// count hits
	xl.NewSheet("Count")
	if err := xl.AddPivotTable(&excelize.PivotTableOption{
		DataRange:       fmt.Sprintf("Sheet1!$A$1:$A$%d", row),
		PivotTableRange: "Count!$A$1:$C$14",
		Rows:            []excelize.PivotTableField{{Data: "DATE", Name: "Date"}},
		Data:            []excelize.PivotTableField{{Data: "DATE", Name: "Count", Subtotal: "Count"}},
		RowGrandTotals:  true,
	}); err != nil {
		fmt.Fprintf(os.Stderr, err.Error())
		os.Exit(1)
	}
	xl.Close()
	buf := new(bytes.Buffer)
	_, err := xl.WriteTo(buf)
	if err != nil {
		fmt.Fprintf(os.Stderr, err.Error())
		os.Exit(1)

I get a corrupted file that is correctly repaired by Excel

I was expecting a file that did not need to be repaired

go version go1.18.2 linux/amd64

7a6d5f5

on Linux

@xuri
Copy link
Member

xuri commented May 31, 2022

Thanks for your feedback. Which version of the Excel application are you using? I have tested with Excel for Mac 16.58 (22021501), Office 2007 (12.0.4518.1014), 2010 (14.0.4763.1000), and it works well.

@xuri xuri added the needs more info This issue can't reproduce, need more info label May 31, 2022
@msilvoso
Copy link
Author

Hello,

Excel 2016 on windows (16.0.5317.1000) MSO (16.0.5278.1000) 32-bit

I have attached the xml before repair and after repair for comparison.

Best regards,
pivotTable1_afterrepair.xml.txt
pivotTable1_beforerepair.xml.txt

Manu

@xuri
Copy link
Member

xuri commented May 31, 2022

I think this issue may be a duplicate with #1203, I have fixed it by commit c2be30c, please make sure the library version was 7a6d5f5 or upgrade to using the master branch code.

@msilvoso
Copy link
Author

Oh yes, you are correct. Sorry about that. I can confirm that the latest repository version works.

Thank you!

@xuri xuri added duplicate This issue or pull request already exists and removed needs more info This issue can't reproduce, need more info labels May 31, 2022
@xuri xuri closed this as completed Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants