Foros del Web » Programación para mayores de 30 ;) » .NET »

Word a Xml

Estas en el tema de Word a Xml en el foro de .NET en Foros del Web. Hola me encuentro frente a un desafio ke aun no he podido solucionar,convertir un doc a xml. Investigue y encontre una function ke me ayuda ...
  #1 (permalink)  
Antiguo 14/08/2007, 08:54
Avatar de rekkiem  
Fecha de Ingreso: diciembre-2006
Mensajes: 30
Antigüedad: 17 años, 4 meses
Puntos: 0
Sonrisa Word a Xml

Hola me encuentro frente a un desafio ke aun no he podido solucionar,convertir un doc a xml. Investigue y encontre una function ke me ayuda en parte, pero el problema esta en pasar las tablas del word en forma de nodos xml para poder transformarlas despues por xsl a html en forma ordenada

Código:
Private Function docToXml(ByVal doc As Word.Document) As XmlDocument
      Dim xmlDoc As New XmlDocument
      Dim styleMapper As New StyleMapping(Application.StartupPath & "\stylemapping.xml")
      'Dim styleMapper As New StyleMapping("c:\stylemapping.xml")
      'styleMapper.SetMapping("Normal", "text")
      xmlDoc.PreserveWhitespace = True
        Dim pageNode As XmlElement
        Dim tableNode As XmlElement

      Dim documentNode As XmlElement
      ' create a root document node
      documentNode = xmlDoc.CreateElement("document")
      xmlDoc.AppendChild(documentNode)

      ' add one page
      pageNode = Me.addPage(xmlDoc)
      documentNode.AppendChild(pageNode)
      Dim currentPageNumber As Integer = Integer.Parse(pageNode.Attributes("id").Value)
      ' loop through each paragraph
      For Each section As Word.Section In doc.Sections
         For Each p As Word.Paragraph In doc.Paragraphs
            ' check the pagenumber
            If CType(wordApp.Selection.Information(Word.WdInformation.wdActiveEndPageNumber), Integer) > currentPageNumber Then
               pageNode = Me.addPage(xmlDoc)
               currentPageNumber = Integer.Parse(pageNode.Attributes("id").Value)
            End If
            ' get the para text
            Dim s As String = p.Range.Text

            ' check to see if there's a hard page break at the start of this para
            If Asc(s.Chars(0)) = &HC Then
               s = s.Substring(1, s.Length - 1)
               pageNode = Me.addPage(xmlDoc)
               currentPageNumber = Integer.Parse(pageNode.Attributes("id").Value)
            End If
            If p.Range.Text.Trim <> String.Empty Then
               ' strip carriage return from end of para text
               Do While s.EndsWith(Chr(13)) Or s.EndsWith(Chr(10))
                  s = s.Substring(0, s.Length - 1)
               Loop
               Dim stylename As String = CType(p.Style, Word.Style).NameLocal
               Dim elementName As String = styleMapper.GetStyleToElementMapping(stylename)
               Dim N As XmlElement = xmlDoc.CreateElement(elementName)
                    N.InnerText = s

                    pageNode.AppendChild(N)

          '          If stylename = "<table>" Then
           '             tableNode = Me.addTable(xmlDoc)
            '        End If
                End If
              
            Next
      Next
      Return xmlDoc
   End Function
ahora estoy buscando una funcion que me permita manejar tablas d word en vb.net, si alguien tiene alguna idea c lo agradecere
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 08:01.