public void TestExportToXMLInverseOrder() { XSSFWorkbook wb = XSSFTestDataSamples .OpenSampleWorkbook("CustomXmlMappings-inverse-order.xlsx"); MapInfo mapInfo = null; foreach (POIXMLDocumentPart p in wb.GetRelations()) { if (!(p is MapInfo)) { continue; } mapInfo = (MapInfo)p; XSSFMap map = mapInfo.GetXSSFMapById(1); XSSFExportToXml exporter = new XSSFExportToXml(map); MemoryStream os = new MemoryStream(); exporter.ExportToXML(os, true); os.Position = 0; XmlDocument xml = new XmlDocument(); xml.Load(os); Assert.IsNotNull(xml); Assert.IsTrue(xml.OuterXml != ""); String docente = xml.SelectSingleNode("//DOCENTE").InnerText.Trim(); String nome = xml.SelectSingleNode("//NOME").InnerText.Trim(); String tutor = xml.SelectSingleNode("//TUTOR").InnerText.Trim(); String cdl = xml.SelectSingleNode("//CDL").InnerText.Trim(); String durata = xml.SelectSingleNode("//DURATA").InnerText.Trim(); String argomento = xml.SelectSingleNode("//ARGOMENTO").InnerText.Trim(); String progetto = xml.SelectSingleNode("//PROGETTO").InnerText.Trim(); String crediti = xml.SelectSingleNode("//CREDITI").InnerText.Trim(); Assert.AreEqual("aa", nome); Assert.AreEqual("aaaa", docente); Assert.AreEqual("gvvv", tutor); Assert.AreEqual("g", cdl); Assert.AreEqual("gs", durata); Assert.AreEqual("ds", argomento); Assert.AreEqual("ro", progetto); Assert.AreEqual("ro", crediti); } }
public void TestMultiTable() { XSSFWorkbook wb = XSSFTestDataSamples .OpenSampleWorkbook("CustomXMLMappings-complex-type.xlsx"); foreach (POIXMLDocumentPart p in wb.GetRelations()) { if (p is MapInfo) { MapInfo mapInfo = (MapInfo)p; XSSFMap map = mapInfo.GetXSSFMapById(2); Assert.IsNotNull(map); XSSFExportToXml exporter = new XSSFExportToXml(map); MemoryStream os = new MemoryStream(); exporter.ExportToXML(os, true); String xml = Encoding.UTF8.GetString(os.ToArray()); Assert.IsNotNull(xml); String[] regexConditions = { "<MapInfo", "</MapInfo>", "<Schema ID=\"1\" SchemaRef=\"\" Namespace=\"\" />", "<Schema ID=\"4\" SchemaRef=\"\" Namespace=\"\" />", "DataBinding", "Map ID=\"1\"", "Map ID=\"5\"", }; foreach (String condition in regexConditions) { Regex pattern = new Regex(condition, RegexOptions.Compiled); Assert.IsTrue(pattern.IsMatch(xml), condition); } } } }