|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
案例来自
http://club.excelhome.net/forum. ... p;page=1#pid6817292
要求把附件的汇总工作表的数据生成XML文件。
主要的序列化子过程:- private void button1_Click(object sender, EventArgs e)
- {
- Scene[] sc = null;
- subExcel myDemo = new subExcel("汇总",@"d:\temp\汇总.xlsm");
- sc = myDemo.GetArr();
- SerializaDemo(sc);
- textBox1.Text = @"文件路径 d:\temp\汇总.xml";
- }
- //XML序列化主过程
- void SerializaDemo(Scene[] sc)
- {
- StreamWriter sr = new StreamWriter(@"d:\temp\汇总.xml");
- XmlSerializer mySerializer = new XmlSerializer(typeof(Scene[]), new XmlRootAttribute("NpcSceneUpdate"));
- mySerializer.Serialize(sr, sc);
- sr.Close();
- }
复制代码 需序列化的主类模块:- public class Scene
- {
- private Npc[] m_npcs = null;
- private string mapId;
- [XmlAttribute(AttributeName = "mapId")]
- public string MapId
- {
- get { return mapId; }
- set { mapId = value; }
- }
- [XmlElement(ElementName = "Npc")]
- public Npc[] Npcs
- {
- get { return m_npcs; }
- set { m_npcs = value; }
- }
复制代码 主要子类模块 |
|