wordpress hit counter
Welcome to OpenXML Developer Sign in | Join | Help

Error while opening an xlsx file created in vb.net

Last post 08-06-2010, 2:12 AM by Raheem MA. 4 replies.
Sort Posts: Previous Next
  •  05-08-2009, 1:47 AM 4616

    Error while opening an xlsx file created in vb.net

    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.

     

  •  05-14-2009, 4:43 AM 4642 in reply to 4616

    Re: Error while opening an xlsx file created in vb.net

    i am done with the application.

    now it doesnt show any error message.

    No office is required on server.

    All you need is office 2007 on client mahine.

    and in case your client has 2003 then SP2 office 2007 is needed.

    In case anybody needs any help with this, feel free to ask.

    regards,

    Abhishek.

  •  07-01-2009, 12:42 PM 7097 in reply to 4642

    Re: Error while opening an xlsx file created in vb.net

    How did you fix this problem? I get it when I try to push the file as a download. Seems like the version saved on the server during creation is fine, though.
  •  07-01-2009, 1:01 PM 7099 in reply to 7097

    Re: Error while opening an xlsx file created in vb.net

    If you have a valid document saved into your temporary directory but it appeaars invalid when you stream back to the client it's likely you're not setting the correct MIME type.

    This article has a good list.

    http://therightstuff.de/2006/12/16/Office+2007+File+Icons+For+Windows+SharePoint+Services+20+And+SharePoint+Portal+Server+2003.aspx
  •  08-06-2010, 2:12 AM 21642 in reply to 4642

    Re: Error while opening an xlsx file created in vb.net

    Hello Abhishek,

    We have the same issue while opening excel sheet which is created using Open XML and C#. You said its required to have SP2 office 2007 on client machine. We do have main version of office 2007 but not SP1 and SP2.

    Is there any way to get rid of this issue if we do not have SP2 office 2007 on client machine?

    Please shed some light on this and help us in fixing the issue :)

    Thank you,
    Raheem MA

View as RSS news feed in XML