In one of my ASP.NET applications, I was developing a page to extract some data to an xlsx file, and for this purpose I was using the library NPOI. Using Excel to open the xlsx file created by the application, I obtained different results depending on the server where the application was deployed: using some servers I could open the xlsx file without problems, while using other servers I got the following error:

Excel found unreadable content in ‘[filename].xlsx’. Do you want to recover the contents of this workbook?

After having struggled a lot I finally decided to unzip the xlsx file and make a file comparison between a working file and a “damaged” file.

I have found a difference in the file “docProps\core.xml”, tag “<dcterms:created xsi:type=”dcterms:W3CDTF”>”.

Here is an extract of the “damaged” file:

<dcterms:created xsi:type="dcterms:W3CDTF">2018-07-05T23.39.32Z</dcterms:created>

And here the same tag but as it appears in the working file:

<dcterms:created xsi:type="dcterms:W3CDTF">2018-07-05T23:39:32Z</dcterms:created>

As you can see, time separator character is different. So I modified the time separator in the “damaged” file and zipped the data to get an xlsx file again. Now Excel was able to open that file, without showing any error!

To finally solve the problem, I did a simple thing…. in each ASP.NET page that uses NPOI to generate an xlsx file I added this code in the OnInit event:

CultureInfo newCulture = (CultureInfo) System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
newCulture.DateTimeFormat.TimeSeparator = ":";
System.Threading.Thread.CurrentThread.CurrentCulture = newCulture;

Note that in order to make work the code above, you have to import the namespace System.Globalization.

Have a nice day!