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

有些话、适合烂在心里 提交于 2019-12-04 07:41:44

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);
        }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!