Solved

writing into excel

Posted on 2004-09-14
6
179 Views
Last Modified: 2010-04-06
I am trying to write into excel  bu  i  doesnt  sem to work
my excel is blank

 here  is code


<%
Response.ContentType = "application/vnd.ms-excel"
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- #Include File = "Include/Settings.asp" -->
<!-- #Include File = "Include/Public.asp" -->


<table border="1" bordercolor="#000000">
      <thead>
      
            <tr>
                  <th bgcolor="black"><font color="white">Date</font></th>
                  <th bgcolor="black"><font color="white">No of Pure Card calls</font></th>
                  <th bgcolor="black"><font color="white">No of Pure Bank calls</font></th>
                  <th bgcolor="black"><font color="white">No of Hybrid calls</font></th>
                                    
      
      </tr>
      </thead>

<tbody>

<%
Dim cnnDB
      Dim I, intPureCard, intPureBank, intHybrid
      Dim mis_Date
      Dim strSQL, strHTML
      Dim rstR
      
            
            
      
      
      ' Setup connection to database

      Set cnnDB = CreateConnection
      
      strSQL = "SELECT tblMIS.* FROM tblMIS"
                                                
      
      Set rstR = Server.CreateObject("ADODB.Recordset")
      rstR.CursorLocation=adUseClient
      rstR.Open strSQL, cnnDB, adOpenStatic, adLockReadOnly, adCmdText
      
      If rstR.BOF And rstR.EOF Then
      
            ' No records returned
      intPureCard = 0
      intPureBank = 0
      intHybrid = 0

            
      Else
      
            While Not rstR.EOF
            
            mis_Date = rstR.Fields("MISDate")
            intPureCard = rstR.Fields("PureCard")
            intPureBank = rstR.Fields("PureBank")
            intHybrid= rstR.Fields("Hybrid")
            %>
            <tr bordercolor="#000000">
                  <td bordercolor="#000000"><%= mis_Date %></td>
                  <td bordercolor="#000000"><%= intPureCard %></td>
                  <td bordercolor="#000000"><% = intPureBank %></td>
                  <td bordercolor="#000000"><%= intHybrid %></td>
                  
</tr>
            <%
          
            rstR.MoveNext
 
            WEnd
            
      
      End If
      
      rstR.Close
      Set rstR = Nothing
      
cnnDB.Close
Set cnnDB = Nothing
      %>
      </tbody>
</table>
0
Comment
Question by:mudugose
  • 3
  • 3
6 Comments
 
LVL 11

Expert Comment

by:sciber_dude
ID: 12059070
You will have to work with me on this to identify the bug.

Try this first.

<%
 ' Response.ContentType = "application/vnd.ms-excel"  ' <<<<<<<<<<< Comment this line out
%>

and tell if you see the output on the ASP page.

:) SD
0
 
LVL 11

Expert Comment

by:sciber_dude
ID: 12059208
Any feedback about my earlier post? It looks like there is a problem in this line...

    ' Setup connection to database
     Set cnnDB = CreateConnection     ' <<<<<<<<<<<<<<<<<


Try this code. Edit where indicated.
:) SD

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

<%
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment;filename=MyExcelFile.xls"
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- #Include File = "Include/Settings.asp" -->
<!-- #Include File = "Include/Public.asp" -->

<%
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' XML parameters to open an Excel file
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Dim u_title
u_title = "My Excel File"
Response.Write "<html xmlns:x=""urn:schemas-microsoft-com:office:excel"">" & VbCrLf
Response.Write "<head>" & VbCrLf
Response.Write "<!--[if gte mso 9]><xml>" & VbCrLf
Response.Write "<x:ExcelWorkbook>" & VbCrLf
Response.Write "<x:ExcelWorksheets>" & VbCrLf
Response.Write "<x:ExcelWorksheet>" & VbCrLf
Response.Write "<x:Name>"& u_title &"</x:Name>" & VbCrLf
Response.Write "<x:WorksheetOptions>" & VbCrLf
Response.Write "<x:Print>" & VbCrLf
Response.Write "<x:ValidPrinterInfo/>" & VbCrLf
Response.Write "</x:Print>" & VbCrLf
Response.Write "</x:WorksheetOptions>" & VbCrLf
Response.Write "</x:ExcelWorksheet>" & VbCrLf
Response.Write "</x:ExcelWorksheets>" & VbCrLf
Response.Write "</x:ExcelWorkbook>" & VbCrLf
Response.Write "</xml>" & VbCrLf
Response.Write "<![endif]--> " & VbCrLf
Response.Write "</head>" & VbCrLf
Response.Write "<body>" & VbCrLf
%>

<table border="1" bordercolor="#000000">
     <tr>
               <th bgcolor="black"><font color="white">Date</font></th>
               <th bgcolor="black"><font color="white">No of Pure Card calls</font></th>
               <th bgcolor="black"><font color="white">No of Pure Bank calls</font></th>
               <th bgcolor="black"><font color="white">No of Hybrid calls</font></th>
     </tr>

<%
Dim cnnDB
     Dim I, intPureCard, intPureBank, intHybrid
     Dim mis_Date
     Dim strSQL, strHTML
     Dim rstR

    ' Setup connection to database
     Dim strDataPath, strConnectString

     strDataPath = server.MapPath("Insert_database_Path_HERE.mdb")                     ' <<<<< edit this line

     strConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;"_
               & " Data Source= " & strDataPath & ";"_
               & " Mode=Share Deny None;User Id=Admin;PASSWORD=;"

     if not IsObject("cnnDB") then
          set cnnDB=Server.CreateObject("ADODB.Connection")
          if cnnDB.state = 0 then
               cnnDB.Open strConnectString
          end if
     end if
     
     strSQL = "SELECT tblMIS.* FROM tblMIS"
     
     Set rstR = Server.CreateObject("ADODB.Recordset")
     rstR.CursorLocation=adUseClient
     rstR.Open strSQL, cnnDB, adOpenStatic, adLockReadOnly, adCmdText
     
     If rstR.BOF And rstR.EOF Then
          ' No records returned
          intPureCard = 0
          intPureBank = 0
          intHybrid = 0
          %>
          <tr bordercolor="#000000">
               <td bordercolor="#000000"><%= mis_Date %></td>
               <td bordercolor="#000000"><%= intPureCard %></td>
               <td bordercolor="#000000"><% = intPureBank %></td>
               <td bordercolor="#000000"><%= intHybrid %></td>      
         </tr>
          <%
     Else
          While Not rstR.EOF
         
                    mis_Date = rstR.Fields("MISDate")
                    intPureCard = rstR.Fields("PureCard")
                    intPureBank = rstR.Fields("PureBank")
                    intHybrid= rstR.Fields("Hybrid")
                    %>
                    <tr bordercolor="#000000">
                         <td bordercolor="#000000"><%= mis_Date %></td>
                         <td bordercolor="#000000"><%= intPureCard %></td>
                         <td bordercolor="#000000"><% = intPureBank %></td>
                         <td bordercolor="#000000"><%= intHybrid %></td>      
                   </tr>
                    <%
                    rstR.MoveNext
          WEnd
     End If
     
     rstR.Close
     Set rstR = Nothing
     
cnnDB.Close
Set cnnDB = Nothing
     %>
</table>
</body>
</html>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0
 

Author Comment

by:mudugose
ID: 12061630
no luck, I still get an empty excel file.

when i comment  the  excel line, i can see the  html table
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 11

Accepted Solution

by:
sciber_dude earned 30 total points
ID: 12065895
> when i comment  the  excel line, i can see the  html table

HTML Table: Does it look like the output you want? Does it have the data?

Do you have excel loaded on your machine? Did you try to test it on other machines?

Also, try deleting all history, files and cookies and try again.

Did you try the code i gave you with the XML code in it?

:) SD
0
 

Author Comment

by:mudugose
ID: 12073218
I tried  everything....... still no luck :(
0
 

Author Comment

by:mudugose
ID: 12095443
thanks anyway
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to dynamically set the form action using jQuery.

744 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

11 Experts available now in Live!

Get 1:1 Help Now