locked
creating one word doc from some xml files RRS feed

  • Question

  •  

    Hi,

     

    I am trying to create a word document file using a XslCompiledTransform object.

    I succeed to write a doc from one xml file with xslt.


    No I am trying to write one doc from some xmls and not just one. I want to append every xml data to the end of the same doc after I added the previous one.

    The result is that the first xml data is in the doc file but the others are not appending there.

     

    The code is attached. CreateReportDoc() is called from a foreach loop giving the same destFolder, xsltFile, isUnicode = false and same reportFile. The only difference if the inputXml, which is a Path.GetTempFileName() xml file filled with my information.

     

    I need you advice, please. What is the problem and how can I do it.

     

     

            StreamWriter writer = null;

            XslCompiledTransform xslTran = null;

     

            private bool CreateReportDoc(string destFolder, string inputXml, string xsltFile, bool isUnicode, out string reportFile)

            {

                bool isOk = true;

     

                destFolder = "c:\"

                string  strReportName = "aaa";

                reportFile = strReportName + ".rtf";

     

                XmlTextReader reader;

     

                    writer = new StreamWriter(reportFile, true, isUnicode ? System.Text.Encoding.Unicode : System.Text.Encoding.Default);

                    reader = new XmlTextReader(inputXml);

      

                 XmlTextReader reader = new XmlTextReader(inputXml);

     

                    // Load the XSLT for Transformation

                    if (xslTran == null)

                    {

                        xslTran = new XslCompiledTransform(true);

                    }

                    xslTran.Load(xsltFile);

     

                    // Create the rtf file by Transforming the XML and XSLT.

                    xslTran.Transform(reader, null, writer);

                    writer.Flush();

                    writer.Close();

                    reader.Close();

                }

                catch (Exception ex)

                {

                    isOk = false;

                }

     

                return isOk;

            }

     

     

     

     

     

     

     

     

     

    Wednesday, February 11, 2009 2:58 PM

Answers

  • Don't think this would work. But htis should be easy to debug.
    First split problems:
    1. What format you wneed to generate
    2. How to generate data in this format.

    Should be easy to unswer either of them. RTF is text. Open it in notepad and see how each of files you want to mearge look and whether word opens them separately.
    Second step merge them manualy. In the Notepad again. Check in the word that what you get is what you want. 
    If not -- you have a problem with forma and should bother debugging the program that generates it.
    If it is you know the format -- then open generated merged file in the Notepad and see does your program generates what you expected it should.

    WebData/Sergey
    Friday, February 13, 2009 7:13 AM

All replies

  • I am not familiar with details of the RTF format. Are you sure it allows you to simply append new contents to the end of an existing RTF file?
    MVP XML
    Wednesday, February 11, 2009 4:39 PM
  • Don't think this would work. But htis should be easy to debug.
    First split problems:
    1. What format you wneed to generate
    2. How to generate data in this format.

    Should be easy to unswer either of them. RTF is text. Open it in notepad and see how each of files you want to mearge look and whether word opens them separately.
    Second step merge them manualy. In the Notepad again. Check in the word that what you get is what you want. 
    If not -- you have a problem with forma and should bother debugging the program that generates it.
    If it is you know the format -- then open generated merged file in the Notepad and see does your program generates what you expected it should.

    WebData/Sergey
    Friday, February 13, 2009 7:13 AM