<%
Set msg = Server.CreateObject("JMail.Message")
msg.silent = true
msg.Logging = true
msg.Charset = "gb2312"
msg.MailServerUserName = "*****@126.com" ''ÊäÈësmtp·þÎñÆ÷ÑéÖ¤µÇ½Ãû £¨ÓʾÖÖÐÈκÎÒ»¸öÓû§µÄEmailµØÖ·£©
msg.MailServerPassword = "*****" ''ÊäÈësmtp·þÎñÆ÷ÑéÖ¤ÃÜÂë £¨Óû§EmailÕʺŶÔÓ¦µÄÃÜÂ룩
msg.From ="*****@126.com"' Request.Form("email") ''·¢¼þÈËEmail
msg.FromName = "С»Ò"'Request.Form("name") ''·¢¼þÈËÐÕÃû
msg.AddRecipient "*****@163.com" ''ÊÕ¼þÈËEmail
msg.Subject = "ÐżþÖ÷Ìâ"'Request.Form("subject") ''ÐżþÖ÷Ìâ
msg.Body = "ÕýÎÄ"'Request.Form("body") ''ÕýÎÄ
'msg.addattachment(server.mappath("new.txt"))
msg.Send ("smtp.126.com") ''smtp·þÎñÆ÷µØÖ·£¨ÆóÒµÓʾֵØÖ·£©
set msg = nothing
response.write("·¢Ëͳɹ¦£¡")
%>Top
<%
Set msg = Server.CreateObject("JMail.Message")
msg.silent = true
msg.Logging = true
msg.Charset = "gb2312"
msg.MailServerUserName = "*****@126.com" ''輸入smtp服務(wù)器驗(yàn)證登陸名 (郵局中任何一個(gè)用戶的Email地址)
msg.MailServerPassword = "*****" ''輸入smtp服務(wù)器驗(yàn)證密碼 (用戶Email賬號(hào)對(duì)應(yīng)的密碼)
msg.From ="*****@126.com"' Request.Form("email") ''發(fā)件人Email
msg.FromName = "小灰"'Request.Form("name") ''發(fā)件人姓名
msg.AddRecipient "*****@163.com" ''收件人Email
msg.Subject = "信件主題"'Request.Form("subject") ''信件主題
msg.Body = "正文"'Request.Form("body") ''正文
'msg.addattachment(server.mappath("new.txt"))
msg.Send ("smtp.126.com") ''smtp服務(wù)器地址(企業(yè)郵局地址)
set msg = nothing
response.write("發(fā)送成功!")
%>Top
'本地提交
Function isLocalPost()
server1 = CStr(request.servervariables("http_referer"))
server2 = CStr(request.servervariables("server_name"))
isLocalPost = true
If Mid(server1, 8, Len(server2))<>server2 Then
isLocalPost = false
End If
End Function
'訪問(wèn)者IP
Function ip()
ip = request.servervariables("http_x_forwarded_for")
If ip = "" Then
ip = request.servervariables("remote_addr")
End If
End FunctionTop
excel導(dǎo)入導(dǎo)出:
1
excel導(dǎo)放到數(shù)據(jù)庫(kù)
select * into SQL中的表 from OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="e:\excel\tt.xls";User ID=Admin;Password=;Extended properties=Excel 5.0')...[Sheet1$]
二:數(shù)據(jù)庫(kù)導(dǎo)入到excel
EXEC master..xp_cmdshell 'bcp 庫(kù)名.dbo.表名 out f:\1.xls -c -q -t, -S"服務(wù)器名" -U"用戶名" -P"密碼"'
三,插入記錄到已有的excel中
1\如何從第十一行開(kāi)始追加記錄?
2\是否可以采用EXCEL的默認(rèn)列,如"A:B:C:D"等來(lái)代替列名?
--1.你可以在Excel表的第10行隨便填一個(gè)數(shù)據(jù),保證Excel表中,第10行至少有一個(gè)數(shù)據(jù),10行之后沒(méi)有數(shù)據(jù),這樣你可以用類(lèi)似下面的語(yǔ)句插入數(shù)據(jù)到Excel表中,可以保證數(shù)據(jù)插入在11行開(kāi)始追加
insert into OPENROWSET('MICROSOFT.JET.OLEDB.4.0'
,'Excel 5.0;HDR=NO;DATABASE=c:\test.xls',Sheet1$)(F1,F2)
select * from 表
--2.如果你的列中是有數(shù)據(jù)的,可以用F1~Fn來(lái)代替列名
EG:insert into OPENROWSET('MICROSOFT.JET.OLEDB.4.0'
,'Excel 5.0;HDR=NO;DATABASE=f:\book1.xls',Sheet1$)(f1,f2,f3,f4,f5,f6,f7)
select manage_id,manage_name,manage_password,manage_rank,manage_regtime,manage_frontip,manage_fronttime from manage
四:插入到excel
insert into OpenDataSource(
'Microsoft.Jet.OLEDB.4.0','Data Source="f:book1.xls";User ID=Admin;Password=;Extended properties=Excel 5.0')
...[sheet1$](Code,name) VALUES ('20', 'Test')
下面的是用一個(gè)標(biāo)準(zhǔn)的文本文件的內(nèi)容創(chuàng)建一個(gè)數(shù)據(jù)表
***********鄒建(access數(shù)據(jù)庫(kù))**********************************************************************************************
--如果你要在sql中指定字段分隔符,則要寫(xiě)格式文件,無(wú)法在openrowset中指定字段分隔符
導(dǎo)入文本文件時(shí)如何指定字段類(lèi)型?
===========================================================================
問(wèn)題:
我有一個(gè)文本文件需要導(dǎo)入 Access ,但是文本文件中有一列數(shù)據(jù)原本是文本,
但是導(dǎo)入數(shù)據(jù)庫(kù)后自動(dòng)變成了“雙精度”類(lèi)型,我該如何讓各個(gè)字段按我需要的
數(shù)據(jù)類(lèi)型生成哪?
如何讓 ACCESS 按照我規(guī)定的構(gòu)架、規(guī)格從文本文件、XLS文檔中導(dǎo)入數(shù)據(jù)?
==========================================================================
方法:
用 Schema.ini 文件
作用:Schema.ini用于提供文本文件中記錄的構(gòu)架信息。
每個(gè) Schema.ini 項(xiàng)都用于指定表的五個(gè)特征之一:
1、文本文件名
2、文件格式
3、字段名、字段長(zhǎng)度、字段類(lèi)型
4、字符集
5、特別數(shù)據(jù)類(lèi)型轉(zhuǎn)換
======================================================================
指定文件名
文件名要用方括號(hào)括起來(lái),例如如果要對(duì) Sample.txt 使用數(shù)據(jù)構(gòu)架信息文件,
那么它的對(duì)應(yīng)的項(xiàng)應(yīng)該是
[Sample.txt]
=======================================================================
指定文件格式
格式說(shuō)明 表格式 Schema.ini 格式描述
Tab 制表符分隔 文件中的字段用制表符分隔 Format=TabDelimited
CSV 分隔 文件中的字段用逗號(hào)來(lái)分隔 Format=CSVDelimited
自定義分隔 文件中的字段可以用任何字符 Format=Delimited(自定義分隔符)
來(lái)分隔,所有的字符都可以
用來(lái)分隔,包括空格,但是
雙引號(hào) ( " ) 除外
- 或者沒(méi)有分隔符 - Format=Delimited( )
固定寬度 文件中的字段為固定長(zhǎng)度
===============================================================
指定字段
你可以有兩種方法在一個(gè)字符分隔的文本文件中指定字段名
1、在文本文件中的第一行包含字段名,并且設(shè)置 ColNameHeader 為 True 。
2、用數(shù)字編號(hào)指定每一列并且指定每一列的名字以及數(shù)據(jù)類(lèi)型
你必須用數(shù)字編號(hào)指定每一列并且指定每一列的名字、數(shù)據(jù)類(lèi)型以及長(zhǎng)度
(在固定長(zhǎng)度分隔的文本文件中需要指定長(zhǎng)度)
注意,設(shè)定了 ColNameHeader 選項(xiàng),在 Schema.ini 中 Windows 注冊(cè)時(shí)會(huì)忽略
FirstRowHasNames 選項(xiàng)。
你也可以指定字段的數(shù)據(jù)類(lèi)型,使用 MaxScanRows 選項(xiàng)用來(lái)指定在確定列的
數(shù)據(jù)類(lèi)型時(shí)要掃描多少行數(shù)據(jù)。設(shè)置 MaxScanRows 為 0 將掃描整個(gè)文件。
如果文本文件第一行包含字段名,并且要掃描整個(gè)文件,改項(xiàng)目就要定義如下:
ColNameHeader=True
MaxScanRows=0
接下來(lái)的項(xiàng)目用來(lái)指定表中的字段,使用列編號(hào)(Coln)選項(xiàng)來(lái)指定列。字段長(zhǎng)度在
“固定分隔文本文件中”是必填項(xiàng)目,在“字符分隔文本文件”中是可選項(xiàng)目。
示例:定義 2 個(gè)字段,CustomerNumber 是長(zhǎng)度為 10 的文本字段、
CustomerName 是長(zhǎng)度為 30 的文本字段。
Col1=CustomerNumber Text Width 10
Col2=CustomerName Text Width 30
語(yǔ)法如下:
Coln=ColumnName type [Width #]
參數(shù)解釋如下:
參數(shù) 說(shuō)明
ColumnName 文本,標(biāo)識(shí)字段名,如果包含空格要用雙引號(hào)括起來(lái)
type 數(shù)據(jù)類(lèi)型包括:
Microsoft Jet 數(shù)據(jù)類(lèi)型:Bit Byte Short Long Currency Single Double DateTime Text Memo
ODBC 數(shù)據(jù)類(lèi)型: Char (same as Text) Float (same as Double) Integer (same as Short)
LongChar (same as Memo) Date date format
其中date format 是日期的格式字符串例如:Date YYYY-MM-DD
Width 字符串的長(zhǎng)度,后面的數(shù)字用來(lái)指定字段的長(zhǎng)度(“固定分隔文本文件”為必填,
“文字分隔文本文件”為可選)
# 整形數(shù)字,標(biāo)識(shí)字段長(zhǎng)度
===================================================================
指定字符集
CharacterSet 項(xiàng)有兩個(gè)選擇:ANSI | OEM
選擇 ANSI 字符集用如下方法:
CharacterSet=ANSI
====================================================================
特別數(shù)據(jù)類(lèi)型轉(zhuǎn)換
特別數(shù)據(jù)類(lèi)型轉(zhuǎn)換主要是定義比如日期、貨幣型數(shù)據(jù)如何轉(zhuǎn)換或者如何顯示的,
你可以參考下面這張表:
選項(xiàng) 說(shuō)明
DateTimeFormat
Can be set to a format string indicating dates and times. You should specify this entry if all date/time fields in the import/export are handled with the same format. All Microsoft Jet formats except A.M. and P.M. are supported. In the absence of a format string, the Windows Control Panel short date picture and time options are used.
DecimalSymbol
Can be set to any single character that is used to separate the integer from the fractional part of a number.
NumberDigits
Indicates the number of decimal digits in the fractional portion of a number.
NumberLeadingZeros
Specifies whether a decimal value less than 1 and greater than -1 should contain leading zeros; this value can either be False (no leading zeros) or True.
CurrencySymbol
Indicates the currency symbol to be used for currency values in the text file. Examples include the dollar sign ($) and Dm.
CurrencyPosFormat
Can be set to any of the following values:
· Currency symbol prefix with no separation ($1)
· Currency symbol suffix with no separation (1$)
· Currency symbol prefix with one character separation ($ 1)
· Currency symbol suffix with one character separation (1 $)
CurrencyDigits
Specifies the number of digits used for the fractional part of a currency amount.
CurrencyNegFormat
Can be one of the following values:
· ($1)
· -$1
· $-1
· $1-
· (1$)
· -1$
· 1-$
· 1$-
· -1 $
· -$ 1
· 1 $-
· $ 1-
· $ -1
· 1- $
· ($ 1)
· (1 $)
This example shows the dollar sign, but you should replace it with the appropriate CurrencySymbol value in the actual program.
CurrencyThousandSymbol
Indicates the single-character symbol to be used for separating currency values in the text file by thousands.
CurrencyDecimalSymbol
Can be set to any single character that is used to separate the whole from the fractional part of a currency amount.
====================================================================
下面給出一個(gè)簡(jiǎn)單的例子,假設(shè)有一個(gè)表Contacts.txt類(lèi)似下面:
姓名 單位 聯(lián)系日期
王海 上海有機(jī)化學(xué)研究所 2002-1-1
羅炙 數(shù)字化機(jī)床研究院 2004-1-1
導(dǎo)入 Access 應(yīng)該類(lèi)似下面表格:
姓名 單位 聯(lián)系日期
王海 上海有機(jī)化學(xué)研究所 2002-1-1
羅炙 數(shù)字化機(jī)床研究院 2004-1-1
那么 Schema.ini 則是類(lèi)似下面的INI文件:
[Contacts.txt]
ColNameHeader=True
format=Delimited( )‘此處表示為用空格作分界符,如果是用分號(hào)的話則為:format=Delimited(;)
MaxScanRows=0
CharacterSet=ANSI
Col1="姓名" Char Width 10
Col2="單位" Char Width 9
Col3="聯(lián)系日期" Date Width 8
注釋如下:
[Contacts.txt] ///文本文件名
ColNameHeader=True ///帶有表頭
format=Delimited( ) ///空格作為分隔符,如果是分號(hào),請(qǐng)用format=Delimited(;) 來(lái)解決
MaxScanRows=0 ///掃描整個(gè)文件
CharacterSet=ANSI ///ANSI 字符集
Col1="姓名" Char Width 10 ///字段1
Col2="單位" Char Width 9 ///字段2
Col3="聯(lián)系日期" Date Width 8 ///字段3
///如果有更多字段可 Col4 .... ColN
注意,Schema.ini 必須和需要導(dǎo)入的文本文件在同一目錄。
此后,我們就可以利用下面的語(yǔ)句來(lái)導(dǎo)入數(shù)據(jù)了:
CurrentProject.Connection.Execute "SELECT * INTO NewContact FROM [Text;FMT=Delimited;HDR=Yes;DATABASE=C:\;].[Contacts#txt];"T
完整示例(有移動(dòng),增加,刪除)
<SCRIPT LANGUAGE="JScript">
function se(se_text,se_value)
{
var oOption = document.createElement("OPTION");
oOption.text=se_text;
oOption.value=se_value;
addselect.add(oOption);
}
function cha(add_text,add_value)
{
var oOption = document.createElement("OPTION");
oOption.text=add_text;
oOption.value=add_value;
addselect.add(oOption);
}
function del(se_index)
{
addselect.remove(se_index);
}
</SCRIPT>
<SELECT ID="oSelect" NAME="Cars" SIZE="13" ondblclick="cha (this.options[this.selectedIndex].text,this.value);">
<OPTION VALUE="1" SELECTED>寶馬
<OPTION VALUE="2">保時(shí)捷
<OPTION VALUE="3" >奔馳
</SELECT>
===>
<select name="addselect" SIZE="13" ondblclick="del(this.selectedIndex);">
</select>
<input name="se1" type="text" value="f" >
<input name="se2" type="text" value="2">
<input type="button" name="Submit" value="增加" onclick="se(se1.value,se2.value);">
call downloadFile(Request("path"))
function downloadFile(strFile)
strFilename = server.MapPath(strFile)
Response.Buffer = True
Response.Clear
Set s = Server.CreateObject("ADODB.Stream")
s.Open
s.Type = 1
on error resume next
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if not fso.FileExists(strFilename) then
Response.Write("<h1>Error:</h1>" & strFilename & " does not exist<p>")
Response.End
end if
Set f = fso.GetFile(strFilename)
intFilelength = f.size
s.LoadFromFile(strFilename)
if err then
Response.Write("<h1>Error: </h1>" & err.Description & "<p>")
Response.End
end if
Response.AddHeader "Content-Disposition", "attachment; filename=" & f.name
Response.AddHeader "Content-Length", intFilelength
Response.CharSet = "UTF-8"
Response.ContentType = "application/octet-stream"
Response.BinaryWrite s.Read
Response.Flush
s.Close
Set s = Nothing
End Function
聯(lián)系客服