ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 23rd, 2004, 04:05 PM
hismightiness hismightiness is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Florida
Posts: 30 hismightiness User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 49 sec
Reputation Power: 6
Formatting Excel Cells from ASP

I have a report which gets generated from ASP and sent to the user in Excel format. Is there a way to format the cells at run-time to not allow Excel to automatically format numbers? In case you want to see my code, here it is:
Code:
<%@ language="vbscript" %>
<%
option explicit
response.expires=0
response.cachecontrol="no-cache"
%>
<!-- #include file="../../../../log_hits.asp" -->
<!-- #include file="../../../../adovbs.inc" -->
<%
'on error resume next

dim conn,strconn
strconn="dsn=livehrdata;database=hr_data;password=REMOVED;"
set conn=server.CreateObject("adodb.connection")
conn.Open strconn

dim rs
set rs=server.CreateObject("adodb.recordset")
rs.Open "2004_employee_recognition_survey",conn,adOpenKeyset,adLockOptimistic,adcmdtable

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

<body>
	<table>
		<tr>
			<td style="border: 1px solid #c0c0c0;"><b>Date</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>Time</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>q1</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>q1comments</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>q2</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>q3</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>q4</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>q5</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>q5comments</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>q6</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>q6comments</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>q7</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>q8</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>q8comments</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>q9</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>q10</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>q10comments</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>q11</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>q11comments</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>q12</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>q12comments</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>q13</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>q13comments</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>q14</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>q15</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>q15comments</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>q16</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>q17</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>q18</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>q19</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>q19comments</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>q20comments</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>location</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>years service</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>position</b></td>
			<td style="border: 1px solid #c0c0c0;"><b>name</b></td>
		</tr>
<%
	dim field,intNumber
	intNumber=cint(0)
	while not rs.EOF
		Response.Write "<tr>"
		for intNumber=0 to rs.Fields.Count -1
			if intNumber=0 then intNumber=intNumber+1
			if intNumber=1 then intNumber=intNumber+1
			if intNumber=2 then intNumber=intNumber+1
			if intNumber=3 then intNumber=intNumber+1
			if intNumber=40 then exit for
			Response.Write "<td style=""border: 1px solid #c0c0c0; vertical-align: top;"">"
			if isnull(rs(intnumber).Value) = false then Response.Write cstr(rs(intNumber).Value) else Response.Write "&nbsp; "
			Response.Write "</td>"
		next
		Response.Write "</tr>"
		rs.MoveNext
	wend
	rs.close
	set rs=nothing
	conn.close
	set conn=nothing
%>
	</table>
</body>

</html>
<!-- #include file="../../../../handle_error.asp" -->
__________________
____________________

Will

Reply With Quote
  #2  
Old January 24th, 2004, 01:43 AM
victorpendleton victorpendleton is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2003
Location: No es importante
Posts: 2,065 victorpendleton User rank is Private First Class (20 - 50 Reputation Level)victorpendleton User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 6 h 50 m 52 sec
Reputation Power: 8
If you were instantiating the Excel model directly you could use something similar to the following:
Code:
ActiveCell.NumberFormat = "@"

This would ensure that the cell is formatted like a text instead of general which is the default.
...
I do not know of way to do it via the ContentType
__________________
El éxito consiste en una serie de pequeñas victorias día a día

MySQL, MS SQL, MS ACCESS, Oracle Database Manager - http://victorpendleton.net/products/psdviewer.html

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Formatting Excel Cells from ASP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT