Click here to Skip to main content
13,046,356 members (69,051 online)
Click here to Skip to main content


82 bookmarked
Posted 11 Jan 2009

XML/XSLT Word Report Generator

, 11 Jan 2009
The tool is based on XML/XSLT, and allows a user to create a Word report from scratch, namely: construct SQL query, construct a WordML template, generate a document.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Data.SqlClient;
using System.Reflection;
using System.IO;

namespace WordReportGenerator
    public partial class WRG : Form
        private WRGEngine engine;

        public static DAL dal;
        public static string _namespace = typeof(WRG).Namespace;
        public static Assembly _assembly = Assembly.GetExecutingAssembly();
        public static string _path;
        public static string _assemblyName;

        private SqlConnection cnn;

        public WRG(){
            dal = new DAL();
            cnn = new SqlConnection(global::WordReportGenerator.Properties.Settings.Default.SQLConnectionString);

            this.Load += new EventHandler(ObjectsEditorForm_Load);
            this.FormClosing += new FormClosingEventHandler(WRG_FormClosing);


        void WRG_FormClosing(object sender, FormClosingEventArgs e)
            if (MessageBox.Show("Do you want to save changes?", "", MessageBoxButtons.OKCancel) == DialogResult.OK)
                this.btn_apply_Click(sender, (EventArgs)e);

        void ObjectsEditorForm_Load(object sender, EventArgs e)

            dal.Init(cnn, true, true);
            engine = new WRGEngine();

            _path = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData), "WordReportGenerator");
                PathCreationEngine.CreateDirectory(_path, this, "CommonDataPath");
            catch (Exception ex) { MessageBox.Show(ex.Message); }

            _assemblyName = _assembly.GetName().Name;
            btn_loadtemplate.Click += new EventHandler(engine.btn_loadtemplate_Click);
            btn_genreport.Click += new EventHandler(engine.btn_genreport_Click);

            this.gv.DataSource = WRG.dal.bs_wordreports;
            this.nav.BindingSource = WRG.dal.bs_wordreports;
   = engine;
            engine.gv = this.gv;
            this.Text = "Word Report Generator";
            cb.Checked = true;


        private void btn_apply_Click(object sender, EventArgs e){

        private void btn_OK_Click(object sender, EventArgs e){
            DialogResult = DialogResult.OK;

        private void btn_cancel_Click(object sender, EventArgs e)
            DialogResult = DialogResult.Cancel;

        private void btn_Refresh_Click(object sender, EventArgs e){

        private void toolStripButton3_Click(object sender, EventArgs e){
            Object value = engine;
            SqlExecutor sqlexec = new SqlExecutor(ref value);
            if (sqlexec.ShowDialog() == DialogResult.OK)


        private void cb_CheckedChanged(object sender, EventArgs e){
            engine.autoset = cb.Checked;


    public class DocumentInstanceException : Exception
    { }

    public class ValidDocumentException : Exception
    { }

    public class WordInstanceException : Exception
    { }

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.


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


About the Author

Sam Safonov
Software Developer
Russian Federation Russian Federation
I have Master degree in Particle Physics. During my last several years I work as software developer.

Primary Interests
- c#, c++, php, java.
- scientific programming

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 11 Jan 2009
Article Copyright 2009 by Sam Safonov
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid