ClosedXML.Report icon indicating copy to clipboard operation
ClosedXML.Report copied to clipboard

Pivot table: Excel completed file level validation and repair. Some parts of this workbook may have been repaired or discarded.

Open Aduthraes opened this issue 3 years ago • 15 comments

Hi,

i was trying to create an example with pivot tables and i've used your template tPivot1.xlsx When trying to open the generated excel file with Office 2016 and 2019, i'm getting the following error:

"Excel completed file level validation and repair. Some parts of this workbook may have been repaired or discarded. Removed Part: /xl/pivotTables/pivotTable.xml part with XML error. (PivotTable view) HRESULT 0x8000ffff Line 1, column 0."

I thought i was doing something wrong until i opened the same file with LibreOffice and i saw that the pivot table was correctly generated.

Am i missing something or is there really an issue with Office?

Thank you

Aduthraes avatar May 13 '21 17:05 Aduthraes

Hi. Have you changed something in the template or in the report generation code?

b0bi79 avatar May 17 '21 06:05 b0bi79

Hi, i've changed the name of the named range to Data and that was the only change i've made in the template. Here's the class and export methods:

public class Order
{
    public string Company { get; set; }
    public int PaymentMethod { get; set; }
    public string OrderNo { get; set; }
    public DateTime ShipDate { get; set; } 
    public int ItemsTotal { get; set; }
    public int TaxRate { get; set; }
    public int AmountPaid { get; set; }
}

    public virtual byte[] Export<TEntity>(IList<TEntity> dataToExport, Guid templateId) where TEntity : class
    {
        byte[] template = GetTemplateFile(templateId);

        if (template == null) return null;

        using (MemoryStream stream = new MemoryStream())
        {
            stream.Write(template, 0, template.Length);
            stream.Seek(0, SeekOrigin.Begin);
            return CreateExcelFromTemplate.CreateExcel(
                stream,
                new
                {
                    Data = dataToExport,
                    DynamicHeaders = DynamicColumnsInExcel,
                    Username = _userService.Fullname,
                    CreationDate = DateTime.Now.ToString("dd/MM/yyyy"),
                    CreationDateTime = DateTime.Now.ToString("dd/MM/yyyy HH:mm"),
                    Reference = Reference,
                    Title = Title
                });
        }
    }

public static class CreateExcelFromTemplate
{
    /// <summary>
    /// Generate excel file from template by file stream
    /// </summary>
    /// <param name="fileStream"></param>
    /// <param name="data"></param>
    /// <returns>File byte array</returns>
    public static byte[] CreateExcel(Stream fileStream, object data)
    {
        using (XLTemplate template = new XLTemplate(fileStream))
        {
            return Generate(template, data);
        }
    }

    private static byte[] Generate(XLTemplate template, object data)
    {
        template.AddVariable(data);
        template.Generate();

        using (MemoryStream outputStream = new MemoryStream())
        {
            template.SaveAs(outputStream);
            return outputStream.ToArray();
        }
    }

} Thank you for the quick response.

Aduthraes avatar May 17 '21 10:05 Aduthraes

Can you tell which version of ClosedXML you are using?

b0bi79 avatar May 17 '21 12:05 b0bi79

v0.2.1

Aduthraes avatar May 17 '21 13:05 Aduthraes

0.2.1 it is a ClosedXML.Report version. Which version of ClosedXML?

b0bi79 avatar May 17 '21 15:05 b0bi79

I didn't install ClosedXML, just ClosedXML.Report. Do i have to install both of them?

Aduthraes avatar May 17 '21 15:05 Aduthraes

ClosedXML should be installed automatically as a dependency on ClosedXML.Report. Most likely this is the latest compatible version, it should be 0.95.1. Tomorrow I'll check how Pivot works with ClosedXML 0.95.1.

b0bi79 avatar May 17 '21 18:05 b0bi79

You're right, it was installed as a dependency. Version 0.95.0

Aduthraes avatar May 17 '21 18:05 Aduthraes

Hi, just un update. The problem persists in version 0.95.4

Aduthraes avatar May 26 '21 13:05 Aduthraes

Hi. Have you solved this issue? You're right, ClosedXML generates a file that Excel cannot read. The fix should be in ClosedXML.

b0bi79 avatar May 27 '21 15:05 b0bi79

Hi. I didn't fix the issue yet. Do you know what's causing the problem? I could try to help if you give some hints on where the issue might be. Thank you.

Aduthraes avatar Jun 02 '21 17:06 Aduthraes

Any news? I'm having the same issue with (0.95.4)

C1rdec avatar Feb 23 '22 07:02 C1rdec

The fix should be in ClosedXML. Not fixed yet.

b0bi79 avatar Mar 15 '22 18:03 b0bi79

Can I help in any way to speed things up?

C1rdec avatar Mar 15 '22 18:03 C1rdec

I think, I found the problem... I described it here: https://github.com/ClosedXML/ClosedXML/discussions/2135

StepanHusa avatar Jul 26 '23 08:07 StepanHusa