Background
I have an Excel spreadsheet that I have saved as a 2003 XML spread sheet and I have pasted this into a console mode VB.NET program created with VS 2022.
Goal
I want to automate adding some columns using VB.NET.
Observations
I see that MSExcel makes extensive use of XML namespaces:
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<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">
<Worksheet ss:Name="197 Industry Groups">
<Table ss:ExpandedColumnCount="10" ss:ExpandedRowCount="198" x:FullColumns="1"
x:FullRows="1" ss:DefaultColumnWidth="42" ss:DefaultRowHeight="11.25">
<Row>
<Cell><Data ss:Type="String">Order</Data><NamedCell ss:Name="_FilterDatabase"/></Cell>
<Cell><Data ss:Type="String">Symbol</Data><NamedCell ss:Name="_FilterDatabase"/></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">2</Data><NamedCell ss:Name="_FilterDatabase"/></Cell>
<Cell ss:StyleID="s62" ss:HRef="https://marketsmith.investors.com/mstool?Symbol=G1000"><Data
ss:Type="String">G1000</Data><NamedCell ss:Name="_FilterDatabase"/></Cell>
Plan
Use the XPath to get a reference to the first row and add a cell to it using this post as a guide
Questions
- What namespaces do I need to add to the namespaceManager? What do I use for the second (uri) argument to the AddNameSpace function? Do I need to add an empty namespace?
- Why do the values g2 and g1000 get the value Nothing?
Dim g2 = industryGroups.XPathSelectElement("//ss:Workbook/ss:Worksheet/ss:Table/ss:Row[0]", namespaceManager)
Dim g1000 = (From p In industryGroups.Descendants("Table") Select p).FirstOrDefault()
- How do I add a new XElement (cell) using the other cells as a pattern (i.e. each cell contains a data with an attribute or in some cases the cell will have an href attribute). Can I use the XML literal feature and embed my computed hrefs, strings and numbers?
Thanks!
Siegfried