如何创建xsd来验证excel文件 [英] how to create xsd to validate excel file

查看:76
本文介绍了如何创建xsd来验证excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好,我正在使用c#语言获胜。我必须读取一个excel文件(xls和xlsx),我会用xsd文件验证它,但我错了,因为我收到一个错误:根级别的数据无效。第1行,位置1,如果我使用相同的xsd与corrispondent xml文件这正常工作,所以在我的Excel文件或代码中的问题,以验证我的Excel文件。我已经使用了这段代码:

XmlReaderSettings booksSettings = new XmlReaderSettings();

booksSettings.Schemas.Add(http://www.w3.org7XMLSchema,XMLImportUsers。 xsd);

booksSettings.ValidationType = ValidationType.Schema;

XmlReader books = XmlReader.Create(@" D:\ test.xml",booksSettings);



while(books.Read()){}



< pre lang =" xml" ;>我的xsd



& lt;?xml version =& quot; 1.0& quot; encoding =& quot; utf-8& quot; ?& gt;

& lt; xs:schema xmlns:xs =& quot; http://www.w3.org/2001/XMLSchema& quot;& gt;

& lt; xs:element name =& quot; UserSettings& quot;& gt;

& lt; xs:complexType& gt;

& lt; xs:sequence& gt;

& lt; xs:element name =& quot; ID_UTENTE& quot; type =& quot; xs:decimal& quot;的minOccurs =安培; QUOT 1安培;曲ot; maxOccurs =& quot; 1& quot; /& gt;

& lt; xs:element name =& quot; ID_GRUPPO& quot;类型=安培; QUOT; XS:小数&安培; QUOT;的minOccurs =安培; QUOT 0安培; QUOT; maxOccurs =& quot; 1& quot; /& gt;

等等



你能帮我发一个代码示例吗?从xsd验证xls / xlsx罚款?提前谢谢< / pre>

解决方案

Excel(从2007及更高版本开始)使用非典型的XML文件。请参阅 OpenXML标准 [ ^ ]。您不能以这种方式验证Excel文件。



旧版本的MS Excel不支持OpenXML标准。


good morning, i am in a win application in c# language. i have to read a excel file (both xls and xlsx) and i would validate it with an xsd file but i wrong something because i get an error: data at the root level is invalid. Line 1, position 1 if i use the same xsd with corrispondent xml file this work correctly so shoul be a problem in my excel file or in a code to validate my excel file. i have use this code:
XmlReaderSettings booksSettings = new XmlReaderSettings();
booksSettings.Schemas.Add("http://www.w3.org7XMLSchema",XMLImportUsers.xsd");
booksSettings.ValidationType = ValidationType.Schema;
XmlReader books = XmlReader.Create(@"D:\test.xml",booksSettings);

while (books.Read()) { }

<pre lang="xml">my xsd

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;xs:schema xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;&gt;
&lt;xs:element name=&quot;UserSettings&quot;&gt;
&lt;xs:complexType&gt;
&lt;xs:sequence&gt;
&lt;xs:element name=&quot;ID_UTENTE&quot; type=&quot;xs:decimal&quot; minOccurs=&quot;1&quot; maxOccurs=&quot;1&quot;/&gt;
&lt;xs:element name=&quot;ID_GRUPPO&quot; type=&quot;xs:decimal&quot; minOccurs=&quot;0&quot; maxOccurs=&quot;1&quot;/&gt;
etc etc

Can you help me and post a code example to validate xls /xlsx fine from an xsd? thanks in advance</pre>

解决方案

Excel (starting from 2007 and higher) uses non-typical XML file. See OpenXML standard[^]. You can't validate Excel files this way.

Older version of MS Excel does not support OpenXML standard.


这篇关于如何创建xsd来验证excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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