我正在尝试将XML文件映射到Excel文件,然后在点网C#中导入其他文件
在第xlWorkbook.XmlImport(item, out xmlMap, false);
行中出现异常
请帮助
public static void test2()
{
string mappingfile = @"C:\mapping\template.xml";
string folder = @"C:\mapping\";
string filter = "*.xml";
string[] files = Directory.GetFiles(folder, filter);
//Mapping xml file and than import xmls files c#
string filepath = @"C:\mapping\2.xlsx";
Excel.Application xlApp = new Excel.Application();
xlApp.DisplayAlerts = false;
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(filepath);
Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
Excel.Range xlRange = xlWorksheet.UsedRange;
var xmlMap = xlWorkbook.XmlMaps.Add(mappingfile, "InventoryResponse");
xlWorkbook.XmlImport(mappingfile, out xmlMap, true, "$A1");
foreach (string item in files)
{
if (item == mappingfile)
{
continue;
}
xlWorkbook.XmlImport(item, out xmlMap, false);
}
xlWorkbook.RefreshAll();
xlWorkbook.SaveAs(@"C:\mapping\test.xlsx");
xlWorkbook.Close();
xlApp.Quit();
}