Click here to Skip to main content
15,745,306 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have writen a page in ASP that uses

Response.ContentType = "application/vnd.ms-excel"

My problem is I can get it to populate the sheet from my database table and it fills in over 5000 rows fine across 25 columns, however after finishing the loop i need to move to a different cell in the sheet.

So after filling in upto column Y and all the rows I want to move the cursor to cells AC and start another loop to fill in the rows from cell AC2 down to the amount of records in my table in this case 5000.

What is the correct Response.Write syntax to move to the cell so its active to fill in my next loop?

Any help would be very appreciated on this as I have been trying various different things and getting absolutely nowhere :)

Many Thanks
Ray
Posted

Hard to give a full answer without seeing some of the code.

Have you tried ActiveCell.Offset(0,4)?
 
Share this answer
 
Comments
Sandeep Mewara 14-Sep-10 12:45pm    
Well, there is a comment (long one!) as an answer posted. Have a look.
Hi Dalek Dave

Thank you for answering and yes I should included some code...

This is the code: So as mentioned when its finished running through filling in all the columns and rows I want to then leave 3 columns blank and start filling 3 columns from row 2 down, this is to auto fill the equations in the cells. i tried adding it to the inner loop but it bombs out when it hits the end of the recordset so i need to know how to add the relevant code to start writting in the cells again from where I decide the active cell should be.

<!--#include virtual="/Connections/Asda.asp" -->
<%

Response.ContentType = "application/vnd.ms-excel"
Dim Confirm_data
Dim Confirm_data_cmd
Dim Confirm_data_numRows
Set Confirm_data_cmd = Server.CreateObject ("ADODB.Command")
Confirm_data_cmd.ActiveConnection = MM_Asda_STRING
Confirm_data_cmd.CommandText = "SELECT dbo.Tbl_Down_Fleet.Inp_ID,Site_Name,dbo.Tbl_Down_Fleet.Day_No,dbo.Tbl_Down_Fleet.Inp_Date, dbo.Tbl_Down_Fleet.Reach_Total, dbo.Tbl_Down_Fleet.LLOP_Total, dbo.Tbl_Down_Fleet.PPT_Total, dbo.Tbl_Down_Fleet.CB_Total, dbo.Tbl_Down_Fleet.ECB_Total, dbo.Tbl_Down_Fleet.BDU_Total, dbo.Tbl_Down_Fleet.PPPT_Total, dbo.Tbl_Down_Fleet.PPPTBC_Total, dbo.Tbl_Down_Fleet.Dollop_Total, dbo.Tbl_Down_Fleet.Kombi_Total, dbo.Tbl_Down_Fleet.Beast_Total,dbo.Tbl_Down_Fleet.Day_No,dbo.Tbl_Down_Fleet.Inp_Date, dbo.Tbl_Down_Fleet.Reach, dbo.Tbl_Down_Fleet.LLOP, dbo.Tbl_Down_Fleet.PPT, dbo.Tbl_Down_Fleet.CB, dbo.Tbl_Down_Fleet.ECB, dbo.Tbl_Down_Fleet.BDU, dbo.Tbl_Down_Fleet.PPPT, dbo.Tbl_Down_Fleet.PPPTBC, dbo.Tbl_Down_Fleet.Dollop, dbo.Tbl_Down_Fleet.Kombi, dbo.Tbl_Down_Fleet.Beast FROM dbo.Tbl_Down_Fleet, dbo.Tbl_Primary_Fleet WHERE Fleet_ID =Priflt_ID ORDER BY Site_Name ASC"
Confirm_data_cmd.Prepared = true
Confirm_data_cmd.Parameters.Append Confirm_data_cmd.CreateParameter("param1", 5, 1, -1, Confirm_data__MMColParam) ' adDouble
Set RS = Confirm_data_cmd.Execute

%>
<TABLE BORDER=1>
<TR>
<%
' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' % Loop through Fields Names and print out the Field Names
' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
j = 2 'row counter
For i = 0 to 15 - 1
%>
<TD><B><% = RS(i).Name %></B></TD>
<% Next %>
<TD><B><% Response.Write("Total Fleet")%></B></TD>

<%
' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' % Loop again through remaining Headers
' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
For i = 15 to RS.Fields.Count -1
%>
<TD><B><% = RS(i).Name %></B></TD>
<% Next %>
<TD><B><% Response.Write("Sum")%></B></TD>
<TD><B><% Response.Write("Reach")%></B></TD>
<TD><B><% Response.Write("LLOP")%></B></TD>
<TD><B><% Response.Write("PPT")%></B></TD>
<TD><B><% Response.Write("CB")%></B></TD>
<TD><B><% Response.Write("ECB")%></B></TD>
<TD><B><% Response.Write("BDU")%></B></TD>
<TD><B><% Response.Write("PPPT")%></B></TD>
<TD><B><% Response.Write("PPPTBC")%></B></TD>
<TD><B><% Response.Write("Dollop")%></B></TD>
<TD><B><% Response.Write("Kombi")%></B></TD>
<TD><B><% Response.Write("Beast")%></B></TD>
<TD><B><% Response.Write("dfleet")%></B></TD>


</TR>
<%
' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' % Loop through rows, create first set of Fleet Totals
' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Do While Not RS.EOF
%>
<TR>
<% For i = 0 to 15 - 1 %>
<TD VALIGN=TOP><% = RS(i) %></TD>

<% Next %>
<TD VALIGN=TOP><% Response.Write("=SUM(E"&(j)&":O"&(j)&")") %></TD>

<%
' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' % Loop through rows, create second set of Fleet Down Totals
' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%>

<% For i = 15 to RS.Fields.Count -1 %>
<TD VALIGN=TOP><% = RS(i) %></TD>

<% Next %>
<TD VALIGN=TOP><% Response.Write("=SUM(S"&(j)&":AC"&(j)&")") %></TD>
<TD VALIGN=TOP><% Response.Write("=(E"&(j)&"-S"&(j)&")/E"&(j)) %></TD>
<TD VALIGN=TOP><% Response.Write("=(F"&(j)&"-T"&(j)&")/F"&(j)) %></TD>
<TD VALIGN=TOP><% Response.Write("=(G"&(j)&"-U"&(j)&")/G"&(j)) %></TD>
<TD VALIGN=TOP><% Response.Write("=(H"&(j)&"-V"&(j)&")/H"&(j)) %></TD>
<TD VALIGN=TOP><% Response.Write("=(I"&(j)&"-W"&(j)&")/I"&(j)) %></TD>
<TD VALIGN=TOP><% Response.Write("=(J"&(j)&"-X"&(j)&")/J"&(j)) %></TD>
<TD VALIGN=TOP><% Response.Write("=(K"&(j)&"-Y"&(j)&")/K"&(j)) %></TD>
<TD VALIGN=TOP><% Response.Write("=(L"&(j)&"-Z"&(j)&")/L"&(j)) %></TD>
<TD VALIGN=TOP><% Response.Write("=(M"&(j)&"-AA"&(j)&")/M"&(j)) %></TD>
<TD VALIGN=TOP><% Response.Write("=(N"&(j)&"-AB"&(j)&")/N"&(j)) %></TD>
<TD VALIGN=TOP><% Response.Write("=(O"&(j)&"-AC"&(j)&")/O"&(j)) %></TD>
<TD VALIGN=TOP><% Response.Write("=(P"&(j)&"-AD"&(j)&")/P"&(j)) %></TD>



</TR>
<%
RS.MoveNext
j = j + 1
Loop


' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' % Make sure to close the Result Set and the Connection object
' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
RS.Close

%>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900