欢迎光临
我们一直在努力

把数据库查询信息直接生成网页嵌入EXCEL表的格式,并可导出成EXCEL文件-ASP教程,数据库相关

建站超值云服务器,限时71元/月

看了精华区中众多处理excel的贴子,好象没有人写这种操作方法,我把我做过的写出来给大家参考一下。

1、先在frongpage中新建一个网页,在网页中插入一个excel组件(插入-web组件-excel电子表格),然后把你要输出的数据格式输入该嵌入的excel表格中,在组件中点右键-属性,可定义该组件的各部分定义项,做好后,查看源代码,得到该嵌入组件的源代码。

2、在vid中新建一asp网页,复制上步骤中的源代码,然后针对数据列加入循环取数代码。如下:
<object classid=”clsid:0002e510-0000-0000-c000-000000000046″ id=”spreadsheet1″ codebase=”msowc.cab” width=”599″ height=”490″>
  <param name=”htmlurl” value>
  <param name=”htmldata” value=”&lt;html xmlns:x=&quot;urn:schemas-microsoft-com:office:excel&quot;
xmlns=&quot;http://www.w3.org/tr/rec-html40&quot;&gt;

&lt;head&gt;
&lt;style type=&quot;text/css&quot;&gt;
&lt;!–tr
    {mso-height-source:userset;}
td
    {white-space:nowrap;}
.wc80a6909
    {white-space:nowrap;
    font-family:宋体;
    mso-number-format:general;
    font-size:auto;
    font-weight:auto;
    font-style:auto;
    text-decoration:auto;
    mso-background-source:auto;
    mso-pattern:auto;
    mso-color-source:auto;
    text-align:general;
    vertical-align:bottom;
    border-top:none;
    border-left:none;
    border-right:none;
    border-bottom:none;
    mso-protection:locked;}
.wc01f2f7a
    {white-space:nowrap;
    font-family:宋体;
    mso-number-format:general;
    font-size:auto;
    font-weight:auto;
    font-style:auto;
    text-decoration:auto;
    mso-background-source:auto;
    mso-pattern:auto;
    mso-color-source:auto;
    text-align:general;
    vertical-align:bottom;
    border-top:none;
    border-left:none;
    border-right:none;
    border-bottom:none;
    mso-protection:locked;}
.wc0ea6f7a
    {white-space:nowrap;
    font-family:宋体;
    mso-number-format:general;
    font-size:auto;
    font-weight:auto;
    font-style:auto;
    text-decoration:auto;
    mso-background-source:auto;
    mso-pattern:auto;
    mso-color-source:auto;
    text-align:center;
    vertical-align:bottom;
    border-top:none;
    border-left:none;
    border-right:none;
    border-bottom:none;
    mso-protection:locked;}
–&gt;
&lt;/style&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;!–[if gte mso 9]&gt;&lt;xml&gt;
&lt;x:excelworkbook&gt;
  &lt;x:excelworksheets&gt;
   &lt;x:excelworksheet&gt;
    &lt;x:owcversion&gt;9.0.0.2710&lt;/x:owcversion&gt;
    &lt;x:label style=font-size:11pt;border-top:solid .5pt silver;border-left:
     solid .5pt silver;border-right:solid .5pt silver;border-bottom:solid .5pt silver&gt;
     &lt;x:caption&gt;返工处理日报表-产成品出入库报表-<%=trim(rs_stock(“fname”))%>(<%=sdate%>至<%=edate%>)&lt;/x:caption&gt;
    &lt;/x:label&gt;
    &lt;x:name&gt;sheet1&lt;/x:name&gt;
    &lt;x:worksheetoptions&gt;
     &lt;x:selected/&gt;
     &lt;x:height&gt;12965&lt;/x:height&gt;
     &lt;x:width&gt;13996&lt;/x:width&gt;
     &lt;x:toprowvisible&gt;0&lt;/x:toprowvisible&gt;
     &lt;x:leftcolumnvisible&gt;0&lt;/x:leftcolumnvisible&gt;
     &lt;x:protectcontents&gt;false&lt;/x:protectcontents&gt;
     &lt;x:defaultrowheight&gt;315&lt;/x:defaultrowheight&gt;
     &lt;x:standardwidth&gt;2389&lt;/x:standardwidth&gt;
    &lt;/x:worksheetoptions&gt;
   &lt;/x:excelworksheet&gt;
  &lt;/x:excelworksheets&gt;
  &lt;x:maxheight&gt;80%&lt;/x:maxheight&gt;
  &lt;x:maxwidth&gt;80%&lt;/x:maxwidth&gt;
&lt;/x:excelworkbook&gt;
&lt;/xml&gt;&lt;![endif]–&gt;

&lt;table class=wc01f2f7a x:str&gt;
&lt;col class=wc01f2f7a width=&quot;86&quot; style=mso-width-source:userset&gt;
&lt;col class=wc01f2f7a width=&quot;112&quot; style=mso-width-source:userset&gt;
&lt;col class=wc01f2f7a width=&quot;66&quot; style=mso-width-source:userset&gt;
&lt;col width=&quot;83&quot; style=mso-width-source:userset&gt;
&lt;col width=&quot;56&quot;&gt;
&lt;col width=&quot;82&quot; style=mso-width-source:userset&gt;
&lt;tr height=&quot;21&quot; style=mso-height-source:userset&gt;
  &lt;td class=wc01f2f7a&gt;返工处理日报表-产成品出入库报表-<%=trim(rs_stock(“fname”))%>(<%=sdate%>至<%=edate%>)&lt;/td&gt;
  &lt;td class=wc01f2f7a&gt;&lt;/td&gt;
  &lt;td class=wc01f2f7a&gt;&lt;/td&gt;
  &lt;td&gt;&lt;/td&gt;
  &lt;td&gt;&lt;/td&gt;
  &lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height=&quot;21&quot; style=mso-height-source:userset&gt;
  &lt;td class=wc01f2f7a&gt;仓库名称:&lt;/td&gt;
  &lt;td class=wc01f2f7a&gt;<%=trim(rs_stock(“fname”))%>&lt;/td&gt;
  &lt;td class=wc01f2f7a&gt;统计日期:&lt;/td&gt;
  &lt;td&gt;<%=cstr(sdate)%>&lt;/td&gt;
  &lt;td class=wc0ea6f7a&gt;至&lt;/td&gt;
  &lt;td&gt;<%=cstr(edate)%>&lt;/td&gt;
&lt;/tr&gt;
&lt;tr height=&quot;21&quot; style=mso-height-source:userset&gt;
  &lt;td class=wc80a6909&gt;物料短代码&lt;/td&gt;
  &lt;td class=wc80a6909&gt;物料长代码&lt;/td&gt;
  &lt;td class=wc80a6909&gt;物料名称&lt;/td&gt;
  &lt;td class=wc80a6909&gt;返工转出&lt;/td&gt;
  &lt;td&gt;即时库存&lt;/td&gt;
  &lt;td&gt;&lt;/td&gt;
  &lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
<%
开始数据库取数过程
do while not rs_item.eof%>
&lt;tr height=&quot;21&quot; style=mso-height-source:userset&gt;
  &lt;td class=wc01f2f7a&gt;<%=rs_item(“fshortnumber”)%>&lt;/td&gt;
  &lt;td class=wc01f2f7a&gt;<%=rs_item(“fnumber”)%>&lt;/td&gt;
  &lt;td class=wc01f2f7a&gt;<%=rs_item(“fname”)%>&lt;/td&gt;
  &lt;td class=wc01f2f7a x:num=&quot;<%=round(qty_out,rs_item(“fqtydecimal”))%>&quot;&gt;&lt;/td&gt;
  &lt;td class=wc01f2f7a x:num=&quot;<%=round(kc_now,rs_item(“fqtydecimal”))%>&quot;&gt;&lt;/td&gt;
  &lt;td&gt;&lt;/td&gt;
  &lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
<%rs_item.movenext
loop%>
&lt;/table&gt;

&lt;/body&gt;

&lt;/html&gt;
“>
  <param name=”datatype” value=”htmldata”>
  <param name=”autofit” value=”0″>
  <param name=”displaycolheaders” value=”-1″>
  <param name=”displaygridlines” value=”-1″>
  <param name=”displayhorizontalscrollbar” value=”-1″>
  <param name=”displayrowheaders” value=”-1″>
  <param name=”displaytitlebar” value=”-1″>
  <param name=”displaytoolbar” value=”-1″>
  <param name=”displayverticalscrollbar” value=”-1″>
  <param name=”enableautocalculate” value=”-1″>
  <param name=”enableevents” value=”-1″>
  <param name=”moveafterreturn” value=”-1″>
  <param name=”moveafterreturndirection” value=”0″>
  <param name=”righttoleft” value=”0″>
  <param name=”viewablerange” value=”1:65536″>
</object>

3、发布。在office安装文件中查找msowc.cab文件,把该文件同时复制到web路径中,然后修改组件代码中的第一行,明确该文件的路径,如下:
<object classid=”clsid:0002e510-0000-0000-c000-000000000046″ id=”spreadsheet1″ codebase=”msowc.cab” width=”599″ height=”490″>

效果图查看附件。

注:该嵌入excel组件可以客户端网页动态调整size,可进行数据计算及排序,但不能反写数据库,代码在office2000+win2000环境中通过。另外该代码在office2000及office2003中有所不同,因为所该代码调用office的owc组件,在office2003中该组件已经升级,所以如果客户端一般使用office2003的话,设计环境最好office2000+win2000环境,因为office2003可以向下兼容,如果设计环境采用office2003,但客户端安装office2000,则网页会无法显示,此时会提示安装office2003的owc组件,此组件可以office2003安装盘中提取。

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 把数据库查询信息直接生成网页嵌入EXCEL表的格式,并可导出成EXCEL文件-ASP教程,数据库相关
分享到: 更多 (0)