| |

VerySource

 Forgot password?
 Register
Search
View: 762|Reply: 2

XML file operation questions

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-27 18:40:01
| Show all posts |Read mode
Some parts in the XML file are as follows:
<WorksheetOptions xmlns = "urn: schemas-microsoft-com: office: excel">
   <Unsynced />
    ...
 </ WorksheetOptions>
I now want to remove <Unsynced />
Then add the setting of <PageSetup>, the desired effect is as follows:
<WorksheetOptions xmlns = "urn: schemas-microsoft-com: office: excel">
  <PageSetup>
    <Header x: Margin = "0.51181102362204722" />
    <Footer x: Margin = "0.51181102362204722" />
    <PageMargins x: Bottom = "0.98425196850393704" x: Left = "0.78740157480314965"
     x: Right = "0.47244094488188981" x: Top = "0.98425196850393704" />
   ...
</ WorksheetOptions>
Now ask everyone, thank you for your help!
Reply

Use magic Report

0

Threads

46

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-2-21 20:30:01
| Show all posts
System.Xml.XmlDocument
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-28 21:15:02
| Show all posts
XmlDocument xmlDoc = new XmlDocument ();
xmlDoc.Load ("your file name.xml");
XmlNodeList xnl = xmlDoc.SelectSingleNode ("WorksheetOptions"). ChildNodes;
foreach (XmlNode xn in xnl) // Remove first
      {
        XmlElement xe = (XmlElement) xn;


        if (xe.Name == "Unsynced")
        {
          xe.RemoveAll ();
        }
              }
      xmlDoc.Save ("your file name.xml");

// Add more nodes
 XmlNode root = xmlDoc.SelectSingleNode ("WorksheetOptions"); // Find <WorksheetOptions>
 XmlElement xe1 = xmlDoc.CreateElement ("PageSetup"); // Create a <PageSetup> node

 XmlElement xesub1 = xmlDoc.CreateElement ("Header");
 xesub1.InnerText = "x: Margin = 0.51181102362204722"; // Set the text node
 xe1.AppendChild (xesub1); // Add to <PageSetup> node

 XmlElement xesub2 = xmlDoc.CreateElement ("Footer");
 xesub2.InnerText = "x: Margin = 0.51181102362204722"; // Set the text node
 xe1.AppendChild (xesub2); // Add to <PageSetup> node

 XmlElement xesub3 = xmlDoc.CreateElement ("PageMargins");
 xesub3.InnerText = "x: Bottom =" 0.98425196850393704 "x: Left =" 0.78740157480314965 "
     x: Right = "0.47244094488188981" x: Top = "0.98425196850393704"; // Set text node
 xe1.AppendChild (xesub3); // Add to <PageSetup> node
  .....
      root.AppendChild (xe1);
      xmlDoc.Save ("your file name.xml");
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list