[代码]ASP导出EXCEL代码

mikel阅读(1056)

1.需要先本地配置dcomcnfg中的dcom组件execl应用程序权限对everyone开放

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<%
Set xlApplication = Server.Cr&#101;ateObject("Excel.Application") &#39;调用excel对象
xlApplication.Visible = False &#39;无需打开excel
xlApplication.SheetsInNewWorkbook=1 &#39;指定excel中表的数量
xlApplication.Workbooks.Add &#39;添加工作簿
Set xlWorksheet = xlApplication.Worksheets(1)  &#39;生成第1个工作表的子对象
xlWorksheet.name="周报表" &#39;指定工作表名称
&#39;指定列的宽度以及对齐方式
xlApplication.ActiveSheet.Columns(1).ColumnWidth=15
xlApplication.ActiveSheet.Columns(1).HorizontalAlignment=3
xlApplication.ActiveSheet.Columns(2).ColumnWidth=20
xlApplication.ActiveSheet.Columns(2).HorizontalAlignment=3
xlApplication.ActiveSheet.Columns(3).ColumnWidth=25
xlApplication.ActiveSheet.Columns(3).HorizontalAlignment=3
xlApplication.ActiveSheet.Columns(4).ColumnWidth=20
xlApplication.ActiveSheet.Columns(4).HorizontalAlignment=3
xlApplication.ActiveSheet.Columns(5).ColumnWidth=15
xlApplication.ActiveSheet.Columns(5).HorizontalAlignment=3
xlApplication.ActiveSheet.Columns(6).ColumnWidth=25
xlApplication.ActiveSheet.Columns(6).HorizontalAlignment=3
xlApplication.ActiveSheet.Columns(7).ColumnWidth=45
xlApplication.ActiveSheet.Columns(7).HorizontalAlignment=3
xlApplication.ActiveSheet.Columns(8).ColumnWidth=20
xlApplication.ActiveSheet.Columns(8).HorizontalAlignment=3
&#39;指定列的高度以及特定列
xlApplication.ActiveSheet.Rows.RowHeight = 20
xlApplication.ActiveSheet.Rows(5).RowHeight = 35
xlApplication.ActiveSheet.Columns("A:H").VerticalAlignment=2
xlWorksheet.Range(xlWorksheet.Cells(2,1), xlWorksheet.Cells(2,8)).MergeCells =True &#39;合并列
xlWorksheet.Range("A2").value="出入境动植物及其产品疫情和有害有毒物质信息统计周报表"
xlWorksheet.Range("A2").font.Size=14
xlWorksheet.Range("A2").font.bold=true
xlWorksheet.Range(xlWorksheet.Cells(4,1), xlWorksheet.Cells(4,3)).MergeCells =True
xlWorksheet.Range(xlWorksheet.Cells(4,6), xlWorksheet.Cells(4,8)).MergeCells =True
xlWorksheet.Range("A4").HorizontalAlignment=1
xlWorksheet.Range("A4").VerticalAlignment=2
xlWorksheet.Range("F4").HorizontalAlignment=1
xlWorksheet.Range("F4").VerticalAlignment=2
xlWorksheet.Range("A4").value="填报单位:"
xlWorksheet.Range("F4").value="统计时间: "&year(request("begintime"))&"年 "&month(request("begintime"))&"月 "&day(request("begintime"))&"日  至 "&year(request("endtime"))&"年 "&month(request("endtime"))&"月 "&day(request("endtime"))&"日 "
xlWorksheet.Cells(5,1).value = "截获口岸"
xlWorksheet.Cells(5,2).value = "进出口"
xlWorksheet.Cells(5,3).value = "品  名"
xlWorksheet.Cells(5,4).value = "数/单位"
xlWorksheet.Cells(5,5).value = "批次"
xlWorksheet.Cells(5,6).value = "来源国(产地)"
xlWorksheet.Cells(5,7).value = "检疫情况"
xlWorksheet.Cells(5,8).value = "处理情况"
xlWorksheet.Range("A5:H8").Borders.Linestyle=1
&#39;xlApplication.ActiveSheet.Rows(i).RowHeight = 30
&#39;xlWorksheet.Range(xlWorksheet.Cells(i,3), xlWorksheet.Cells(i,4)).MergeCells =True
&#39;xlWorksheet.Range(xlWorksheet.Cells(i,7), xlWorksheet.Cells(i,8)).MergeCells =True
Set fs = Cr&#101;ateObject("Scripting.FileSystemObject")
tfile=Server.MapPath("test.xls")
if fs.FileExists(tfile) then
Set f = fs.GetFile(tfile)
f.del&#101;te true
Set f = nothing
end if
Set fs = nothing
xlWorksheet.SaveAs tfile &#39;保存文件
xlApplication.Quit &#39;释放对象
Set xlWorksheet = Nothing
Set xlApplication = Nothing
%>
<%
Function downLoadFile(FileSpec)
on error resume next
Const ForReading=1
Const TristateTrue=-1
Const FILE_TRANSFER_SIZE=1024   &#39;16384
Dim objFileSystem, objFile, objStream
Dim char
Dim sent
Set objFileSystem = Cr&#101;ateObject("Scripting.FileSystemObject")
If objFileSystem.FileExists(fileSpec)=false Then
response.write("<Script>alert(""请求文件不存在!"");history.back();</script>")
Exit Function
End If
FileName = objFileSystem.GetFileName(FileSpec)
send=0
TransferFile = True
Set objFileSystem = Server.Cr&#101;ateObject("Scripting.FileSystemObject")
Set objFile = objFileSystem.GetFile(FileSpec)
Set objStream = objFile.OpenAsTextStream(ForReading, TristateTrue)
Response.AddHeader "content-type", "application/octet-stream"
Response.AddHeader "Content-Disposition","attachment;filename=" & filename
Response.AddHeader "content-length", objFile.Size
Do While Not objStream.AtEndOfStream
char = objStream.Read(1)
Response.BinaryWrite(char)
sent = sent + 1
If (sent MOD FILE_TRANSFER_SIZE) = 0 Then
Response.Flush
If Not Response.IsClientConnected Then
TransferFile = False
Exit Do
End If
End If
Loop
Response.Flush
If Not Response.IsClientConnected Then TransferFile = False
objStream.Close
Set objStream = Nothing
Set objFileSystem = Nothing
End Function
fileSpec =Lcase(Cstr(Trim(Request("fileSpec"))))
downLoadFile(fileSpec)
%>
<p align="center"><a href="downfile.asp?fileSpec=<%=tfile%>">下载</a></p>
</body>
</html>

[代码]TextArea中显示回车换行

mikel阅读(1004)

<textarea name="messages" cols="90" rows="30" id="messages"><%
while not chat.eof
response.Write(chat("messagedate")&":"&chat("statevalue")&"说:"&chat("linkname")&" "&chat("message")&vbCrlf)
chat.movenext
wend%>
</textarea>

[代码]TextArea中加入链接

mikel阅读(967)

TEXTAREA的内容是纯文本,默认是不能有链接之类的,如果要实现的话必须使用JavaScript来实在
带颜色的文字和链接

[问题]ASP中recordcount=-1的问题

mikel阅读(786)

Set Rs=Conn.Execute(SQLStr)

Set Rs=Server.CreateObject(“ADODB.RecordSet“)
Rs.Open SQLStr,Conn,CursorType,LockType
(RecordSet对象方法请看这里)
由于默认的记录集游标是服务器游标,
Rs.CursorLocation = adUseServer
所以返回Rs.RecordCount=-1,
应该把服务器游标改为客户端游标,
Rs.CursorLocation = adUseClient
Rs.Open SqlStr,Conn,CursorType,LockType
rs.cursortype
光标类型 recordcount 属性
———————————————
ForwardOnly 0(默认) 返回-1
Keyset 1 正确的记录数
Dynamic 2 -1或不正确的记录数,依数据源而定
Static 3 正确的记录数
所以Rs.CursorLocation = 3
可用recordset.support(“属性名”)进行测试是否支持该属性。

[代码]跨窗口漂浮JavaScript代码

mikel阅读(751)

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>跨窗口漂浮窗口</title>
<SCRIPT LANGUAGE="JAVASCRIPT">
var imagepath="http://xindaima.cn/images/logo.jpg"
var imagewidth=110 //这两行写图片的大小
var imageheight=50
var speed=3;
var imageclick="http://xindaima.cn" //这里写点击图片连接到的地址
var hideafter=0
var isie=0;
if(window.navigator.appName=="Microsoft Internet Explorer"&&window.navigator.appVersion.substring(window.navigator.appVersion.indexOf("MSIE")+5,window.navigator.appVersion.indexOf("MSIE")+8)>=5.5) {
isie=1;
}
else {
isie=0;
}
if(isie){
var preloadit=new Image()
preloadit.src=imagepath
}
function pop() {
if(isie) {
x=x+dx;y=y+dy;
oPopup.show(x, y, imagewidth, imageheight);
if(x+imagewidth+5>screen.width) dx=-dx;
if(y+imageheight+5>screen.height) dy=-dy;
if(x<0) dx=-dx;
if(y<0) dy=-dy;
startani=setTimeout("pop();",50);
}
}
function dismisspopup(){
clearTimeout(startani)
oPopup.hide()
}
function dowhat(){
if (imageclick=="dismiss")
dismisspopup()
else
window.open(imageclick);
}
if(isie) {
var x=0,y=0,dx=speed,dy=speed;
var oPopup = window.cr&#101;atePopup();
var oPopupBody = oPopup.document.body;
oPopupBody.style.cursor="hand"
oPopupBody.innerHTML = &#39;<IMG SRC="&#39;+preloadit.src+&#39;">&#39;;
oPopup.document.body.onmouseover=new Function("clearTimeout(startani)")
oPopup.document.body.onmouseout=pop
oPopup.document.body.onclick=dowhat
pop();
if (hideafter>0)
setTimeout("dismisspopup()",hideafter*1000)
}
</SCRIPT>

[教程]将图片保存为swf文件的AIR

mikel阅读(1050)

Problem Summary

Saving images from AIR application in SWF format.

Solution Summary

Encode BitmapData to PNG or JPEG file, and load it to Loader using loadBytes method. After loading is completed you can pull out SWF data using bytes property of LoaderInfo class. This method works only in AIR applications.

Explanation

In AIR applications images loaded with Loader class are internally stored as a single frame, not compressed SWF file. As far as I know, this isn't documented anywhere, but it seems to work this way. This also fast way to convert local image file (png, jpg or gif) to swf format. We will use this method to create save local swf file from any image that is stored in BitmapData class instance.

 /* create bitmap to be saved as an swf file */
 var bd:BitmapData = new BitmapData(320,240);
 /* capture application snapshot, this can be any other object */
 bd.draw( Application.application as IBitmapDrawable );

When we have already created bitmap image we need to encode it to PNG or JPEG virtual file. Virtual means it will be stored in memory using ByteArray class. In example below we use mx.graphics.codec.PNGEncoder, to create virtual png file.

/* create virtual png file */
 var png:ByteArray = ( new PNGEncoder() ).encode( bd );

Last step is to use Loader class to load image. To load virtual png image stored in as instance of ByteArray class we must use loadBytes method. Listener function saveContentToSWF will be executed when load completes.

/* load virtual png image */
 var l:Loader = new Loader();
 l.contentLoaderInfo.addEventListener( Event.COMPLETE, saveContentToSWF );
 l.loadBytes( png );

When event is dispatched, our image is already converted to SWF file. Bytes stored in Loader class can be accessed with contentLoaderInfo.bytes property. To create and save local file we use File and FileStream classes. Lets put this all together now.

function saveContentToSWF( event : Event ):void
{
/* create output file on desktop */
var file:File = File.desktopDirectory.resolvePath('out.swf');
 var fs:FileStream = new FileStream(); fs.open( file, FileMode.WRITE );
/* pull out SWF bytes from Loader */
fs.writeBytes( (evt.target as LoaderInfo).bytes );
fs.close();
}

This method we will create local uncompressed SWF file. To decrease size we can also create compressed SWF file. To do this we must copy 8 byte header from uncompressed one. To indicate that file is compressed we must set first byte to value 0x43 (ascii code of letter 'C'). Entire file after first 8 bytes can be then compressed using compress method of ByteArray class. Puting this together we get new listener function, that creates compressed SWF files.

function saveContentToSWF_compress( event : Event ):void
{
 var file:File = File.desktopDirectory.resolvePath('out_c.swf');
 var fs:FileStream = new FileStream();
 fs.open( file, FileMode.WRITE );         
 /* compressed file header */
 var swf_head : ByteArray = new ByteArray();
 swf_head.endian = Endian.LITTLE_ENDIAN;
 swf_head.writeBytes( (evt.target as LoaderInfo).bytes, 0, 8 );
 swf_head[0] = 0x43; // 'C' letter, indicates that file is compressed
 swf_head.position = 0;
 /* compressed file body */
 var swf_body : ByteArray = new ByteArray();
 swf_body.endian = Endian.LITTLE_ENDIAN;
 swf_body.writeBytes( (evt.target as LoaderInfo).bytes, 8 );
 swf_body.position = 0;
 swf_body.compress();
 swf_body.position = 0;         
 /* write it down to file */
 fs.writeBytes( swf_head );
 fs.writeBytes( swf_body );
 fs.close();         
};

Example code using this technique is attached. Example application saves two SWF files compressed and uncompressed on users desktop.

Related files for download

save file, save image, save swf, swf, AIR, jpg, png
save_swf.zip

[工具]将GB转换为UTF-8的工具

mikel阅读(988)

现在做的时候发现原来用的是gb编码,既然木已成舟,生米煮成熟饭,不如只转换涉及到的页面的编码了
于是,将包含的文件saveas后,找了个好用的工具,看来同病相连的人不少,呵呵….先一步写了工具
共产出来大家下载!
下载文件 点击下载此文件

[教程]ASP中UTF-8乱码

mikel阅读(753)

为什么在ASP里指定了codepage为65001还经常显示乱码。才子在这里将这个问题详细解释一下,以免很多朋友再走弯路,甚至排斥UTF-8。
如果你还不知道UTF-8是什么东东,那才子建议你先去搜索一下UTF-8的相关资料吧。
UTF-8编码之所以被越来越多的人接受甚至喜欢,肯定是有道理的,在WEB2.0盛行的今天,在大谈多浏览器兼容的同时,不得不想到字符编码不同所造成的乱码现象同样需要得到很好的处理…..
在N年以前,IE6以下的所有版本,只要没有安装相应的字库,访问相关的页面都是会乱码的,例如,我是IE5 (Windows2000默认) 的版本,在没有安装IE繁体字库的情况下,访问任何繁体页面的网站都是会乱码的,当然前提是该页面采用了BIG5的Charset,而UTF-8作为一种国际编码就能很好的处理该问题,只要将页面存为UTF-8编码格式,再在页面上将codepage及charset全部定义为utf-8就可以在任何客户端浏览器中显示出完全正确的内容,完全不会乱码……
好了,这里以ASP页面为例,以一个实例来看具体操作吧:
打开新建一个ASP页面,相信玩ASP的朋友都会留意到,许多下载的源码里,页面最上方一般都有一句:
以下为引用的内容:
%@LANGUAGE=”VBSCRIPT” CODEPAGE=”936″%
前面的language应该不用多说了,vbscript就是ASP默认的脚本语言,其实完全可以不用写,写了好像还会影响页面执行效率,在这里我们先不讨论这个问题。后面的codepage就是关键了,目的就是告诉浏览器,此页面是何种编码,936代表是简体中文,而950代表繁体中文, 65001就是我们今天说的UTF-8编码了。我们将936改成65001。整句如下:
以下为引用的内容:
%@LANGUAGE=”VBSCRIPT” CODEPAGE=”65001″%
再加上输出几个中文字看看能不能正确显示吧。
以下为引用的内容:
<% Response.Write "第一次测试UTF-8页面" %>
 
OK,直接点击“保存”,执行这个页面看看,如果不出意外,大家可能看到显示出的是 “一尾UTF-8页”这几个字,中文有乱码的现象,什么原因呢?
OK,请大家再点击最上面的 “文件” 菜单,选择”另存为”,最下面一行有个编码,默认应该是ANSI的,请大家点下拉框,选择UTF-8,再点保存,再执行试试看,如果不出意外,乱得更厉害了,呵呵,晕了吧。别急,想想原因,因为我们做的页面是HTML返回的,以前我们写HTML时,看到body前面,也就是head里都有一句meta,应该是这样的:
以下为引用的内容:

  
也就是指定页面以gb2312编码返回结果,一定要写在有返回结果输出的前面。大家都知道gb2312是简体中文吧,我们今天说的是UTF-8编码,我们就将gb2312改成UTF-8吧,全部代码如下:
以下为引用的内容:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>

<% Response.Write "第一次测试UTF-8页面" %>
  
再执行看看,嗯,这次正常显示了吧…….
结论:采用UTF-8编码,除了要将文件另存为UTF-8格式之外,还需要同时指定codepage及charset。

[代码]Javascript获取链接的文字内容

mikel阅读(878)

if (navigator.appName == "Microsoft Internet Explorer"){
document.getElementById("sayto").value=document.getElementById(lid).innerText;
}else{
document.getElementById("sayto").value=document.getElementById(lid).text;
}

[资源]程序员晋级教程

mikel阅读(776)

《J2EE 课程视频教程》赛迪网校罗泽彬老师主讲
http://www.beifengkd.com/read.php?tid=886&u=2660
《张孝祥JAVA视频教程》完整版[RMVB]
http://www.beifengkd.com/read.php?tid=422&u=2660
尚学堂148班高清晰版本Hibernate(王勇主讲)—共40集
http://www.beifengkd.com/read.php?tid=1338&u=2660
新东方J2ee系列
http://www.beifengkd.com/read.php?tid=531&u=2660
树人J2EE高级框架实战教学(视频教程)郭克华
http://www.beifengkd.com/read.php?tid=620&u=2660
MLDN J2EE 开发视频(共54讲)
http://www.beifengkd.com/read.php?tid=443&u=2660
北大青鸟 ASP.NET 视频(主讲:于海涛)共32 讲
http://www.beifengkd.com/read.php?tid=475&u=2660
达内anyfo–EJB视频第一集发布!!
http://www.beifengkd.com/read.php?tid=1329&u=2660
郭克华J2ME
http://www.beifengkd.com/read.php?tid=241&u=2660
H.S联盟VIP东西[黑客特训班]
http://www.beifengkd.com/read.php?tid=216&u=2660
oracle10g快捷版使用视频
http://www.beifengkd.com/read.php?tid=996&u=2660
参考资料:http://www.beifengkd.com/?a=ietjfdnv