62,244
社区成员




<Workbook>
<DocumentProperties>
<Created>2011-11-03T12:11:54Z</Created>
<Version>03.1015</Version>
</DocumentProperties>
<Worksheet Name="第1页">
<Table>
<Row Index="12">
<Cell Index="2">
<Data Type="String">26岁至35岁</Data>
</Cell>
<Cell Index="3">
<Data Type="Number">9</Data>
</Cell>
<Cell Index="6">
<Data Type="String">研究生</Data>
</Cell>
<Cell Index="7">
<Data Type="Number">22</Data>
</Cell>
</Row>
<Row Index="13">
<Cell Index="2">
<Data Type="String">36岁至45岁</Data>
</Cell>
<Cell Index="3">
<Data Type="Number">10</Data>
</Cell>
<Cell Index="6">
<Data Type="String">本科</Data>
</Cell>
<Cell Index="7">
<Data Type="Number">23</Data>
</Cell>
</Row>
<Row Index="14">
<Cell Index="2">
<Data Type="String">46岁至55岁</Data>
</Cell>
<Cell Index="3">
<Data Type="Number">11</Data>
</Cell>
<Cell Index="6">
<Data Type="String">大专</Data>
</Cell>
<Cell Index="7">
<Data Type="Number">24</Data>
</Cell>
</Row>
</Table>
</Worksheet>
</Workbook>
public class Workbook
{
private DocumentProperties doc;
[XmlElement(ElementName = "DocumentProperties")]
public DocumentProperties Doc
{
get { return doc; }
set { doc = value; }
}
private Worksheet[] worksheet;
[XmlElement(ElementName = "Worksheet")]
public Worksheet[] Worksheet
{
get { return worksheet; }
set { worksheet = value; }
}
}
public class DocumentProperties
{
private string created;
public string Created
{
get { return created; }
set { created = value; }
}
private string version;
public string Version
{
get { return version; }
set { version = value; }
}
}
public class Worksheet
{
private string name;
[XmlAttribute(AttributeName = "Name")]
public string Name
{
get { return name; }
set { name = value; }
}
private Table[] table;
[XmlElement(ElementName="Table")]
public Table[] Table
{
get { return table; }
set { table = value; }
}
}
public class Table
{
private Row[] row;
[XmlElement(ElementName = "Row")]
public Row[] Row
{
get { return row; }
set { row = value; }
}
}
public class Row
{
private int index;
[XmlAttribute(AttributeName = "Index")]
public int Index
{
get { return index; }
set { index = value; }
}
private Cell[] cell;
[XmlElement(ElementName = "Cell")]
public Cell[] Cell
{
get { return cell; }
set { cell = value; }
}
}
public class Cell
{
private int index;
[XmlAttribute(AttributeName = "Index")]
public int Index
{
get { return index; }
set { index = value; }
}
private Data data;
public Data Data
{
get { return data; }
set { data = value; }
}
}
public class Data
{
private string type;
[XmlAttribute(AttributeName = "Type")]
public string Type
{
get { return type; }
set { type = value; }
}
private string text;
[XmlText]
public string Text
{
get { return text; }
set { text = value; }
}
}
static void Main(string[] args)
{
Workbook workbook = new Workbook();
DocumentProperties doc = new DocumentProperties();
doc.Created = "2011-11-03T12:11:54Z";
doc.Version = "03.1015";
workbook.Doc = doc;
Cell[] cell1 = new Cell[2] { new Cell() { Index = 2, Data = new Data() { Type = "String", Text = "26岁至35岁" } }, new Cell() { Index = 3, Data = new Data() { Type = "Number", Text = "9" } } };
Cell[] cell2 = new Cell[2] { new Cell() { Index = 2, Data = new Data() { Type = "String", Text = "36岁至45岁" } }, new Cell() { Index = 3, Data = new Data() { Type = "Number", Text = "10" } } };
Cell[] cell3 = new Cell[2] { new Cell() { Index = 2, Data = new Data() { Type = "String", Text = "46岁至55岁" } }, new Cell() { Index = 3, Data = new Data() { Type = "Number", Text = "11" } } };
Row[] row = new Row[3] { new Row() { Index = 12, Cell = cell1 }, new Row() { Index = 13, Cell = cell2 }, new Row() { Index = 14, Cell = cell3 } };
Table[] table = new Table[1] { new Table() { Row = row } };
Worksheet[] worksheet = new Worksheet[1] { new Worksheet() { Name = "第一页", Table = table } };
workbook.Worksheet = worksheet;
XmlSerializer xml = new XmlSerializer(workbook.GetType());
FileStream fs = new FileStream(@"E:\a.xml", FileMode.Create, FileAccess.Write);
xml.Serialize(fs, workbook);
fs.Close();
fs.Dispose();
Console.ReadLine();
}
<?xml version="1.0"?>
<Workbook xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<DocumentProperties>
<Created>2011-11-03T12:11:54Z</Created>
<Version>03.1015</Version>
</DocumentProperties>
<Worksheet Name="第一页">
<Table>
<Row Index="12">
<Cell Index="2">
<Data Type="String">26岁至35岁</Data>
</Cell>
<Cell Index="3">
<Data Type="Number">9</Data>
</Cell>
</Row>
<Row Index="13">
<Cell Index="2">
<Data Type="String">36岁至45岁</Data>
</Cell>
<Cell Index="3">
<Data Type="Number">10</Data>
</Cell>
</Row>
<Row Index="14">
<Cell Index="2">
<Data Type="String">46岁至55岁</Data>
</Cell>
<Cell Index="3">
<Data Type="Number">11</Data>
</Cell>
</Row>
</Table>
</Worksheet>
</Workbook>
[Serializable]
public class Workbook
{
public DocumentProperties DocumentProperties { get; set; }
public Worksheet Worksheet { get; set; }
}
[Serializable]
public class Worksheet
{
[XmlAttribute("Name")]
public string Name { get; set; }
public List<Row> Table { get; set; }
}
[Serializable]
public class Table
{
public List<Row> Row { get; set; }
}
[Serializable]
public class Row
{
[XmlAttribute("Index")]
public int Index { get; set; }
[XmlElement]
public List<Cell> Cell { get; set; }
}
[Serializable]
public class Cell
{
[XmlAttribute("Index")]
public int Index { get; set; }
public Data Data { get; set; }
}
[Serializable]
public class Data
{
[XmlAttribute("Type")]
public string Type { get; set; }
[XmlText]
public string Value { get; set; }
}
[Serializable]
public class DocumentProperties
{
public DateTime Created { get; set; }
public string Version { get; set; }
}
<?xml version="1.0" encoding="gb2312" ?>