I tried using
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlFilePath);
// Create a new Excel application
Excel.Application excelApp = new Excel.Application
{
Visible = false, // Set to true if you want to see the Excel application
DisplayAlerts = false // Disable any Excel alerts or messages
};
// Create a new Workbook and Worksheet
Excel.Workbook workbook = excelApp.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);
Excel.Worksheet worksheet = (Excel.Worksheet)workbook.Worksheets[1];
// Get XML rows (assuming the XML structure has <Row> elements)
XmlNodeList rows = xmlDoc.SelectNodes("//Row");
int rowIndex = 1;
// Loop through XML rows and insert them into the Excel sheet
foreach (XmlNode row in rows)
{
int columnIndex = 1;
foreach (XmlNode cell in row.ChildNodes)
{
// Set the cell valuecvbnmmmkkkjhgfdsaqwertyyo
worksheet.Cells[rowIndex, columnIndex] = cell.InnerText;
columnIndex++;
}
rowIndex++;
}
if (File.Exists(excelFilePath))
{
File.SetAttributes(excelFilePath, FileAttributes.Normal); // Ensure it's not read-only
}
workbook.Save();
//workbook.SaveAs(
// excelFilePath, // Path to save the file
// Excel.XlFileFormat.xlOpenXMLWorkbook, Type.Missing, Type.Missing, Type.Missing // .xlsx format
// );
// Save the Excel file with the specified path and format
excelApp.Quit();
// Release the COM objects to prevent memory leaks
Marshal.ReleaseComObject(worksheet);
Marshal.ReleaseComObject(workbook);
Marshal.ReleaseComObject(excelApp);
MessageBox.Show("XML successfully converted to Excel!");
but not converting the row count is zero also save as will not work i use save()