This repository was archived by the owner on Nov 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport_csv.asp
More file actions
121 lines (112 loc) · 3.58 KB
/
export_csv.asp
File metadata and controls
121 lines (112 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<%@ Language=VBScript %>
<!--#include file=scripts\inc_common.asp -->
<%
if Request.Form("action") = "export" then
On Error Resume Next
dim dba, rec, s, fld
dim DlmColumn, DlmRow, DlmText
if Request.Form("column") = "TAB" then
DlmColumn = vbTab
elseif Request.Form("column") = "SPACE" then
DlmColumn = " "
elseif Request.Form("column") = "OTHER" then
DlmColumn = Request.Form("other")
else
DlmColumn = Request.Form("column")
End if
DlmRow = vbCrLf
DlmText = Request.Form("text")
set dba = new DBAdmin
dba.Connect Session(DBA_cfgSessionDBPathName), Session(DBA_cfgSessionDBPassword)
set rec = dba.RunScript(Request.Form("sql").Item, False, True, null)
Randomize
Response.AddHeader "Content-Disposition", "attachment; filename=" & Int((Rnd() * 10000000)) & "_export.csv"
Response.ContentType = "application/octet-stream"
'Export field names
if Request.Form("nofields") <> "1" then
s = ""
for each fld in rec.Fields
s = s & fld.Name & DlmColumn
next
if Len(s) > 0 then s = Left(s, Len(s)-1) & DlmRow
Response.Write s
end if
do while not rec.EOF
s = ""
for each fld in rec.Fields
Select Case fld.Type
Case adBSTR,adChar,adLongVarChar,adLongVarWChar,adVarChar,adVarWChar,adWChar
s = s & DlmText
if not IsNull(fld.Value) and Len(fld.Value) > 0 then s = s & Replace(fld.Value, DlmText, DlmText & DlmText)
s = s & DlmText & DlmColumn
Case adBinary, adLongVarBinary, adVarBinary
s = s & DlmColumn
Case Else
s = s & fld.Value & DlmColumn
End Select
next
if Len(s) > 0 then s = Left(s, Len(s)-1) & DlmRow
Response.Write s
Response.Flush
rec.MoveNext
loop
Response.Write DlmRow
rec.Close
set rec = nothing
set dba = Nothing
%>
<%else%>
<!doctype html public "-//w3c//dtd html 4.01 transitional//en">
<html>
<head>
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<meta name="GENERATOR" content="Microsoft Visual Studio 6.0">
<link href="default.css" rel="stylesheet" type="text/css">
<title>DBA:<%=langCaptionExportCSV%></title>
<script type="text/javascript" language="javascript" src="scripts/common.js" defer></script>
</head>
<body>
<%
call DBA_WriteNavigation
DBA_BeginNewTable langExcelExportAlt, "", "90%", ""
%>
<p align="center"><%=langPleaseDefineExp%></p>
<form action="export_csv.asp" method="POST">
<input type="hidden" name="sql" value="<%=Replace(Request.QueryString("sql").Item, """", """)%>">
<input type="hidden" name="action" value="export">
<table align="center" cellspacing="1" cellpadding="1">
<tr>
<td><%=langColumnDelimiter%></td>
<td>
<select name="column">
<option value="TAB">{<%=langTab%>}</option>
<option value="SPACE">{<%=langSpace%>}</option>
<option value=";">;</option>
<option value=",">,</option>
<option value="OTHER">{<%=langOther%>} --></option>
</select> <input type="text" name="other" size="2" maxlength="1">
</td>
</tr>
<tr>
<td><%=langTextQualifier%></td>
<td>
<select name="text">
<option value='"'>"</option>
<option value="'">'</option>
<option value="">{None}</option>
</select>
</td>
</tr>
<tr>
<td colspan="2"><input type="checkbox" name="nofields" value="1"> <%=langNoFieldNames%></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submit" value="Export" class="button"></td>
</tr>
</table>
</form>
<% call DBA_EndNewTable%>
<!--#include file=scripts\inc_footer.inc -->
</body>
</html>
<%end if%>