printing and creating an html report from vs2005

Posted on 2007-10-15
Last Modified: 2013-12-17
hi there,
we have an Acess file as our DB, we need to print one of our tables as a tabular report, how do I do it using vs2005, c# and HTML???
Question by:orenisraeli2000
    LVL 22

    Expert Comment

    Do you want to print a tabular report, or generate an HTML file?

    LVL 1

    Author Comment

    I want to print a tabular report, I heard I can generate a HTML file and print it
    LVL 1

    Author Comment

    can I use Access built in Report from my Winform App??
    LVL 22

    Expert Comment

    I load the data into a DataGridView and use a class called DGVPrinter to do tabular reports easily. You can get that class here:

    To generate HTML reports, I dump my data into XML and use XSL to produce the file content. I do not know if Access reports can be used in C#.

    LVL 1

    Author Comment

    and yet what about making an HTML file and then print it?? can u help me with that???
    LVL 22

    Expert Comment

    If you can load the data from access into a DataTable, I will build some sample code to convert it to HTML. This will take some time.

    LVL 22

    Accepted Solution

    Finally - Here's an example that dumps a DataTable to an XML file, then creates an HTML file from the XML.
    In this code, mScheduleData is a DataTable that contains some scheduling information.

    private void DumpToXML(XmlTextWriter tw)
       int rowCount = mScheduleData.Rows.Count;
       DataRow row;
       int index = 0;
       int colIndex = 0;
       string processed = "No";
       string day;
       string date;
       // Dates are used for the column headers in this case.
       DateTime endDate = this.StartDate.AddDays(27);
       DateTime nextDate = this.StartDate;

       if (Processed)
           processed = "Yes";
       tw.WriteAttributeString("Processed", processed);
       // This is for the HTML page
       tw.WriteElementString("Title", nextDate.ToString("MMM d") + " through " + endDate.ToString("MMM d yyyy"));

       // The XSL uses this block to create column headers.

       for (int i = 2; i < 30; i++)
          day = nextDate.ToString("r").Substring(0, 3);
          date = nextDate.ToString("MMM d");
          tw.WriteElementString("Col" + i.ToString(), day + " " + date);
          nextDate = nextDate.AddDays(1);

       // Now dump the data rows.
       while (index < rowCount)
           row = mScheduleData.Rows[index++];
           colIndex = 0;
           while (colIndex < 30)
             tw.WriteElementString("Col" + colIndex.ToString(), row[colIndex].ToString());

    This creates the HTML using the xsl file. In this code, mFileName is a class member that contains the complete path to the xml file.

    public void DumpToHtml(string xslPath)
       string htmlPath = mFileName.Replace("xml", "html");

       XslCompiledTransform xsl = new XslCompiledTransform(true);

       xsl.Transform(mFileName, htmlPath);

    Here is the XSL I used. NOTE - You will need to replace "SleepSchedule.css" with the name of your css file:

    <?xml version="1.0"?>
    <!-- This stylesheet is used to make SleepStore schedule files suitable for email. -->
    <xsl:stylesheet version="1.0" xmlns:xsl="">
    <xsl:output method="xml" indent="yes" doctype-system="" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" omit-xml-declaration="yes"/>
    <xsl:template match="/">
    <html xmlns="">
    <title>The SleepStore</title>
    <link href="SleepSchedule.css" rel="stylesheet" type="text/css" />
    <h1>The SleepStore</h1>
      <li>Staff schedule for: <xsl:value-of select="//Schedule/Title" /></li>
      <li>Notes:<BR/>All schedule requests are due by the third week of the schedule.<BR/>C indicates on-call.</li>
    <br />
    <br />
            <th><xsl:value-of select="//Schedule/Header/Col1" /></th>
            <th><xsl:value-of select="//Schedule/Header/Col2" /></th>
            <th><xsl:value-of select="//Schedule/Header/Col3" /></th>
            <th><xsl:value-of select="//Schedule/Header/Col4" /></th>
            <th><xsl:value-of select="//Schedule/Header/Col5" /></th>
            <th><xsl:value-of select="//Schedule/Header/Col6" /></th>
            <th><xsl:value-of select="//Schedule/Header/Col7" /></th>
            <th><xsl:value-of select="//Schedule/Header/Col8" /></th>
            <th><xsl:value-of select="//Schedule/Header/Col9" /></th>
            <th><xsl:value-of select="//Schedule/Header/Col10" /></th>
            <th><xsl:value-of select="//Schedule/Header/Col11" /></th>
            <th><xsl:value-of select="//Schedule/Header/Col12" /></th>
            <th><xsl:value-of select="//Schedule/Header/Col13" /></th>
            <th><xsl:value-of select="//Schedule/Header/Col14" /></th>
            <th><xsl:value-of select="//Schedule/Header/Col15" /></th>
            <th><xsl:value-of select="//Schedule/Header/Col16" /></th>
            <th><xsl:value-of select="//Schedule/Header/Col17" /></th>
            <th><xsl:value-of select="//Schedule/Header/Col18" /></th>
            <th><xsl:value-of select="//Schedule/Header/Col19" /></th>
            <th><xsl:value-of select="//Schedule/Header/Col20" /></th>
            <th><xsl:value-of select="//Schedule/Header/Col21" /></th>
            <th><xsl:value-of select="//Schedule/Header/Col22" /></th>
            <th><xsl:value-of select="//Schedule/Header/Col23" /></th>
            <th><xsl:value-of select="//Schedule/Header/Col24" /></th>
            <th><xsl:value-of select="//Schedule/Header/Col25" /></th>
            <th><xsl:value-of select="//Schedule/Header/Col26" /></th>
            <th><xsl:value-of select="//Schedule/Header/Col27" /></th>
            <th><xsl:value-of select="//Schedule/Header/Col28" /></th>
            <th><xsl:value-of select="//Schedule/Header/Col29" /></th>
          <xsl:for-each select="Schedule/Row">
                   <td><xsl:value-of select="Col1"/></td>
                   <td><xsl:value-of select="Col2"/></td>
                   <td><xsl:value-of select="Col3"/></td>
                   <td><xsl:value-of select="Col4"/></td>
                   <td><xsl:value-of select="Col5"/></td>
                   <td><xsl:value-of select="Col6"/></td>
                   <td><xsl:value-of select="Col7"/></td>
                   <td><xsl:value-of select="Col8"/></td>
                   <td><xsl:value-of select="Col9"/></td>
                   <td><xsl:value-of select="Col10"/></td>
                   <td><xsl:value-of select="Col11"/></td>
                   <td><xsl:value-of select="Col12"/></td>
                   <td><xsl:value-of select="Col13"/></td>
                   <td><xsl:value-of select="Col14"/></td>
                   <td><xsl:value-of select="Col15"/></td>
                   <td><xsl:value-of select="Col16"/></td>
                   <td><xsl:value-of select="Col17"/></td>
                   <td><xsl:value-of select="Col18"/></td>
                   <td><xsl:value-of select="Col19"/></td>
                   <td><xsl:value-of select="Col20"/></td>
                   <td><xsl:value-of select="Col21"/></td>
                   <td><xsl:value-of select="Col22"/></td>
                   <td><xsl:value-of select="Col23"/></td>
                   <td><xsl:value-of select="Col24"/></td>
                   <td><xsl:value-of select="Col25"/></td>
                   <td><xsl:value-of select="Col26"/></td>
                   <td><xsl:value-of select="Col27"/></td>
                   <td><xsl:value-of select="Col28"/></td>
                   <td><xsl:value-of select="Col29"/></td>
        <br />
        <br />

    LVL 1

    Author Comment

    well, I got it allready but I think you own the points anyway for the effort. thank you very much

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
    I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
    Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now