Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Old 10-22-2009, 12:44 PM   PM User | #1
emzipoo4u
New to the CF scene

 
Join Date: Oct 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
emzipoo4u is an unknown quantity at this point
ASP to Excel

Hi,

I have a table in an MSSQL database with the following layout

partnumber group description barcode date

I want a report to export the data into excel by date, but, I need each seperate product group on a seperate tab in excel.

I have the following code but its not working!

Any ideas?

Code:
<%
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment;filename=file01.xls"
%>
<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
<DownloadComponents/>
<LocationOfComponents HRef="file:///\\"/>
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<WindowHeight>12525</WindowHeight>
<WindowWidth>15195</WindowWidth>
<WindowTopX>480</WindowTopX>
<WindowTopY>120</WindowTopY>
<ActiveSheet>2</ActiveSheet>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom"/>
<Borders/>
<Font/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
</Styles>

<% 
		'NOW CONNECTS TO DISPLAY DATA FROM TABLE VINDEX
Dim adoCon             
Dim SQL
Dim Recordset2
Dim oddsevens

Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "Provider=SQLOLEDB; Data Source=\SQLEXPRESS; Initial Catalog=; User ID=; Password="

SQLSTRING = "SELECT Partdevelopment.*, Supplierprice.*, Supplierprice.primesupplier FROM Partdevelopment LEFT OUTER JOIN Supplierprice ON Partdevelopment.partnumber = Supplierprice.partnumber WHERE (Supplierprice.primesupplier = N'Yes') ORDER BY productgroup, Partnumber"

SQL= (sqlstring)

Set recordset2 = adoCon.Execute(SQL)

If recordset2.eof then
	no_rows = True
          End If
		  
If no_rows Then

Else    

groupx = 0
  
do while not recordset2.eof 

if groupx <> recordset2.fields("productgroup") then%>
<Worksheet ss:Name="1">
<Table ss:ExpandedColumnCount="1" ss:ExpandedRowCount="1" x:FullColumns="1" x:FullRows="1">
<% End If %>

<Row>
<Cell><Data ss:Type="Text">1</Data></Cell>
</Row>

<Row>
<Cell><Data ss:Type="Text">2</Data></Cell>
</Row>

<%if groupx <> recordset2.fields("productgroup") then%>
</Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
<% end if %>

<% groupx = recordset2.fields("productgroup") 

response.flush
recordset2.MoveNext
Loop
End If%>

<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<Selected/>
<Panes>
<Pane>
<Number>3</Number>
<ActiveRow>1</ActiveRow>
</Pane>
</Panes>
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
</Workbook>
<%adoCon.close
Set AdoCon = nothing
Set Recordset2 = nothing%>
emzipoo4u is offline   Reply With Quote
Old 11-06-2009, 06:40 PM   PM User | #2
SouthwaterDave
Regular Coder

 
Join Date: May 2007
Location: UK
Posts: 166
Thanks: 0
Thanked 18 Times in 18 Posts
SouthwaterDave is on a distinguished road
I think your connection string is wrong. It should be .\sqlexpress or machineName\sqlexpress.
SouthwaterDave is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:46 AM.

Home - Contact Us - Archives - Link to CF - Resources - Top 

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.