Click here to Skip to main content
15,887,856 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Sir,
I have a XML File like below:
<?xml version="1.0"?>
<Box>
	<Point1 X="318" Y="108" />
	<Point2 X="554" Y="105" />
	<Point3 X="783" Y="374" />
	<Point4 X="34" Y="378" />
</Box>


I want Point1, Point2, Point3 and Point4 data from Excel. I have a new in this code. Please help me.
Thanks in advance...

What I have tried:

I am new and cant understand howto do that.
Posted
Updated 31-Dec-19 3:28am
Comments
EricERankin 26-Mar-20 13:32pm    
Let's say you have those values in an Excel file under columns A and B, here is how you would update your XML file with that data:
-----------
var workbook = ExcelFile.Load("input.xlsx");
var worksheet = workbook.Worksheets[0];

var xml = new XmlDocument();
xml.Load("box.xml");
var nodes = xml.DocumentElement.ChildNodes.Cast<XmlNode>().ToArray();

for (int index = 0; index < 4; index++)
{
var row = worksheet.Rows[index];
var node = nodes[index];

node.Attributes["X"].Value = row.Cells["A"].Value.ToString();
node.Attributes["Y"].Value = row.Cells["B"].Value.ToString();
}

xml.Save("box-updated.xml");
-----------
The code is processing Excel using this C# library.
Also, you can as a reference this full C# example for reading Excel files.
I hope this helps.

 
Share this answer
 
Comments
manish kr. chaturvedi 31-Dec-19 6:42am    
can you give me full code. I have only xml file and dont idea how to update it.
ZurdoDev 31-Dec-19 10:21am    
No, no one is going to do this all for you.
You first need to decide how you are going to extract the data from your Excel files. You can try OLEDB: Working with MS Excel(xls / xlsx) Using MDAC and Oledb[^], or work with Microsoft.Office.Interop.Excel Namespace | Microsoft Docs[^].
 
Share this answer
 
Comments
manish kr. chaturvedi 31-Dec-19 6:41am    
I want use by EXCEL VBA
Richard MacCutchan 31-Dec-19 9:26am    
Then you will need to learn how to write Excel macros.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900