-
Notifications
You must be signed in to change notification settings - Fork 0
/
ODSReader.cs
59 lines (45 loc) · 1.46 KB
/
ODSReader.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using System.IO.Compression;
using System.Text;
using System.Threading.Tasks;
namespace ODSReader
{
class ODSReader
{
private ZipArchiveEntry ContentXmlFile;
private XDocument Document;
public List<List<XElement>> CellRows;
private List<XElement> Cells;
void UnzipODS(System.IO.Stream stream)
{
//ZipArchive archive = ZipFile.OpenRead(path);
ZipArchive archive = new ZipArchive(stream);
ContentXmlFile = archive.GetEntry("content.xml");
}
void LoadXMLFile()
{
Document = XDocument.Load(ContentXmlFile.Open());
}
public void ReadXmlFile()
{
var rows = Document.Descendants("{urn:oasis:names:tc:opendocument:xmlns:table:1.0}table-row").Skip(1);
foreach (var row in rows)
{
Cells = (from c in row.Descendants()
where c.Name == "{urn:oasis:names:tc:opendocument:xmlns:table:1.0}table-cell"
select c).ToList();
CellRows.Add(Cells);
}
}
public ODSReader(System.IO.Stream stream)
{
CellRows = new List<List<XElement>>();
UnzipODS(stream);
LoadXMLFile();
ReadXmlFile();
}
}
}