在使用OpenXML SDK创建的Excel文档中是否有找到错误的工具? [英] Is there a tool to find errors in Excel documents created with the OpenXML SDK?

查看:140
本文介绍了在使用OpenXML SDK创建的Excel文档中是否有找到错误的工具?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用OpenXML SDK创建的Excel文档中,是否存在可以识别错误确切位置的工具?

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

我已经使用Microsoft OpenXML SDK 2.5创建了一个Excel文件(也尝试了v 2.0,但结果相同),并且一定在代码中出现了错误.我想找出的是哪里.

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.

SDK验证功能均表示该文档有效.使用OpenXML SDK Productivity工具验证生成的Excel文件时,响应为在包中未找到验证错误".

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".

但是..当使用MS Excel打开Excel文件时,错误提示用户需要修复文档,修复后文档会正确显示. Excel修复日志说table.xml文件有错误,但该文件上没有错误的位置. Excel修复日志如下:

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:

已修复的记录:/xl/tables/table.xml中的表(列表)

除了OpenXML SDK生产力工具之外,是否还有其他工具可用于验证Excel电子表格并识别文档中的错误?

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?

推荐答案

虽然帖子很旧,但我也遇到了同样的情况&因此我创建了一个Windows应用程序,该应用程序将使用文件对话框&解析它以显示其中的错误.第一个功能只是使用对话框&来占用生成的文件名.第二种方法显示在生成的文件中观察到的所有错误.

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.

生成的输出如图像 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);
        }
    }

这篇关于在使用OpenXML SDK创建的Excel文档中是否有找到错误的工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆