Error in Excel downloading

Bellow code is Progress bar its open properly but after fill dataset then open excel downloading popup that time this error occurred: Server cannot append header after HTTP headers have been sent .
Please give me solution.
Private Sub JavaScriptFunc()
Response.Write("<div id='mydiv' STYLE='FONT-WEIGHT: bold; FONT-SIZE: 11pt; LEFT: 320px; COLOR: blue; FONT-FAMILY: Verdana; POSITION: absolute; TOP: 140px; TEXT-ALIGN: center() ' >")
Response.Write(" ")
Response.Write("</div>")
Response.Write("<script> var mydiv = document.getElementById('mydiv'); mydiv.innerText = '';</script>")
Response.Write("<script language=javascript>")
Response.Write("var dots = 0;var dotmax = 10;function ShowWait()")
Response.Write("{var output; output = 'Generating Report. Please wait() ';dots++;if(dots>=dotmax)dots=1;")
Response.Write("for(var x = 0;x < dots;x++){output += '.';}mydiv.innerText = output;}")
Response.Write("function StartShowWait(){mydiv.style.visibility = 'visible';ShowWait();ShowWait();window.setInterval('ShowWait()',2);}")
Response.Write("StartShowWait();</script>")
Response.Flush()
End Sub
[1372 byte] By [tirthpatel] at [2007-11-20 10:47:15]