看了精华区中众多处理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安装盘中提取。