Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 576
Lenny Avatar asked Aug 29 '13 16:08

Lenny


1 Answers

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);
        }
    }
like image 187
Manoj Kapoor Avatar answered Sep 28 '22 05:09

Manoj Kapoor