Is there a tool to find errors in Excel documents created with the OpenXML SDK?
Asked Answered
C

1

7

Is there a tool that can identify the exact location of errors in an Excel document created using the OpenXML SDK?

I've created an Excel file using the Microsoft OpenXML SDK 2.5 (also tried v 2.0 with the same result), and must have made a mistake somewhere in the code. What I'm trying to find out is where.

The SDK validation functions all say the document is valid. When validating the generated Excel file using the OpenXML SDK Productivity tool, the response is "No validation error is found in the package".

But.. when opening the Excel file using MS Excel, an error alerts the user that the document needs repair, after repair the document shows up correctly. The Excel repair log says the table.xml file has an error, but not the location of the error on the file. Excel repair log follows:

Repaired Records: Table from /xl/tables/table.xml (List)

Is there a tool other than the OpenXML SDK productivity tool that can be used to validate Excel spreadsheets and identify errors in the document?

Choe answered 29/8, 2013 at 16:28 Comment(0)
I
5

Though the post is old, but I was stuck with the same situation & so I created a windows application which shall accept the file using a file dialog & parse it to display the errors within. The first function just takes up the generated file name using the dialog box & the second methods displays all the errors that are observed within the generated file.

The generated output is as shown in the image http://s18.postimg.org/60rqf78gp/Parse_Open_XML_Generated_File.jpg

private void button1_Click(object sender, EventArgs e)
    {
        lblError.Text = "";

        if (openFileDialog1.ShowDialog() == DialogResult.OK)
        {
            textBox1.Text = openFileDialog1.SafeFileName;                
        }

    }

    private void button2_Click(object sender, EventArgs e)
    {
        try
        {
            var validator = new OpenXmlValidator();
            int count = 0;
            foreach (ValidationErrorInfo error in validator.Validate(SpreadsheetDocument.Open(openFileDialog1.FileName, true)))
            {
                lblError.Text += "\r\n";
                count++;
                lblError.Text += ("Error Count : " + count) + "\r\n";
                lblError.Text += ("Description : " + error.Description) + "\r\n";
                lblError.Text += ("Path: " + error.Path.XPath) + "\r\n";
                lblError.Text += ("Part: " + error.Part.Uri) + "\r\n";
            }
            Console.ReadKey();
        }
        catch (Exception ex)
        {
            lblError.Text += (ex.Message);
        }
    }
Ionium answered 10/12, 2013 at 12:51 Comment(3)
Tried that thanks, the OpenXmlValidator returns no errors, but when you open the file on Excel, it reports errors and tries to repair them. Looks like OpenXmlValidator doesn't catch as many errors as Excel does.Choe
OpenXmlValidator is useless it seems. Excel detect all kinds of errors while OpenXmlValidator never detect anything. And the error info from Excel is useless too! Thank you, Microsoft.Otten
In my case the cells were not in rising order, eg. for a row: A4,B4,D4,C4. Excel does not like that. Was a bug in DevExpress export.Otten

© 2022 - 2024 — McMap. All rights reserved.