Converting HTML export to Excel..
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Converting HTML export to Excel..

  1. #1
    Join Date
    Apr 2013
    Posts
    2

    Converting HTML export to Excel..

    Hello all... I currently am working on a program that exports to an HTML document. I am trying to get it exporting to excel and am not sure where to start (never exported to excel before). I have Excel referenced but can't get much further. Here's a bit of the first HTML section I'm working on:

    Code:
    private void HtmlWriteIntro(StreamWriter sw, string credit)
            {
                string customer = "cust"; 
                string reference = "ref"; 
                DateTime doc_date = DateTime.Now; 
                try
                {
                    string q = @"
                        SELECT     CreditNumber, Customer, DocumentNumber, AdditionDate
                        FROM         viewCmCreditReportSrcAll
                        WHERE     (CreditNumber = @credit)";
                    List<string> vp = new List<string>();
                    vp.Add("credit");
                    List<string> vv = new List<string>();
                    vv.Add(credit);
                    DataTable dt = ExecuteQuery("MobileScan", q, vp, vv);
                    customer = dt.Rows[0].ItemArray[1].ToString();
                    reference = dt.Rows[0].ItemArray[2].ToString();
                    doc_date = DateTime.Parse(dt.Rows[0].ItemArray[3].ToString());
                }
                catch { }
                sw.WriteLine("<table border=\"0\" style=\"font-family:Verdana; font-size:x-small;\" width=\"100%\">");
                sw.WriteLine("<tr>");
                sw.WriteLine("<td align=\"left\"><span style=\"font-size:large\"><b>Credit Comparison Report</b></span></td>");
                sw.WriteLine("<td align=\"right\"><span style=\"font-size:x-small\"><b>Print Date:</b> " + DateTime.Now.ToLongDateString() + "</span></td>");
                sw.WriteLine("</tr>");
                sw.WriteLine("<tr>");
                sw.WriteLine("<td align=\"left\"><span style=\"font-size:medium\"><b>Credit Number " + credit + "</b></span></td>");
                sw.WriteLine("<td align=\"right\">&nbsp;</td>");
                sw.WriteLine("</tr>");
                sw.WriteLine("<tr>");
                sw.WriteLine("<td align=\"left\"><b>Document Date:</b> " + doc_date.ToShortDateString() + "</td>");
                sw.WriteLine("<td align=\"right\">&nbsp;</td>");
                sw.WriteLine("</tr>");
                sw.WriteLine("<tr>");
                sw.WriteLine("<td align=\"left\"><b>Customer:</b> " + customer + "</td>");
                sw.WriteLine("<td align=\"right\">&nbsp;</td>");
                sw.WriteLine("</tr>");
                sw.WriteLine("<tr>");
                sw.WriteLine("<td align=\"left\"><b>Reference #:</b> " + reference + "</td>");
                sw.WriteLine("<td align=\"right\">&nbsp;</td>");
                sw.WriteLine("</tr>");
                sw.WriteLine("<tr>");
                sw.WriteLine("<td align=\"right\" colspan=\"2\"><hr /></td>");
                sw.WriteLine("</tr>");
                sw.WriteLine("</table>");
            }
    Any tips/guidance would be greatly appreciated.

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,997

    Re: Converting HTML export to Excel..

    Why not just select the query in Excel? It can open SQL tables.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Apr 2013
    Posts
    2

    Re: Converting HTML export to Excel..

    Quote Originally Posted by dglienna View Post
    Why not just select the query in Excel? It can open SQL tables.
    Not possible.

    How about creating a button that exports the html doc to excel? Might be a lazy way about it but I need to get this done

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center