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

看了精华区中众多处理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="<html xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns
="http://www.w3.org/TR/REC-html40">

<head>
<style type="text/css">
<!--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;}
-->
</style>
</head>

<body>
<!--[if gte mso 9]><xml>
<x:ExcelWorkbook>
  <x:ExcelWorksheets>
   <x:ExcelWorksheet>
    <x:OWCVersion>9.0.0.2710</x:OWCVersion>
    <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'>
     <x:Caption>返工处理日报表-产成品出入库报表-<%=trim(rs_stock("fname"))%>(<%=sdate%>至<%=edate%>)</x:Caption>
    </x:Label>
    <x:Name>Sheet1</x:Name>
    <x:WorksheetOptions>
     <x:Selected/>
     <x:Height>12965</x:Height>
     <x:Width>13996</x:Width>
     <x:TopRowVisible>0</x:TopRowVisible>
     <x:LeftColumnVisible>0</x:LeftColumnVisible>
     <x:ProtectContents>False</x:ProtectContents>
     <x:DefaultRowHeight>315</x:DefaultRowHeight>
     <x:StandardWidth>2389</x:StandardWidth>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
  </x:ExcelWorksheets>
  <x:MaxHeight>80%</x:MaxHeight>
  <x:MaxWidth>80%</x:MaxWidth>
</x:ExcelWorkbook>
</xml><![endif]
-->

<table class=wc01F2F7A x:str>
<col class=wc01F2F7A width="86" style='mso-width-source:userset'>
<col class=wc01F2F7A width="112" style='mso-width-source:userset'>
<col class=wc01F2F7A width="66" style='mso-width-source:userset'>
<col width="83" style='mso-width-source:userset'>
<col width="56">
<col width="82" style='mso-width-source:userset'>
<tr height="21" style='mso-height-source:userset'>
  
<td class=wc01F2F7A>返工处理日报表-产成品出入库报表-<%=trim(rs_stock("fname"))%><%=sdate%><%=edate%></td>
  
<td class=wc01F2F7A></td>
  
<td class=wc01F2F7A></td>
  
<td></td>
  
<td></td>
  
<td></td>
</tr>
<tr height="21" style='mso-height-source:userset'>
  
<td class=wc01F2F7A>仓库名称:</td>
  
<td class=wc01F2F7A><%=trim(rs_stock("fname"))%></td>
  
<td class=wc01F2F7A>统计日期:</td>
  
<td><%=cstr(sdate)%></td>
  
<td class=wc0EA6F7A></td>
  
<td><%=cstr(edate)%></td>
</tr>
<tr height="21" style='mso-height-source:userset'>
  
<td class=wc80A6909>物料短代码</td>
  
<td class=wc80A6909>物料长代码</td>
  
<td class=wc80A6909>物料名称</td>
  
<td class=wc80A6909>返工转出</td>
  
<td>即时库存</td>
  
<td></td>
  
<td></td>
</tr>
<%
'开始数据库取数过程
do while not rs_item.EOF%>
<tr height="21" style='mso-height-source:userset'>
  
<td class=wc01F2F7A><%=rs_item("FshortNumber")%></td>
  
<td class=wc01F2F7A><%=rs_item("FNumber")%></td>
  
<td class=wc01F2F7A><%=rs_item("FName")%></td>
  
<td class=wc01F2F7A x:num="<%=round(qty_out,rs_item("FQtyDecimal"))%>"></td>
  
<td class=wc01F2F7A x:num="<%=round(kc_now,rs_item("FQtyDecimal"))%>"></td>
  
<td></td>
  
<td></td>
</tr>
<%rs_item.MoveNext
loop%>
</table>

</body>

</html>
">
  
<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安装盘中提取。

申明

非源创博文中的内容均收集自网上,若有侵权之处,请及时联络,我会在第一时间内删除.再次说声抱歉!!!

博文欢迎转载,但请给出原文连接。

原文地址:https://www.cnblogs.com/Athrun/p/1126271.html