hi,
i am facing a problem while opening an xlsx file crested by code in vb.net.
can anyone help me out.?
below is the error log i am getting.
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
- <recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<logFileName>error027240_01.xml</logFileName>
<summary>Errors were detected in file '\\LocalMachine\New Folder\Export.xlsx'</summary>
- <additionalInfo>
<info>Excel completed file level validation and repair. Some parts of this workbook may have been repaired or discarded.</info>
</additionalInfo>
- <repairedRecords summary="Following is a list of repairs:">
<repairedRecord>Repaired Records: Table from /xl/tables/table1.xml part (Table)</repairedRecord>
</repairedRecords>
</recoveryLog>
------------------------------
below is the code.i have a datagrid that has 4 cols and n number of rows.(cols and rows can differ)
-----------------------------------
Dim
cNode As XmlElement
Dim vNode As XmlElement
Dim xDocResult As New XmlDocument
Dim strArray As New ArrayList
Dim totalStringCount As Integer = 0
Dim rowCount As Integer = Me.orderDetails.Count
Dim colCount As Integer = 4
Dim root As XmlElement = xDocResult.DocumentElement
Dim xmldecl As XmlDeclaration = xDocResult.CreateXmlDeclaration("1.0", "UTF-8", "yes")
xDocResult.InsertBefore(xmldecl, root)
Dim workSheet As XmlElement = xDocResult.CreateElement("worksheet")
workSheet.SetAttribute(
"xmlns", "http://schemas.openxmlformats.org/spreadsheetml/2006/main")
workSheet.SetAttribute(
"xmlns:r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships")
xDocResult.AppendChild(workSheet)
Dim cols As XmlElement = xDocResult.CreateElement("cols")
workSheet.AppendChild(cols)
Dim col As XmlElement = xDocResult.CreateElement("col")
col.SetAttribute(
"min", "1")
col.SetAttribute(
"max", colCount.ToString)
col.SetAttribute(
"width", "30")
col.SetAttribute(
"style", "2")
col.SetAttribute(
"customWidth", "1")
cols.AppendChild(col)
Dim sheetData As XmlElement = xDocResult.CreateElement("sheetData")
workSheet.AppendChild(sheetData)
Dim rNode As XmlElement = xDocResult.CreateElement("row")
Dim CSInt As Integer = 1
rNode.SetAttribute(
"r", CSInt.ToString)
rNode.SetAttribute(
"spans", ("1:" & colCount))
sheetData.AppendChild(rNode)
Dim icol As Integer = 0
Do While (icol <= (colCount - 1))
cNode = xDocResult.CreateElement(
"c")
CSInt = 1
cNode.SetAttribute(
"r", (Me.alphArray(icol) & CSInt.ToString))
cNode.SetAttribute(
"s", "1")
rNode.AppendChild(cNode)
vNode = xDocResult.CreateElement(
"v")
Dim hdrRow As GridViewRow = DirectCast(Me.orderDetails.Item(0), GridViewRow)
cNode.SetAttribute(
"t", "s")
totalStringCount += 1
If Not strArray.Contains(hdrRow.Cells.Item(icol).Text) Then
strArray.Add(hdrRow.Cells.Item(icol).Text)
CSInt = (strArray.Count - 1)
vNode.InnerText = CSInt.ToString
Else
vNode.InnerText = strArray.IndexOf(hdrRow.Cells.Item(icol).Text).ToString
End If
cNode.AppendChild(vNode)
icol += 1
Loop
Dim r As Integer = 1
Do While (r <= (Me.orderDetails.Count - 1))
rNode = xDocResult.CreateElement(
"row")
CSInt = (r + 1)
rNode.SetAttribute(
"r", CSInt.ToString)
rNode.SetAttribute(
"spans", ("1:" & colCount))
sheetData.AppendChild(rNode)
Dim dRow As GridViewRow = DirectCast(Me.orderDetails.Item(r), GridViewRow)
Dim c As Integer = 0
Do While (c <= (colCount - 1))
cNode = xDocResult.CreateElement(
"c")
CSInt = (r + 1)
cNode.SetAttribute(
"r", (Me.alphArray(c) & CSInt.ToString))
If (c >= 2) Then
cNode.SetAttribute(
"s", "3")
Else
cNode.SetAttribute(
"s", "2")
End If
rNode.AppendChild(cNode)
vNode = xDocResult.CreateElement(
"v")
cNode.SetAttribute(
"t", "s")
totalStringCount += 1
If Not strArray.Contains(dRow.Cells.Item(c).Text) Then
strArray.Add(dRow.Cells.Item(c).Text)
vNode.InnerText = (strArray.Count - 1).ToString
Else
vNode.InnerText = strArray.IndexOf(dRow.Cells.Item(c).Text).ToString
End If
cNode.AppendChild(vNode)
c += 1
Loop
r += 1
Loop
Dim tableParts As XmlElement = xDocResult.CreateElement("tableParts")
tableParts.SetAttribute(
"count", "1")
workSheet.AppendChild(tableParts)
Dim tablePart As XmlElement = xDocResult.CreateElement("tablePart")
tablePart.SetAttribute(
"id", "http://schemas.openxmlformats.org/officeDocument/2006/relationships", "rId1")
tableParts.AppendChild(tablePart)
Me.CreateSharedStringsPart(strArray, totalStringCount)
Return xDocResult.OuterXml
---------------------------------------------------
Any help will be highly appreciable.
Thanks n Regards.
Abhishek.