Hello,
I am trying to export data from Excel as XML using the Workbook.ExportXml Method . With some files, this method throws a NullReferenceException, even though the file does contain a valid XML Map that can be used from Excel to correctly export data in XML format.
This is the code used:
class Program
{
private const string ResourcesFolder = "Resources";
private const string FileName = "Example.xlsx";
private const string xsdFilename = "xmlMaps.xsd";
private const string xmlFilename = "extractedXML.xml";
static void Main(string[] args)
{
string sourceDir = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), ResourcesFolder);
string path = Path.Combine(sourceDir, FileName);
string xmlPath = Path.Combine(sourceDir, xmlFilename);
GetXmlMapFile(path, xmlPath);
Console.WriteLine("XML extracted to: " + xmlPath);
Console.ReadLine();
}
static void GetXmlMapFile(string filePath, string destination)
{
// Load sample Excel file having XML Map
Workbook wb = new Workbook(filePath);
if (wb.Worksheets.XmlMaps.Count >= 1)
{
XmlMap map = wb.Worksheets.XmlMaps[0];
wb.ExportXml(map.Name, destination);
}
}
}
You can see that the variable “map” is not null:
image.png (41.0 KB)
The Excel file: Example.zip (7.9 KB)
This issues looks like the same as this one: ExportXML using XML Map is throwing error
Best Regards