Solved

writing into excel

Posted on 2004-09-14
6
184 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn how to count occurrences of each item in an array.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

820 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