Problem: generated xlsx needs to be repaired when opened by Excel 2012

Topics: Developer Forum, User Forum
Mar 18, 2013 at 11:32 AM
Hello!

I have an project that needs to generate xlsx-Files from a database. I am using ExcelPackage simply as descriped in the "Getting started"-Section ( Getting Started ).

(vb)
Using xlPackage As New ExcelPackage(newFile)
Dim worksheet As ExcelWorksheet = xlPackage.Workbook.Worksheets.Add(FileManager.WorksheetName)

' Header
worksheet.Cell(row, ProductID).Value = "ProductID"

'Content
For Each ...
....
worksheet.Cell(row, ProductID).Value = p.ProductID.ToString
....
Next

xlPackage.Save()
End Using
This works fine and a file is generated. But when I open this file, I got an Errormessage (sadly in German..)

Image
(We found a Problem in 'products(6).xlsx'. Recover as much as possible? If you trust... bla bla 'Ja')

Then the file is opened and the content is showen. All content that is meant to be there is there, no data lost etc.

Because I provide the file via Webserver i have to allow modifications:

Image

When I click I get a Message telling me that Excel needed to repair the File in order to open it.

Image

When i close the Message i can work with the file as usual. I can save it, load it into my application, add stuff and so on, so the file itself seems not to be broken at all.

error.xml:
<?xml version="1.0" encoding="UTF-8" standalone="true"?>
-<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><logFileName>error013960_01.xml</logFileName><summary>Fehler in Datei 'D:\Download\products (6).xlsx'</summary>-<additionalInfo><info>Excel hat die Überprüfung und Reparatur auf Dateiebene abgeschlossen. Einige Teile dieser Arbeitsmappe wurden repariert oder verworfen.</info></additionalInfo>-<repairedRecords summary="Die folgenden Reparaturen wurden durchgeführt:_x000d__x000a__x000d__x000a_"><repairedRecord>Reparierte Datensätze: Zellinformationen von /xl/worksheets/sheet1.xml-Part</repairedRecord></repairedRecords></recoveryLog>
As said the generated file works fine but the "error"-Messages stating that the file is broken are annoying.
Does anybody have similar issues or any idea how this issue is caused? Is there a special step I have to do in order to generate a new xlsx file from scratch? Thanks a lot for any help
Mar 19, 2013 at 9:44 AM
Hello again,

I figuered out what the problem is:

Image

due to my localisation to German my ".ToString()" Methods of Decimals, floats changes a value of "2.5" to "2,5". Excel does not like that obviously. My current solution:

I added 2 set-methods to the "ExcelCell.cs" --> (~line 103)
        /// <summary>
        /// Sets the value of the Cell. Handles Location-Problems (2,5 instead of 2.5 etc)
        /// </summary>
        public decimal ValueAsDecimal
        {
            set
            {
                this.Value = value.ToString(System.Globalization.CultureInfo.InvariantCulture);
            }
        }
and
        /// <summary>
        /// Sets the value of the Cell. Handles Location-Problems (2,5 instead of 2.5 etc)
        /// </summary>
        public double ValueAsDouble
        {
            set
            {
                this.Value = value.ToString(System.Globalization.CultureInfo.InvariantCulture);
            }
        }
Works for me.

kind regards