ASP生成execl如何控制单元格大小-合并单元格

dywu520 2013-01-29 03:36:57
set fs=Server.CreateObject("Scripting.FileSystemObject")
fpath=Server.MapPath ("../") & "\attend\tempreport"
set fo=fs.GetFolder(fpath & "\")
for each x in fo.files
'Print the name of all files in the folder
if fs.FileExists(fpath & "\" & x.Name) then
fs.DeleteFile fpath & "\" & x.Name
end if
next
flogname=fpath & "\" & tstamp & ".csv"
set fname=fs.CreateTextFile(flogname,true)

for i=1 to icount
fname.WriteLine(printform(i))
next
printform(1)="考勤报表"
printform(2)="1"&"2"&"3"
fname.Close
set fname=nothing
set fs=nothing
response.Redirect "tempreport/" & tstamp & ".csv"
response.end
set fo=nothing
set fs=nothing
我现在就是想将“考勤报表”用A1-C1合并单元格打印,1,2,3这几个数字的单元格大小缩小到2个数字的距离,目前我是一行一行的打印出来,但是单元格格式怎么设置呢?请高手帮忙解答一下,谢谢。
...全文
356 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
三楼の郎 2013-02-04
  • 打赏
  • 举报
回复
这是个.Net的,ASP里面用法一样
三楼の郎 2013-02-04
  • 打赏
  • 举报
回复

<% response.ContentType="application/vnd.ms-excel;charset=utf-8" %>

<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 11">
<link rel=File-List href="啊啊啊啊.files/filelist.xml">
<style id="啊啊啊啊_Styles">
<!--table
	{mso-displayed-decimal-separator:"\.";
	mso-displayed-thousand-separator:"\,";}
.font54864
	{color:windowtext;
	font-size:9.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;}
.xl154864
	{padding-top:1px;
	padding-right:1px;
	padding-left:1px;
	mso-ignore:padding;
	color:windowtext;
	font-size:12.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-number-format:General;
	text-align:general;
	vertical-align:middle;
	mso-background-source:auto;
	mso-pattern:auto;
	white-space:nowrap;}
.xl224864
	{padding-top:1px;
	padding-right:1px;
	padding-left:1px;
	mso-ignore:padding;
	color:windowtext;
	font-size:9.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-number-format:General;
	text-align:center;
	vertical-align:middle;
	border:.5pt solid windowtext;
	mso-background-source:auto;
	mso-pattern:auto;
	white-space:nowrap;}
.xl234864
	{padding-top:1px;
	padding-right:1px;
	padding-left:1px;
	mso-ignore:padding;
	color:windowtext;
	font-size:18.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-number-format:General;
	text-align:center;
	vertical-align:top;
	border-top:none;
	border-right:none;
	border-bottom:.5pt solid windowtext;
	border-left:none;
	mso-background-source:auto;
	mso-pattern:auto;
	white-space:nowrap;}
.xl244864
	{padding-top:1px;
	padding-right:1px;
	padding-left:1px;
	mso-ignore:padding;
	color:windowtext;
	font-size:12.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-number-format:General;
	text-align:center;
	vertical-align:top;
	border-top:none;
	border-right:none;
	border-bottom:.5pt solid windowtext;
	border-left:none;
	mso-background-source:auto;
	mso-pattern:auto;
	white-space:nowrap;}
ruby
	{ruby-align:left;}
rt
	{color:windowtext;
	font-size:9.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-char-type:none;}
-->
</style>
</head>

<body>
<!--[if !excel]>  <![endif]-->
<!--下列信息由 Microsoft Office Excel 的“发布为网页”向导生成。-->
<!--如果同一条目从 Excel 中重新发布,则所有位于 DIV 标记之间的信息均将被替换。-->
<!----------------------------->
<!--“从 EXCEL 发布网页”向导开始-->
<!----------------------------->

<div id="公积金开户明细情况表_4864" align=center x:publishsource="Excel">
<table x:str border=0 cellpadding=0 cellspacing=0 width=646 style='border-collapse:collapse;table-layout:fixed;width:485pt'>
 <col width=79 style='mso-width-source:userset;mso-width-alt:2528;width:59pt'>
 <col width=104 style='mso-width-source:userset;mso-width-alt:3328;width:78pt'>
 <col width=146 style='mso-width-source:userset;mso-width-alt:4672;width:110pt'>
 <col width=132 style='mso-width-source:userset;mso-width-alt:4224;width:99pt'>
 <col width=72 style='width:54pt'>
 <col width=113 style='mso-width-source:userset;mso-width-alt:3616;width:85pt'>
 <tr height=38 style='mso-height-source:userset;height:28.5pt'>
  <td colspan=6 height=38 class=xl234864 width=646 style='height:28.5pt;width:485pt'>啊啊啊啊</td>
 </tr>
 <tr height=24 style='mso-height-source:userset;height:18.0pt'>
  <td height=24 class=xl224864 style='height:18.0pt;border-top:none'>列1</td>
  <td class=xl224864 style='border-top:none;border-left:none'>列2</td>
  <td class=xl224864 style='border-top:none;border-left:none'>列3</td>
  <td class=xl224864 style='border-top:none;border-left:none'>列4</td>
  <td class=xl224864 style='border-top:none;border-left:none'>列5</td>
  <td class=xl224864 style='border-top:none;border-left:none'>列6</td>
 </tr>
<%
    	For xx as integer= 0 To 50
%> 
 <tr height=24 style='mso-height-source:userset;height:18.0pt'>
  <td height=24 class=xl224864 style='height:18.0pt;border-top:none'><%=xx%></td>
  <td class=xl224864 style='border-top:none;border-left:none'><%=xx%></td>
  <td class=xl224864 style='border-top:none;border-left:none'><%=xx%></td>
  <td class=xl224864 style='border-top:none;border-left:none'><%=xx%></td>
  <td class=xl224864 style='border-top:none;border-left:none'><%=xx%></td>
  <td class=xl224864 style='border-top:none;border-left:none'><%=xx%></td>
 </tr>
<% 
	Next
%> 
 <![if supportMisalignedColumns]>
 <tr height=0 style='display:none'>
  <td width=79 style='width:59pt'></td>
  <td width=104 style='width:78pt'></td>
  <td width=146 style='width:110pt'></td>
  <td width=132 style='width:99pt'></td>
  <td width=72 style='width:54pt'></td>
  <td width=113 style='width:85pt'></td>
 </tr>
 <![endif]>
</table>
</div>
<!----------------------------->
<!--“从 EXCEL 发布网页”向导结束-->
<!----------------------------->
</body>
</html>
现在还是人类 2013-02-02
  • 打赏
  • 举报
回复
其实我已经说得很清楚了的呀,建议你用Flish来处理这种东西,要不就在后台脚本生成xls文件,这样可以包含excel表格样式,你想通过后台生成简单的csv格式来实现的目的是不现实的,因为这需要前台脚本程序的控制支持,而前台脚本程序涉及到多浏览器的兼容性已经浏览器的安全设置,而这些对于web开发上来说是无法完全控制的,如果你的想法是在指定的环境运行你的程序,建议你用C/S架构会比你现在的B/S架构在环境上好很多,也容易很多,如果你的需求是面向真正Internet上的web用户,这就涉及到B/S架构的兼容性问题,最好的方案就是用Flish+AJAX实现这样的过程。
dywu520 2013-02-01
  • 打赏
  • 举报
回复
中间那些缩小的单元格不是固定的。
dywu520 2013-02-01
  • 打赏
  • 举报
回复
感谢1,2楼的解答。就像1楼说的是“FSO创建一个csv文件输出,估计是想目标浏览器直接用系统安装好的Excel打开该数据内容来打印吧”,在网页直接一个按钮导出EXECL。2楼说的好像是做个格式样板去调用它么?在网页直接打印execl可以直接调用模版吗?我试了好像不行啊,直接打印这么调用execl格式,在麻烦大侠们帮帮忙,十分感谢。
dywu520 2013-01-31
  • 打赏
  • 举报
回复
这么没人来啊。。来2个顶一下也好啊。能答的加分
三楼の郎 2013-01-31
  • 打赏
  • 举报
回复
1、用Excel做好样式 2、在Excel的菜单"文件-》另存为"里面另存成.htm格式文件 3、把这个生成出来的.htm文件的扩展名改成.asp 4、打开这个.asp文件,在文件的最前面加上<% response.ContentType="application/vnd.ms-excel;" %>这句 5、写脚本把数据读出来填到对应的位置
现在还是人类 2013-01-31
  • 打赏
  • 举报
回复
从ASP的角度看,ASP是服务器脚本,和打印没什么关系。 从你的标题看,你好象想操作 Excel 文件,但从你提供的代码上看,有没有 Excel 的影子。 从你后面的问题上看,好像是想搞浏览器的打印功能。 如果你的最终目的只是浏览器的打印功能,那你就好好研究打印这块,相对来说,在Flish里控制要答应的内容可以比较容易甚至精确的控制打印内容。对于浏览器脚本来说,可控性不是那么强也不那么方便。 如果你是想在服务器生成Excel文件,可以参考PHP中的一个可以操作Excel或Word文件模块,里面有具体的源码可以任意控制要生成的Excel文件内容,至于在ASP里引用Excel对象的方法,建议不要这么使用,因为这是WEB开发,可能有多人同时在进行该操作,而要在IIS中调用这种东西,会占用很大的资源,并且还要在安全、策略等各种地方配置,而却即使能用稳定性也不强,所以服务器要处理这类事物很少有人直接用这种组件或接口的。 还有,看你的代码应该是用FSO创建一个csv文件输出,估计是想目标浏览器直接用系统安装好的Excel打开该数据内容来打印吧,而且你还想控制其数据在Excel显示的样式好打印。但是,CSV文件只能记录数据,不能控制数据的显示样式,要控制样式这这能通过前台控制,服务器脚本是对于csv文件是没法控制前台样式的,除非你服务器脚本生成的是XLS文件才可以这么做,至于XLS文件就和我上面所说的一样,有两种方法可以处理,1个是Office的对象来控制,不过需要配置服务器才能调用,而且不稳定,2是自己了解XLS文件格式自己写类来控制,网上有php的相关模块可以供你下载参考,不过应为涉及的技术比较多,也是个不容易的事情。如果你的目的只是打印数据或显示数据,给你条捷径,就是去玩Flish的AS程序,这个容易满足你的需求,而且基本上没有很多的兼容性问题困扰。

2,503

社区成员

发帖
与我相关
我的任务
社区描述
VBA(Visual Basic for Applications)是Visual Basic的一种宏语言,是在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。
社区管理员
  • VBA
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧