[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

printing and creating an html report from vs2005

Posted on 2007-10-15
8
Medium Priority
?
203 Views
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???
10x
0
Comment
Question by:orenisraeli2000
  • 4
  • 4
8 Comments
 
LVL 22

Expert Comment

by:JimBrandley
ID: 20080297
Do you want to print a tabular report, or generate an HTML file?

Jim
0
 
LVL 1

Author Comment

by:orenisraeli2000
ID: 20080790
I want to print a tabular report, I heard I can generate a HTML file and print it
0
 
LVL 1

Author Comment

by:orenisraeli2000
ID: 20080809
can I use Access built in Report from my Winform App??
0
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 22

Expert Comment

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

http://www.codeproject.com/useritems/DGVPrinter.asp

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#.

Jim
0
 
LVL 1

Author Comment

by:orenisraeli2000
ID: 20081211
and yet what about making an HTML file and then print it?? can u help me with that???
0
 
LVL 22

Expert Comment

by:JimBrandley
ID: 20081327
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.

Jim
0
 
LVL 22

Accepted Solution

by:
JimBrandley earned 600 total points
ID: 20097462
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.WriteStartElement("Schedule");
   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.
   tw.WriteStartElement("Header");

   tw.WriteElementString("Col1","Name");
   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);
   }
   tw.WriteEndElement();

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

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.Load(xslPath);

   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="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" omit-xml-declaration="yes"/>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>The SleepStore</title>
<link href="SleepSchedule.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>The SleepStore</h1>
<ul>
  <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>
</ul>
<br />
<br />
    <table>
      <tr>
        <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>
      </tr>
      <xsl:for-each select="Schedule/Row">
            <tr>
               <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>
            </tr>
      </xsl:for-each>
    </table>
    <br />
    <br />
</body></html>
</xsl:template>
</xsl:stylesheet>

Jim
0
 
LVL 1

Author Comment

by:orenisraeli2000
ID: 20100234
well, I got it allready but I think you own the points anyway for the effort. thank you very much
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Suggested Courses

834 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