Click here to Skip to main content
15,891,431 members
Articles / Web Development / HTML

Generating Word Reports / Documents

Rate me:
Please Sign up or sign in to vote.
4.94/5 (122 votes)
4 Oct 2009CPOL22 min read 707.1K   8K   544  
Generate Word documents by appling XSLT on XML data.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Diagnostics;
using GeneratingMicrosoftWordReports.Reports;

namespace GeneratingMicrosoftWordReports.Transformer
{
    /// <summary>
    /// Demonstrates usage of GeneratingMicrosoftWordReports.Reports class library
    /// </summary>
    class Program
    {
        private static string _outputPath = @"c:\test.doc";
        static void Main(string[] args)
        {
            // Populate report using data and return it as byte array
            //byte[] wordDoc = Report.WordGeneratedInvoice();
            byte[] wordDoc = Report.WordGeneratedInvoice();

            // Write resulting array to HDD, show process information
            using (FileStream fs = new FileStream(_outputPath, FileMode.Create))
                fs.Write(wordDoc, 0, wordDoc.Length);

            Console.WriteLine("Saved to: {0}", _outputPath);
            Console.WriteLine("\nPress any key to continue");
            Console.ReadKey();

            // Display resulting report in Word
            Process.Start(new ProcessStartInfo(_outputPath));
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer
United States United States
If you liked this article, consider reading other articles by me. For republishing article on other websites, please contact me by leaving a comment.

Comments and Discussions