Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

writing into excel

Posted on 2004-09-14
6
Medium Priority
?
188 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 11

Accepted Solution

by:
sciber_dude earned 90 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

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.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…
Suggested Courses

916 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