⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nb联盟18.htm

📁 较为详细的介绍了asp自定义的各种函数,方便asp的各种开发.
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0055)http://www.51base.com/article/view_article.asp?id=67560 -->
<HTML lang=zh-cn><HEAD><TITLE>NB联盟</TITLE>
<META content="text/html; charset=gb2312" http-equiv=Content-Type><LINK 
href="NB联盟18.files/style.css" rel=stylesheet>
<META content="MSHTML 5.00.2614.3500" name=GENERATOR></HEAD>
<BODY><!-- start page body -->
<TABLE align=center border=0 cellPadding=0 cellSpacing=0 class=td id=position 
width=773>
  <TBODY>
  <TR>
    <TD class=shadow colSpan=2 height=20 width=262>&nbsp;&nbsp;<A 
      href="http://www.51base.com/"><IMG border=0 
      src="NB联盟18.files/logo1.gif"></A> </TD>
    <TD align=right width=505>
      <P align=left></P></TD></TR></TBODY></TABLE>
<TABLE align=center border=0 cellPadding=0 cellSpacing=0 id=main width=770>
  <TBODY>
  <TR>
    <TD class=tdlbr vAlign=top>
      <TABLE align=center border=0 cellPadding=0 cellSpacing=0 id=welcome 
      style="TABLE-LAYOUT: fixed" width="98%">
        <TBODY>
        <TR>
          <TD style="TABLE-LAYOUT: fixed; WORD-BREAK: break-all" 
            vAlign=top><FONT color=red><B>文章标题</B></FONT><FONT color=red><B>: 
            ASP对excel的操作? </B></FONT>
            <HR noShade SIZE=1>
            <BR>请问ASP中怎样访问EXCEL对象! 
            &nbsp;<BR>--------------------------------------------------------------- 
            &nbsp;<BR>&nbsp;<BR>ASP操作Excel技术总结 &nbsp;<BR>&nbsp;<BR>目录 
            &nbsp;<BR>一、 &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;环境配置 
            &nbsp;<BR>二、 &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp;ASP对Excel的基本操作 &nbsp;<BR>三、 &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp;ASP操作Excel生成数据表 &nbsp;<BR>四、 &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;ASP操作Excel生成Chart图 
            &nbsp;<BR>五、 &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp;服务器端Excel文件浏览、下载、删除方案 &nbsp;<BR>六、 &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;附录 &nbsp;<BR>&nbsp;<BR>正文 
            &nbsp;<BR>一、 &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;环境配置 
            &nbsp;<BR>服务器端的环境配置从参考资料上看,微软系列的配置应该都行,即: 
            &nbsp;<BR>1.Win9x+PWS+Office &nbsp;<BR>2.Win2000 
            &nbsp;Professional+PWS+Office &nbsp;<BR>3.Win2000 
            &nbsp;Server+IIS+Office 
            &nbsp;<BR>目前笔者测试成功的环境是后二者。Office的版本没有特殊要求,考虑到客户机配置的不确定性和下兼容特性,建议服务器端Office版本不要太高,以防止客户机下载后无法正确显示。 
            &nbsp;<BR>服务器端环境配置还有两个偶然的发现是: &nbsp;<BR>1. &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; 
            &nbsp;&nbsp;笔者开发机器上原来装有金山的WPS2002,结果Excel对象创建始终出现问题,卸载WPS2002后,错误消失。 
            &nbsp;<BR>2. &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp;笔者开发ASP代码喜欢用FrontPage,结果发现如果FrontPage打开(服务器端),对象创建出现不稳定现象,时而成功时而不成功。扩展考察后发现,Office系列的软件如果在服务器端运行,则Excel对象的创建很难成功。 
            &nbsp;<BR>服务器端还必须要设置的一点是COM组件的操作权限。在命令行键入“DCOMCNFG”,则进入COM组件配置界面,选择Microsoft 
            &nbsp;Excel后点击属性按钮,将三个单选项一律选择自定义,编辑中将Everyone加入所有权限。保存完毕后重新启动服务器。 
            &nbsp;<BR>客户端的环境配置没发现什么特别讲究的地方,只要装有Office和IE即可,版本通用的好象都可以。 
            &nbsp;<BR>&nbsp;<BR>二、 &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp;ASP对Excel的基本操作 &nbsp;<BR>1、 &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp;建立Excel对象 &nbsp;<BR>set &nbsp;objExcelApp 
            &nbsp;= &nbsp;CreateObject("Excel.Application") 
            &nbsp;<BR>objExcelApp.DisplayAlerts &nbsp;= &nbsp;false &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp;不显示警告 
            &nbsp;<BR>objExcelApp.Application.Visible &nbsp;= &nbsp;false 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;不显示界面 &nbsp;<BR>2、 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;新建Excel文件 
            &nbsp;<BR>objExcelApp.WorkBooks.add &nbsp;<BR>set &nbsp;objExcelBook 
            &nbsp;= &nbsp;objExcelApp.ActiveWorkBook &nbsp;<BR>set 
            &nbsp;objExcelSheets &nbsp;= &nbsp;objExcelBook.Worksheets 
            &nbsp;<BR>set &nbsp;objExcelSheet &nbsp;= 
            &nbsp;objExcelBook.Sheets(1) &nbsp;<BR>3、 &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp;读取已有Excel文件 &nbsp;<BR>strAddr &nbsp;= 
            &nbsp;Server.MapPath(".") 
            &nbsp;<BR>objExcelApp.WorkBooks.Open(strAddr &nbsp;&amp; 
            &nbsp;"\Templet\Table.xls") &nbsp;<BR>set &nbsp;objExcelBook &nbsp;= 
            &nbsp;objExcelApp.ActiveWorkBook &nbsp;<BR>set &nbsp;objExcelSheets 
            &nbsp;= &nbsp;objExcelBook.Worksheets &nbsp;<BR>set 
            &nbsp;objExcelSheet &nbsp;= &nbsp;objExcelBook.Sheets(1) 
            &nbsp;<BR>4、 &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp;另存Excel文件 &nbsp;<BR>objExcelBook.SaveAs &nbsp;strAddr 
            &nbsp;&amp; &nbsp;"\Temp\Table.xls" &nbsp;<BR>5、 &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;保存Excel文件 
            &nbsp;<BR>objExcelBook.Save &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp;(笔者测试时保存成功,页面报错。) &nbsp;<BR>6、 &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp;退出Excel操作 &nbsp;<BR>objExcelApp.Quit 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;一定要退出 
            &nbsp;<BR>set &nbsp;objExcelApp &nbsp;= &nbsp;Nothing 
            &nbsp;<BR>&nbsp;<BR>三、 &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp;ASP操作Excel生成数据表 &nbsp;<BR>1、 &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp;在一个范围内插入数据 
            &nbsp;<BR>objExcelSheet.Range("B3:k3").Value &nbsp;= 
            &nbsp;Array("67", &nbsp;"87", &nbsp;"5", &nbsp;"9", &nbsp;"7", 
            &nbsp;"45", &nbsp;"45", &nbsp;"54", &nbsp;"54", &nbsp;"10") 
            &nbsp;<BR>2、 &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp;在一个单元格内插入数据 
            &nbsp;<BR>objExcelSheet.Cells(3,1).Value="Internet &nbsp;Explorer" 
            &nbsp;<BR>3、 &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp;选中一个范围 &nbsp;<BR>4、 &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp;单元格左边画粗线条 &nbsp;<BR>5、 &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;单元格右边画粗线条 &nbsp;<BR>6、 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;单元格上边画粗线条 
            &nbsp;<BR>7、 &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp;单元格下边画粗线条 &nbsp;<BR>8、 &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp;单元格设定背景色 &nbsp;<BR>9、 &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;合并单元格 &nbsp;<BR>10、 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;插入行 &nbsp;<BR>11、 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;插入列 
            &nbsp;<BR>&nbsp;<BR>四、 &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp;ASP操作Excel生成Chart图 &nbsp;<BR>1、 &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;创建Chart图 
            &nbsp;<BR>objExcelApp.Charts.Add &nbsp;<BR>2、 &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;设定Chart图种类 
            &nbsp;<BR>objExcelApp.ActiveChart.ChartType &nbsp;= &nbsp;97 
            &nbsp;<BR>注:二维折线图,4;二维饼图,5;二维柱形图,51 &nbsp;<BR>3、 &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;设定Chart图标题 
            &nbsp;<BR>objExcelApp.ActiveChart.HasTitle &nbsp;= &nbsp;True 
            &nbsp;<BR>objExcelApp.ActiveChart.ChartTitle.Text &nbsp;= &nbsp;"A 
            &nbsp;test &nbsp;Chart" &nbsp;<BR>4、 &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp;通过表格数据设定图形 
            &nbsp;<BR>objExcelApp.ActiveChart.SetSourceData 
            &nbsp;objExcelSheet.Range("A1:k5"),1 &nbsp;<BR>5、 &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;直接设定图形数据(推荐) 
            &nbsp;<BR>objExcelApp.ActiveChart.SeriesCollection.NewSeries 
            &nbsp;<BR>objExcelApp.ActiveChart.SeriesCollection(1).Name &nbsp;= 
            &nbsp;"=""333""" 
            &nbsp;<BR>objExcelApp.ActiveChart.SeriesCollection(1).Values &nbsp;= 
            &nbsp;"={1,4,5,6,2}" &nbsp;<BR>6、 &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp;绑定Chart图 
            &nbsp;<BR>objExcelApp.ActiveChart.Location &nbsp;1 &nbsp;<BR>7、 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;显示数据表 
            &nbsp;<BR>objExcelApp.ActiveChart.HasDataTable &nbsp;= &nbsp;True 
            &nbsp;<BR>8、 &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;显示图例 
            &nbsp;<BR>objExcelApp.ActiveChart.DataTable.ShowLegendKey &nbsp;= 
            &nbsp;True &nbsp;<BR>&nbsp;<BR>五、 &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp;服务器端Excel文件浏览、下载、删除方案 
            &nbsp;<BR>浏览的解决方法很多,“Location.href=”,“Navigate”,“Response.Redirect”都可以实现,建议用客户端的方法,原因是给服务器更多的时间生成Excel文件。 
            &nbsp;<BR>下载的实现要麻烦一些。用网上现成的服务器端下载组件或自己定制开发一个组件是比较好的方案。另外一种方法是在客户端操作Excel组件,由客户端操作服务器端Excel文件另存至客户端。这种方法要求客户端开放不安全ActiveX控件的操作权限,考虑到通知每个客户将服务器设置为可信站点的麻烦程度建议还是用第一个方法比较省事。 
            &nbsp;<BR>删除方案由三部分组成: &nbsp;<BR>A: &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; 
            &nbsp;&nbsp;同一用户生成的Excel文件用同一个文件名,文件名可用用户ID号或SessionID号等可确信不重复字符串组成。这样新文件生成时自动覆盖上一文件。 
            &nbsp;<BR>B: &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp;在Global.asa文件中设置Session_onEnd事件激发时,删除这个用户的Excel暂存文件。 
            &nbsp;<BR>C: &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp;在Global.asa文件中设置Application_onStart事件激发时,删除暂存目录下的所有文件。 
            &nbsp;<BR>注:建议目录结构 &nbsp;\Src &nbsp;代码目录 &nbsp;\Templet &nbsp;模板目录 
            &nbsp;\Temp &nbsp;暂存目录 &nbsp;<BR>&nbsp;<BR>六、 &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;附录 
            &nbsp;<BR>出错时Excel出现的死进程出现是一件很头疼的事情。在每个文件前加上“On &nbsp;Error 
            &nbsp;Resume 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -