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

📄 用asp如何把access的内容转到excel里面 .htm

📁 较为详细的介绍了asp自定义的各种函数,方便asp的各种开发.
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0055)http://www.51base.com/article/view_article.asp?id=74212 -->
<HTML lang=zh-cn><HEAD><TITLE>NB联盟</TITLE>
<META content="text/html; charset=gb2312" http-equiv=Content-Type><LINK 
href="NB联盟31.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联盟31.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如何把Access的内容转到Excel里面 </B></FONT>
            <HR noShade SIZE=1>
            <BR>把Access的表名作为Excel的第一行? 
            &nbsp;<BR>--------------------------------------------------------------- 
            &nbsp;<BR>&nbsp;<BR>Class &nbsp;ExcelGen &nbsp;<BR>&nbsp;<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp;Private &nbsp;objSpreadsheet &nbsp;<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp;Private &nbsp;iColOffset &nbsp;<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp;Private &nbsp;iRowOffset &nbsp;<BR>&nbsp;<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp;Sub &nbsp;Class_Initialize() &nbsp;<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Set &nbsp;objSpreadsheet &nbsp;= 
            &nbsp;Server.CreateObject("OWC.Spreadsheet") 
            &nbsp;<BR>&nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;iRowOffset &nbsp;= &nbsp;2 &nbsp;<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp;iColOffset &nbsp;= &nbsp;2 &nbsp;<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp;End &nbsp;Sub &nbsp;<BR>&nbsp;<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp;Sub &nbsp;Class_Terminate() &nbsp;<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp;Set &nbsp;objSpreadsheet &nbsp;= 
            &nbsp;Nothing &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp;End &nbsp;Sub 
            &nbsp;<BR>&nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp;Public &nbsp;Property 
            &nbsp;Let &nbsp;ColumnOffset(iColOff) &nbsp;<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp;If &nbsp;iColOff &nbsp;&gt; &nbsp;0 &nbsp;then 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;iColOffset &nbsp;= &nbsp;iColOff &nbsp;<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp;Else &nbsp;<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;iColOffset &nbsp;= &nbsp;2 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;End &nbsp;If 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp;End &nbsp;Property 
            &nbsp;<BR>&nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp;Public &nbsp;Property 
            &nbsp;Let &nbsp;RowOffset(iRowOff) &nbsp;<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp;If &nbsp;iRowOff &nbsp;&gt; &nbsp;0 &nbsp;then 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;iRowOffset &nbsp;= &nbsp;iRowOff &nbsp;<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp;Else &nbsp;<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;iRowOffset &nbsp;= &nbsp;2 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;End &nbsp;If 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp;End &nbsp;Property 
            &nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp;Sub 
            &nbsp;GenerateWorksheet(objRS) &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp;If &nbsp;objRS.EOF &nbsp;then &nbsp;Exit &nbsp;Sub 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dim 
            &nbsp;objField, &nbsp;iCol, &nbsp;iRow &nbsp;<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp;dim &nbsp;TempStr &nbsp;<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp;iCol &nbsp;= &nbsp;iColOffset 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;iRow &nbsp;= 
            &nbsp;iRowOffset &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;For &nbsp;Each &nbsp;objField &nbsp;in &nbsp;objRS.Fields 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;objSpreadsheet.Cells(iRow, &nbsp;iCol).Value &nbsp;= 
            &nbsp;right(objField.Name,len(objField.Name)-1) &nbsp;<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;objSpreadsheet.Columns(iCol).AutoFitColumns &nbsp; 
            &nbsp;<BR>&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;'设置Excel表里的字体 
            &nbsp;<BR>&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp;objSpreadsheet.Cells(iRow, &nbsp;iCol).Font.Bold &nbsp;= 
            &nbsp;True &nbsp; &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp;objSpreadsheet.Cells(iRow, 
            &nbsp;iCol).Font.Italic &nbsp;= &nbsp;False &nbsp;<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;objSpreadsheet.Cells(iRow, 
            &nbsp;iCol).Font.Size &nbsp;= &nbsp;10 &nbsp;<BR>&nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp;objSpreadsheet.Cells(iRow, 
            &nbsp;iCol).Halignment &nbsp;= &nbsp;2 &nbsp;'居中 &nbsp;<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;iCol &nbsp;= 
            &nbsp;iCol &nbsp;+ &nbsp;1 &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp;Next &nbsp; &nbsp;<BR>&nbsp;<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp;Do &nbsp;While &nbsp;Not &nbsp;objRS.EOF 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;iRow &nbsp;= &nbsp;iRow &nbsp;+ &nbsp;1 &nbsp;<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;iCol &nbsp;= 
            &nbsp;iColOffset &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp;For &nbsp;Each &nbsp;objField &nbsp;in 
            &nbsp;objRS.Fields &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;If &nbsp;IsNull(objField.Value) 
            &nbsp;then &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;objSpreadsheet.Cells(iRow, 
            &nbsp;iCol).Value &nbsp;= &nbsp;"" &nbsp;<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Else &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TempStr=objField.Value 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp;if &nbsp;instr(1,"日期",objField.name)&gt;1 
            &nbsp;then &nbsp;<BR>&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;TempStr=Year(objField.Value) 
            &nbsp;&amp; &nbsp;"年" &nbsp;&amp; &nbsp;month(objField.Value) 
            &nbsp;&amp; &nbsp;"月" &nbsp;&amp; &nbsp;day(objField.Value) 
            &nbsp;&amp; &nbsp;"日" &nbsp;<BR>&nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;end 
            &nbsp;if &nbsp;<BR>&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;if 
            &nbsp;instr(1,objField.name,"时间")&gt;1 &nbsp;then 
            &nbsp;<BR>&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp;TempStr=Year(objField.Value) &nbsp;&amp; 
            &nbsp;"年" &nbsp;&amp; &nbsp;month(objField.Value) &nbsp;&amp; 
            &nbsp;"月" &nbsp;&amp; &nbsp;day(objField.Value) &nbsp;&amp; &nbsp;"日 
            &nbsp;" &nbsp;&amp; &nbsp;hour(objField.value) &nbsp;&amp; &nbsp;"时" 
            &nbsp;&amp; &nbsp;minute(objField.value) &nbsp;&amp; &nbsp;"分" 
            &nbsp;&amp; &nbsp;second(objField.value) &nbsp;&amp; &nbsp;"秒" 
            &nbsp;<BR>&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;end &nbsp;if &nbsp;<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp;objSpreadsheet.Cells(iRow, &nbsp;iCol).Value &nbsp;= 
            &nbsp;TempStr &nbsp;<BR>&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp;objSpreadsheet.Columns(iCol).AutoFitColumns &nbsp; 
            &nbsp;<BR>&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;objSpreadsheet.Cells(iRow, 
            &nbsp;iCol).Font.Bold &nbsp;= &nbsp;False &nbsp; &nbsp;<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp;objSpreadsheet.Cells(iRow, &nbsp;iCol).Font.Italic 
            &nbsp;= &nbsp;False &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;objSpreadsheet.Cells(iRow, &nbsp;iCol).Font.Size &nbsp;= 
            &nbsp;10 &nbsp; &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp;End &nbsp;If &nbsp;<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;iCol &nbsp;= 
            &nbsp;iCol &nbsp;+ &nbsp;1 &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp;Next &nbsp;<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;objRS.MoveNext &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;Loop &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp;End &nbsp;Sub &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp;Function &nbsp;SaveWorksheet(strFileName) 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;On &nbsp;Error 
            &nbsp;Resume &nbsp;Next &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;Call &nbsp;objSpreadsheet.ActiveSheet.Export(strFileName, 
            &nbsp;0) &nbsp;<BR>&nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;SaveWorksheet &nbsp;= &nbsp;(Err.Number &nbsp;= &nbsp;0) 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp;End &nbsp;Function 
            &nbsp;<BR>&nbsp;<BR>&nbsp; &nbsp;End &nbsp;Class &nbsp;<BR>ExcelPath 
            &nbsp;= &nbsp;"Excel/" &nbsp;&amp; &nbsp;SaveName &nbsp;&amp; 
            &nbsp;".xls" &nbsp;<BR>&nbsp; &nbsp; &nbsp;<BR>&nbsp; &nbsp;Set 
            &nbsp;objExcel &nbsp;= &nbsp;New &nbsp;ExcelGen 
            &nbsp;<BR>&nbsp;<BR>&nbsp; &nbsp;objExcel.RowOffset &nbsp;= &nbsp;1 
            &nbsp;<BR>&nbsp; &nbsp;objExcel.ColumnOffset &nbsp;= &nbsp;1 
            &nbsp;<BR>&nbsp; &nbsp;Response.write 
            &nbsp;"&lt;center&gt;第一步:文件导出成功!&lt;br&gt;&lt;br&gt;&lt;br&gt;" 
            &nbsp;<BR>&nbsp; &nbsp;objExcel.GenerateWorksheet(AdoRs) 
            &nbsp;<BR>&nbsp; &nbsp;dim &nbsp;Url &nbsp;<BR>&nbsp; 
            &nbsp;Url=ExcelPath &nbsp;<BR>&nbsp; 
            &nbsp;'Url=server.URLEncode(ExcelPath) &nbsp;<BR>&nbsp; &nbsp;If 
            &nbsp;objExcel.SaveWorksheet(Server.MapPath(ExcelPath)) &nbsp;then 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp;response.write 
            &nbsp;"第二步:文件保存成功!<BR></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR>
<TABLE align=center border=0 cellPadding=2 cellSpacing=0 id=footer width=770>
  <TBODY>
  <TR>
    <TD align=middle class=tdt>
      <P align=center></P></TD></TR></TBODY></TABLE><BR></BODY></HTML>

⌨️ 快捷键说明

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