witam ;)
chcialem stworzyc taki plik xml, ktory bedzie mozna edytowac w exelu i z odczytem oraz ewent edycja ktorego poradzi sobie program c#. moim malutkim marzeniem bylo skorzystac z System.XPath zeby bylo ladnie szybko i zgrabnie :) jednak takie cos nie dziala:
private void button1_Click(object sender, EventArgs e)
{
//ustawia regoly odczytu danych z pliku xml
XmlReaderSettings xrs = new XmlReaderSettings();
xrs.ConformanceLevel = ConformanceLevel.Auto;
xrs.IgnoreWhitespace = true;
xrs.IgnoreComments = true;
//ustawia ścieżkę dosępu do interesujących mnie danych
string sciazka_dane = "/Workbook/Worksheet/Table/Row/Cell/Data";
try
{
XmlDocument doc = new XmlDocument();
XmlReader xr = XmlReader.Create(new StreamReader("tab1.xml",Encoding.GetEncoding(1250)),xrs);
XPathDocument xDoc = new XPathDocument(xr);
XPathNavigator nav = xDoc.CreateNavigator();
XPathNodeIterator iterator;
iterator = nav.Select(sciazka_dane);
MessageBox.Show("poczatek petli");
while (iterator.MoveNext())
MessageBox.Show(iterator.Current.Value);
xr.Close();
}
catch (System.IO.FileNotFoundException)
{
MessageBox.Show("nie znaleziono pliku");
goto koniec;
}
koniec:
;
}
problemem nie jest kod a sciezka dostepu bo na prostym pliku XML wszystko dziala. kod wygenerowany przez exela w pliku tab1.xml:
<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
<Version>10.6626</Version>
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
<DownloadComponents/>
<LocationOfComponents HRef="file:///E:\programy\OFFICE.XP.PRO.PL.z.SP3\OFFICE\"/>
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<WindowHeight>10005</WindowHeight>
<WindowWidth>10005</WindowWidth>
<WindowTopX>120</WindowTopX>
<WindowTopY>135</WindowTopY>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom"/>
<Borders/>
<Font x:CharSet="238"/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
</Styles>
<Worksheet ss:Name="Sheet1">
<Table ss:ExpandedColumnCount="3" ss:ExpandedRowCount="2" x:FullColumns="1"
x:FullRows="1">
<Row>
<Cell><Data ss:Type="String">1</Data></Cell>
<Cell><Data ss:Type="String">2</Data></Cell>
<Cell><Data ss:Type="String">3</Data></Cell>
</Row>
<Row>
<Cell ss:Index="2"><Data ss:Type="String">j</Data></Cell>
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<PageSetup>
<PageMargins x:Bottom="0.984251969" x:Left="0.78740157499999996"
x:Right="0.78740157499999996" x:Top="0.984251969"/>
</PageSetup>
<Selected/>
<Panes>
<Pane>
<Number>3</Number>
<ActiveRow>2</ActiveRow>
<ActiveCol>1</ActiveCol>
</Pane>
</Panes>
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
</Workbook>
</quote></span>
poza kilkoma "dodatkami" po drodze struktura pliku tak wlasnei wyglada... moze mi ktos pomoc albo cos zasugerowac?? bo juz pare godz dzisiaj na to stracilem i konczy mi sie cierpliwosc :)
pozdrawiam :)