Question

Hello guys I have 1675 line Code. Want to when user click button textbox.text insert into this xml spreadsheet and then create on desktop. does it possible? How can I insert text in current xml spreadsheet row?

For example:

  ` <Cell ss:StyleID="s38"/>
    <Cell ss:StyleID="s39">
    <Data ss:Type="String">ვაშლიჯვარი</Data>
    </Cell>
    <Cell ss:StyleID="s36"/>`

Please help me, advice something its very important for me or give some good tutorials.

Was it helpful?

Solution

You can open the Excel XML file using LINQ to XML. You can the modify the XML DOM as you require. You will have to correlate cells in the Excel worksheet with XML elements. You can then save the modified XML DOM to create a new and modified Excel XML file.

Here is a small example to get you going:

var xDocument = XDocument.Load("EL-Zednadebi.xml");
// XML elements are in the "ss" namespace.
XNamespace ss = "urn:schemas-microsoft-com:office:spreadsheet";
var rows = xDocument.Root.Element(ss + "Worksheet")
  .Element(ss + "Table").Elements(ss + "Row");
// Row 12.
var row = rows.ElementAt(11);
var cells = row.Elements(ss + "Cell");
// Column U.
var cell = cells.ElementAt(20);
var data = cell.Element(ss + "Data");
// Replace the text in the cell.
data.Value = "Martin Liversage";
xDocument.Save("EL-Zednadebi-2.xml");

This code assumes the following simplified XML:

<Workbook>
  ...
  <Worksheet>
    <Table>
       ...
       <Row> <-- Row at index 11
         ...
         <Cell> <-- Column at index 20
           <Data>ვაშლიჯვარი</Data>
         <Cell>
         ...
       </Row>
       ...
    </Table>
    ...
  </Worksheet>
  ...
</Workbook>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top