I have some XML and I need to convert them to a Microsoft Office Document(2007). What's the best and fastest way to do it? I can do it using C# or Java. I've seen that spire. I can do it but it's quite expensive, is there an alternative? Does Microsoft offer something?
            Asked
            
        
        
            Active
            
        
            Viewed 6,804 times
        
    0
            
            
        - 
                    That's really not how XML works. – Chris Eberle May 09 '12 at 03:04
- 
                    What kind of XML document is it? – Taymon May 09 '12 at 03:05
- 
                    And what kind of "Office Document" do you want? Spreadsheet? Word? PowerPoint? EMail? Note?... – Andrew Barber May 09 '12 at 03:06
- 
                    Maybe open with excel and then copy past into word ??? – RThomas May 09 '12 at 03:06
- 
                    i need to convert it to a Word document, i can parse the XML just fine. I need to create a Word document via code. I have a lot of XML(which are some survey results) files and i need to convert them to a Doc – Thiago Valle May 09 '12 at 03:15
- 
                    1http://stackoverflow.com/questions/2757699/word-2010-for-writing-invoices-starting-with-xml – Preet Sangha May 09 '12 at 03:17
1 Answers
4
            You could use XSLT - And there's a nice sample here on Christian Nagel's OneNotes.
Taking this XML
    <?xml version="1.0" encoding="utf-8" ?>
    <Courses>
     <Course Number="MS-2524">
      <Title>XML Web Services Programming</Title>
     </Course>
     <Course Number="MS-2124">
      <Title>C# Programming</Title>
     </Course>
     <Course Number="NET2">
      <Title>.NET 2.0 Early Adapter</Title>
     </Course>
    </Courses>
And using this XML Style sheet:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml">
 <xsl:output method="xml" indent="yes" />
 <xsl:template match="/">
  <xsl:processing-instruction name="mso-application">
   <xsl:text>progid="Word.Document"</xsl:text>
  </xsl:processing-instruction>
  <w:wordDocument>
   <w:body>
     <xsl:apply-templates select="Courses/Course" />
   </w:body>
  </w:wordDocument>
 </xsl:template>
 <xsl:template match="Course">
    <w:p>
     <w:r>
      <w:t>
       <xsl:value-of select="@Number" />, <xsl:value-of select="Title"/>
      </w:t>
     </w:r>
    </w:p>
 </xsl:template>
</xsl:stylesheet>
Can generate this MS Word Doc for 2003.
<?xml version="1.0" encoding="utf-8"?>
<?mso-application progid="Word.Document"?>
<w:wordDocument xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml">
  <w:body>
    <w:p>
      <w:r>
        <w:t>MS-2524, XML Web Services Programming</w:t>
      </w:r>
    </w:p>
    <w:p>
      <w:r>
        <w:t>MS-2124, C# Programming</w:t>
      </w:r>
    </w:p>
    <w:p>
      <w:r>
        <w:t>NET2, .NET 2.0 Early Adapter</w:t>
      </w:r>
    </w:p>
  </w:body>
</w:wordDocument>
To do this in code see this answer: https://stackoverflow.com/a/34095/30225
What you need to do either use an equivalent for Office 2007 docx or just generate the 2003 doc and let people open it in 2007.
 
    
    
        Community
        
- 1
- 1
 
    
    
        Preet Sangha
        
- 64,563
- 18
- 145
- 216
 
    