This project has moved and is read-only. For the latest updates, please go here.

Whats different to a file saved in excel?

Feb 26, 2015 at 12:14 PM
I recently tried importing an excel file created in ClosedXML into an external system. I received a generic error from their system which I couldn't decipher.

To see if there was an issue with the data I opened the file in excel, then resaved it via Office. I tried importing the file again and it succeeded. I then opened the original file and the "resaved" file in notepad++ and saw that they seemed to be different.

I guess my question is, what would be causing the CLosedXML file to be rejected by the external system? I'd have expected the ClosedXML xlsx file to be the same.

The file sizes were also different. Closed XML was 142kb but "resaving" in excel boosted it to "166Kb".

Is there something I can do to make the files the same without manually resaving it in excel?

Feb 26, 2015 at 1:20 PM
Just to explain..I add the following code to work around this issue (shouldn't have to in my opinion)
It effectively opens the file and saves it again
            Dim excelApp = New Microsoft.Office.Interop.Excel.Application()
            Dim excelWb = excelApp.Workbooks.Open(exportToFilePath)
            excelWb.Application.DisplayAlerts = False
            excelWb.SaveAs(Filename:=exportToFilePath, FileFormat:=Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook)
If someone could point out what I'm doing wrong in the first place, I'd appreciate it greatly as adding Excel interops makes me feel queasy

For the code to create the original doc is as simple as
            Dim wb As New XLWorkbook()
            Dim ws = wb.Worksheets.Add("Changed Products")

            ws.Cell(1, 1).InsertTable(changedProducts)
            ws.Cell(1, 1).Value = "Product ID"
            ws.Cell(1, 2).Value = "SKU"
            ws.Cell(1, 3).Value = "EAN"
            ws.Cell(1, 4).Value = "MPN"
            ws.Cell(1, 5).Value = "Name"
            ws.Cell(1, 6).Value = "UPC"

            ws.Columns.AdjustToContents() 'Adjust the column widths

            wb.Properties.Title = "Changed Data Export"
            wb.Properties.Company = "My company"

            wb.SaveAs(exportToFilePath) 'Save the file
Feb 27, 2015 at 8:40 AM
Anyone able to help? I'm trying to find a way of not adding COM references to my solution before it's release today.