本文整理汇总了C#中DocumentFormat.OpenXml.Validation.OpenXmlValidator类的典型用法代码示例。如果您正苦于以下问题:C# OpenXmlValidator类的具体用法?C# OpenXmlValidator怎么用?C# OpenXmlValidator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OpenXmlValidator类属于DocumentFormat.OpenXml.Validation命名空间,在下文中一共展示了OpenXmlValidator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: X006_Xlsx_DeleteAdd_CoreExtendedProperties
public void X006_Xlsx_DeleteAdd_CoreExtendedProperties()
{
var docName = "Spreadsheet.xlsx";
var ba = File.ReadAllBytes(s_TestFileLocation + docName);
using (MemoryStream ms = new MemoryStream())
{
ms.Write(ba, 0, ba.Length);
using (SpreadsheetDocument doc = SpreadsheetDocument.Open(ms, true))
{
var corePart = doc.CoreFilePropertiesPart;
var appPart = doc.ExtendedFilePropertiesPart;
doc.DeletePart(corePart);
doc.DeletePart(appPart);
doc.AddCoreFilePropertiesPart();
doc.AddExtendedFilePropertiesPart();
doc.AddCustomFilePropertiesPart();
doc.AddDigitalSignatureOriginPart();
doc.AddExtendedPart("relType", "contentType/xml", ".xml");
var tnPart = doc.AddThumbnailPart(ThumbnailPartType.Jpeg);
doc.DeletePart(tnPart);
tnPart = doc.AddThumbnailPart("image/jpg");
OpenXmlValidator v = new OpenXmlValidator(FileFormatVersions.Office2013);
var errs = v.Validate(doc);
Assert.Equal(1, errs.Count());
}
}
}
开发者ID:eriawan,项目名称:Open-XML-SDK,代码行数:27,代码来源:TestXlsx01.cs
示例2: MinimumStyle
public void MinimumStyle()
{
using (MemoryStream mem = new MemoryStream())
{
WordDocument doc = new WordDocument(mem);
doc.Process(new HtmlParser("<div style='font:10px verdana'><div style='font-family:arial'>test</div></div>"));
Assert.IsNotNull(doc.Document.Body);
Assert.AreEqual(1, doc.Document.Body.ChildElements.Count);
OpenXmlElement para = doc.Document.Body.ChildElements[0];
Assert.IsTrue(para is Paragraph);
Assert.AreEqual(1, para.ChildElements.Count);
Run run = para.ChildElements[0] as Run;
Assert.IsNotNull(run);
Assert.AreEqual(2, run.ChildElements.Count);
Assert.IsNotNull(run.RunProperties);
Assert.AreEqual(2, run.RunProperties.ChildElements.Count);
RunFonts fonts = run.RunProperties.ChildElements[0] as RunFonts;
Assert.IsNotNull(fonts);
Assert.AreEqual("arial", fonts.Ascii.Value);
FontSize fontSize = run.RunProperties.ChildElements[1] as FontSize;
Assert.IsNotNull(fontSize);
Assert.AreEqual("20", fontSize.Val.Value);
OpenXmlValidator validator = new OpenXmlValidator();
var errors = validator.Validate(doc.WordprocessingDocument);
Assert.AreEqual(0, errors.Count());
}
}
开发者ID:kannan-ar,项目名称:MariGold.OpenXHTML,代码行数:34,代码来源:InheritedStyles.cs
示例3: SinglePRedColor
public void SinglePRedColor()
{
using (MemoryStream mem = new MemoryStream())
{
WordDocument doc = new WordDocument(mem);
doc.Process(new HtmlParser("<p style='color:red'>test</p>"));
Assert.IsNotNull(doc.Document.Body);
Assert.AreEqual(1, doc.Document.Body.ChildElements.Count);
Paragraph paragraph = doc.Document.Body.ChildElements[0] as Paragraph;
Run run = paragraph.ChildElements[0] as Run;
Assert.IsNotNull(run);
Assert.AreEqual(2, run.ChildElements.Count);
Assert.IsNotNull(run.RunProperties);
Word.Color color = run.RunProperties.ChildElements[0] as Word.Color;
Assert.AreEqual("FF0000", color.Val.Value);
Word.Text text = run.ChildElements[1] as Word.Text;
Assert.IsNotNull(text);
Assert.AreEqual(0, text.ChildElements.Count);
Assert.AreEqual("test", text.InnerText);
OpenXmlValidator validator = new OpenXmlValidator();
var errors = validator.Validate(doc.WordprocessingDocument);
Assert.AreEqual(0, errors.Count());
}
}
开发者ID:kannan-ar,项目名称:MariGold.OpenXHTML,代码行数:30,代码来源:TestP.cs
示例4: DivRGBColorRed
public void DivRGBColorRed()
{
using (MemoryStream mem = new MemoryStream())
{
WordDocument doc = new WordDocument(mem);
doc.Process(new HtmlParser("<div style='color:rgb(255,0,0)'>test</div>"));
Assert.IsNotNull(doc.Document.Body);
Assert.AreEqual(1, doc.Document.Body.ChildElements.Count);
OpenXmlElement para = doc.Document.Body.ChildElements[0];
Assert.IsTrue(para is Paragraph);
Assert.AreEqual(1, para.ChildElements.Count);
Run run = para.ChildElements[0] as Run;
Assert.IsNotNull(run);
Assert.AreEqual(2, run.ChildElements.Count);
Assert.IsNotNull(run.RunProperties);
Assert.IsNotNull(run.RunProperties.Color);
Assert.AreEqual("FF0000", run.RunProperties.Color.Val.Value);
OpenXmlValidator validator = new OpenXmlValidator();
var errors = validator.Validate(doc.WordprocessingDocument);
Assert.AreEqual(0, errors.Count());
}
}
开发者ID:kannan-ar,项目名称:MariGold.OpenXHTML,代码行数:29,代码来源:BasicStyles.cs
示例5: SingleDivOneEmFontSize
public void SingleDivOneEmFontSize()
{
using (MemoryStream mem = new MemoryStream())
{
WordDocument doc = new WordDocument(mem);
doc.Process(new HtmlParser("<div style='font-size:1em'>test</div>"));
Assert.IsNotNull(doc.Document.Body);
Assert.AreEqual(1, doc.Document.Body.ChildElements.Count);
Paragraph paragraph = doc.Document.Body.ChildElements[0] as Paragraph;
Run run = paragraph.ChildElements[0] as Run;
Assert.IsNotNull(run);
Assert.AreEqual(2, run.ChildElements.Count);
Assert.IsNotNull(run.RunProperties);
FontSize fontSize = run.RunProperties.ChildElements[0] as FontSize;
Assert.AreEqual("24", fontSize.Val.Value);
Word.Text text = run.ChildElements[1] as Word.Text;
Assert.IsNotNull(text);
Assert.AreEqual(0, text.ChildElements.Count);
Assert.AreEqual("test", text.InnerText);
OpenXmlValidator validator = new OpenXmlValidator();
var errors = validator.Validate(doc.WordprocessingDocument);
Assert.AreEqual(0, errors.Count());
}
}
开发者ID:kannan-ar,项目名称:MariGold.OpenXHTML,代码行数:30,代码来源:TestDiv.cs
示例6: SimpleText
public void SimpleText()
{
using (MemoryStream mem = new MemoryStream())
{
WordDocument doc = new WordDocument(mem);
doc.Process(new HtmlParser("test"));
Assert.IsNotNull(doc.Document.Body);
Assert.AreEqual(1, doc.Document.Body.ChildElements.Count);
OpenXmlElement para = doc.Document.Body.ChildElements[0];
Assert.IsTrue(para is Paragraph);
Assert.AreEqual(1, para.ChildElements.Count);
OpenXmlElement run = para.ChildElements[0];
Assert.IsTrue(run is Run);
Assert.AreEqual(1, run.ChildElements.Count);
OpenXmlElement text = run.ChildElements[0] as DocumentFormat.OpenXml.Wordprocessing.Text;
Assert.IsNotNull(text);
Assert.AreEqual(0, text.ChildElements.Count);
Assert.AreEqual("test", text.InnerText);
OpenXmlValidator validator = new OpenXmlValidator();
var errors = validator.Validate(doc.WordprocessingDocument);
Assert.AreEqual(0, errors.Count());
}
}
开发者ID:kannan-ar,项目名称:MariGold.OpenXHTML,代码行数:30,代码来源:BasicDocument.cs
示例7: DivFontBold
public void DivFontBold()
{
using (MemoryStream mem = new MemoryStream())
{
WordDocument doc = new WordDocument(mem);
doc.Process(new HtmlParser("<div style='font-weight:bold'>test</div>"));
Assert.IsNotNull(doc.Document.Body);
Assert.AreEqual(1, doc.Document.Body.ChildElements.Count);
OpenXmlElement para = doc.Document.Body.ChildElements[0];
Assert.IsTrue(para is Paragraph);
Assert.AreEqual(1, para.ChildElements.Count);
Run run = para.ChildElements[0] as Run;
Assert.IsNotNull(run);
Assert.AreEqual(2, run.ChildElements.Count);
Assert.IsNotNull(run.RunProperties);
Assert.AreEqual(1, run.RunProperties.ChildElements.Count);
Bold bold = run.RunProperties.ChildElements[0] as Bold;
Assert.IsNotNull(bold);
Word.Text text = run.ChildElements[1] as Word.Text;
Assert.IsNotNull(text);
Assert.AreEqual(0, text.ChildElements.Count);
Assert.AreEqual("test", text.InnerText);
OpenXmlValidator validator = new OpenXmlValidator();
var errors = validator.Validate(doc.WordprocessingDocument);
Assert.AreEqual(0, errors.Count());
}
}
开发者ID:kannan-ar,项目名称:MariGold.OpenXHTML,代码行数:35,代码来源:TestFonts.cs
示例8: ValidateOpenXmlDocument
private static bool ValidateOpenXmlDocument(OpenXmlPackage package )
{
string errorDesc = "";
try
{
OpenXmlValidator validator = new OpenXmlValidator();
int count = 0;
foreach (ValidationErrorInfo error in validator.Validate(package))
{
count++;
errorDesc += String.Format("Error: {0}", count) + Environment.NewLine;
errorDesc += String.Format("Description: {0}", error.Description) + Environment.NewLine;
errorDesc += String.Format("Path: {0}", error.Path.XPath) + Environment.NewLine;
errorDesc += String.Format("Part: {0}", error.Part.Uri) + Environment.NewLine;
errorDesc += "-------------------------------------------" + Environment.NewLine;
}
}
catch (Exception ex)
{
errorDesc += ex.Message;
}
if (!string.IsNullOrEmpty(errorDesc))
{
throw new Exception(errorDesc);
}
return true;
}
开发者ID:myersBR,项目名称:My-FyiReporting,代码行数:27,代码来源:OpenXmlUtils.cs
示例9: OneSentanceInBody
public void OneSentanceInBody()
{
using (MemoryStream mem = new MemoryStream())
{
WordDocument doc = new WordDocument(mem);
doc.Process(new HtmlParser(TestUtility.GetHtmlFromFile("Html\\onesentanceinbody.htm")));
Assert.IsNotNull(doc.Document.Body);
Assert.AreEqual(1, doc.Document.Body.ChildElements.Count);
Paragraph para = doc.Document.Body.ChildElements[0] as Paragraph;
Assert.IsNotNull(para);
Assert.AreEqual(1, para.ChildElements.Count);
Run run = para.ChildElements[0] as Run;
Assert.IsNotNull(run);
Assert.AreEqual(1, run.ChildElements.Count);
Word.Text text = run.ChildElements[0] as Word.Text;
Assert.IsNotNull(text);
Assert.AreEqual(0, text.ChildElements.Count);
Assert.AreEqual("This is a test", text.InnerText.Trim());
OpenXmlValidator validator = new OpenXmlValidator();
var errors = validator.Validate(doc.WordprocessingDocument);
errors.PrintValidationErrors();
Assert.AreEqual(0, errors.Count());
}
}
开发者ID:kannan-ar,项目名称:MariGold.OpenXHTML,代码行数:30,代码来源:SimpleHtmlFromFile.cs
示例10: ValidateFile
/// <summary>
/// Validates the file and prints result to console
/// </summary>
/// <param name="file">Path to the file</param>
private static bool ValidateFile(string file)
{
ConsoleColor color = Console.ForegroundColor;
bool isValid = false;
try
{
Console.WriteLine("File name: {0}", file);
OpenXmlValidator validator = new OpenXmlValidator();
using (var doc = GetOpenXmlPackage(file))
{
var errors = validator.Validate(doc);
if (errors.Any())
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Found {0} validation errors: ", errors.Count());
int count = 0;
foreach (ValidationErrorInfo error in errors)
{
count++;
Console.WriteLine("Error " + count);
Console.WriteLine("Part: " + error.Part.Uri);
Console.WriteLine("Description: " + error.Description);
Console.WriteLine("Path: " + error.Path.XPath);
}
}
else
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Document valid");
isValid = true;
}
Console.WriteLine();
}
}
catch (Exception e)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Exception occured while validating file: {0} - {1}",e.GetType().ToString() ,e.Message);
}
finally
{
Console.ForegroundColor = color;
}
return isValid;
}
开发者ID:KISHORESSK,项目名称:abap2xlsx,代码行数:55,代码来源:Program.cs
示例11: SimpleUl
public void SimpleUl()
{
using (MemoryStream mem = new MemoryStream())
{
WordDocument doc = new WordDocument(mem);
doc.Process(new HtmlParser("<ul><li>test</li></ul>"));
Assert.IsNotNull(doc.Document.Body);
Assert.AreEqual(1, doc.Document.Body.ChildElements.Count);
Paragraph para = doc.Document.Body.ChildElements[0] as Paragraph;
Assert.IsNotNull(para);
Assert.AreEqual(2, para.ChildElements.Count);
ParagraphProperties properties = para.ChildElements[0] as ParagraphProperties;
Assert.IsNotNull(properties);
Assert.AreEqual(2, properties.ChildElements.Count);
ParagraphStyleId paragraphStyleId = properties.ChildElements[0] as ParagraphStyleId;
Assert.IsNotNull(paragraphStyleId);
Assert.AreEqual("ListParagraph", paragraphStyleId.Val.Value);
NumberingProperties numberingProperties = properties.ChildElements[1] as NumberingProperties;
Assert.IsNotNull(numberingProperties);
Assert.AreEqual(2, numberingProperties.ChildElements.Count);
NumberingLevelReference numberingLevelReference = numberingProperties.ChildElements[0] as NumberingLevelReference;
Assert.IsNotNull(numberingLevelReference);
Assert.AreEqual(0, numberingLevelReference.Val.Value);
NumberingId numberingId = numberingProperties.ChildElements[1] as NumberingId;
Assert.IsNotNull(numberingId);
Assert.AreEqual((Int32)NumberFormatValues.Bullet, numberingId.Val.Value);
Run run = para.ChildElements[1] as Run;
Assert.IsNotNull(run);
Assert.AreEqual(1, run.ChildElements.Count);
Word.Text text = run.ChildElements[0] as Word.Text;
Assert.IsNotNull(text);
Assert.AreEqual("test", text.InnerText);
OpenXmlValidator validator = new OpenXmlValidator();
var errors = validator.Validate(doc.WordprocessingDocument);
Assert.AreEqual(0, errors.Count());
}
}
开发者ID:kannan-ar,项目名称:MariGold.OpenXHTML,代码行数:48,代码来源:ContainerElements.cs
示例12: X007_SpreadsheetDocument_Open
public void X007_SpreadsheetDocument_Open()
{
var fiSource = new FileInfo(Path.Combine(s_TestFileLocation, "Spreadsheet.xlsx"));
var fiCopy = new FileInfo(Path.Combine(TestUtil.TempDir.FullName, Guid.NewGuid().ToString() + ".xlsx"));
File.Copy(fiSource.FullName, fiCopy.FullName);
OpenSettings openSettings = new OpenSettings();
openSettings.MarkupCompatibilityProcessSettings = new MarkupCompatibilityProcessSettings(MarkupCompatibilityProcessMode.ProcessAllParts, FileFormatVersions.Office2013);
using (SpreadsheetDocument doc = SpreadsheetDocument.Open(fiCopy.FullName, true, openSettings))
{
OpenXmlValidator v = new OpenXmlValidator(FileFormatVersions.Office2013);
var errs = v.Validate(doc);
Assert.Equal(1, errs.Count());
}
if (TestUtil.DeleteTempFiles)
fiCopy.Delete();
}
开发者ID:eriawan,项目名称:Open-XML-SDK,代码行数:16,代码来源:TestXlsx01.cs
示例13: EmptyBody
public void EmptyBody()
{
using (MemoryStream mem = new MemoryStream())
{
WordDocument doc = new WordDocument(mem);
doc.Process(new HtmlParser("<body></body>"));
Assert.IsNotNull(doc.Document.Body);
Assert.AreEqual(0, doc.Document.Body.ChildElements.Count);
OpenXmlValidator validator = new OpenXmlValidator();
var errors = validator.Validate(doc.WordprocessingDocument);
Assert.AreEqual(0, errors.Count());
}
}
开发者ID:kannan-ar,项目名称:MariGold.OpenXHTML,代码行数:16,代码来源:BasicDocument.cs
示例14: StyleElement
public void StyleElement()
{
using (MemoryStream mem = new MemoryStream())
{
string html = "<style type=\"text/css\">.cls{font-size:10px;}</style>";
WordDocument doc = new WordDocument(mem);
doc.Process(new HtmlParser(html));
Assert.IsNotNull(doc.Document.Body);
Assert.AreEqual(0, doc.Document.Body.ChildElements.Count);
OpenXmlValidator validator = new OpenXmlValidator();
var errors = validator.Validate(doc.WordprocessingDocument);
Assert.AreEqual(0, errors.Count());
}
}
开发者ID:kannan-ar,项目名称:MariGold.OpenXHTML,代码行数:17,代码来源:InvalidElements.cs
示例15: ScriptElement
public void ScriptElement()
{
using (MemoryStream mem = new MemoryStream())
{
string html = "<script type=\"text/javascript\">console.log('ok');</script>";
WordDocument doc = new WordDocument(mem);
doc.Process(new HtmlParser(html));
Assert.IsNotNull(doc.Document.Body);
Assert.AreEqual(0, doc.Document.Body.ChildElements.Count);
OpenXmlValidator validator = new OpenXmlValidator();
var errors = validator.Validate(doc.WordprocessingDocument);
Assert.AreEqual(0, errors.Count());
}
}
开发者ID:kannan-ar,项目名称:MariGold.OpenXHTML,代码行数:17,代码来源:InvalidElements.cs
示例16: EmptyHtmlBody
public void EmptyHtmlBody()
{
using (MemoryStream mem = new MemoryStream())
{
WordDocument doc = new WordDocument(mem);
doc.Process(new HtmlParser(TestUtility.GetHtmlFromFile("Html\\emptybody.htm")));
Assert.IsNotNull(doc.Document.Body);
Assert.AreEqual(0, doc.Document.Body.ChildElements.Count);
OpenXmlValidator validator = new OpenXmlValidator();
var errors = validator.Validate(doc.WordprocessingDocument);
errors.PrintValidationErrors();
Assert.AreEqual(0, errors.Count());
}
}
开发者ID:kannan-ar,项目名称:MariGold.OpenXHTML,代码行数:17,代码来源:SimpleHtmlFromFile.cs
示例17: Validate
public static DocumentValidation Validate(byte[] docByteArray)
{
using (MemoryStream mem = new MemoryStream())
{
Console.WriteLine((int)docByteArray.Length);
mem.Write(docByteArray, 0, (int)docByteArray.Length);
using (WordprocessingDocument wordDoc =
WordprocessingDocument.Open(mem, false))
{
var validator = new OpenXmlValidator();
var errors = validator.Validate(wordDoc).Select(err => new DocumentError(err));
bool valid = !errors.Any();
return new DocumentValidation(valid, errors);
}
}
}
开发者ID:Yoobic,项目名称:docx-builder,代码行数:19,代码来源:Program.cs
示例18: P005_PptxCreation_Package_Settings
public void P005_PptxCreation_Package_Settings()
{
var fiSource = new FileInfo(Path.Combine(s_TestFileLocation, "Presentation.pptx"));
var fiCopy = new FileInfo(Path.Combine(TestUtil.TempDir.FullName, Guid.NewGuid().ToString() + ".pptx"));
File.Copy(fiSource.FullName, fiCopy.FullName);
using (Package package = Package.Open(fiCopy.FullName, FileMode.Open, FileAccess.ReadWrite))
{
OpenSettings openSettings = new OpenSettings();
openSettings.MarkupCompatibilityProcessSettings = new MarkupCompatibilityProcessSettings(MarkupCompatibilityProcessMode.ProcessAllParts, FileFormatVersions.Office2013);
using (PresentationDocument doc = PresentationDocument.Open(package, openSettings))
{
OpenXmlValidator v = new OpenXmlValidator(FileFormatVersions.Office2013);
var errs = v.Validate(doc);
Assert.Equal(94, errs.Count());
}
}
if (TestUtil.DeleteTempFiles)
fiCopy.Delete();
}
开发者ID:eriawan,项目名称:Open-XML-SDK,代码行数:19,代码来源:TestPptx01.cs
示例19: AssertThatOpenXmlDocumentIsValid
static void AssertThatOpenXmlDocumentIsValid(WordprocessingDocument wpDoc)
{
var validator = new OpenXmlValidator(FileFormatVersions.Office2010);
var errors = validator.Validate(wpDoc);
if (!errors.GetEnumerator().MoveNext())
return;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("The document doesn't look 100% compatible with Office 2010.\n");
Console.ForegroundColor = ConsoleColor.Gray;
foreach (ValidationErrorInfo error in errors)
{
Console.Write("{0}\n\t{1}", error.Path.XPath, error.Description);
Console.WriteLine();
}
Console.ReadLine();
}
开发者ID:rexyanglucky,项目名称:uba,代码行数:20,代码来源:Program.cs
示例20: Validator2007BugRegressionTest
public void Validator2007BugRegressionTest()
{
OpenXmlValidator validator = new OpenXmlValidator(FileFormatVersions.Office2007);
Bug423998(validator);
Bug423974(validator);
Bug424104(validator);
Bug412116(validator);
Bug345436(validator);
Bug403545(validator);
Bug429396(validator);
Bug514988(validator);
Bug448264(validator);
Bug319778(validator);
Bug643538(validator);
Bug669663(validator);
Bug583585(validator);
Bug704004(validator);
Bug743591(validator);
}
开发者ID:eriawan,项目名称:Open-XML-SDK,代码行数:20,代码来源:BugRegressionTest.cs
注:本文中的DocumentFormat.OpenXml.Validation.OpenXmlValidator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论