html网页集中转换成excel,一个Web页面转化成Excel的例子

以前在windows Domino 环境中的B/S应用操作EXCEL,相对来说,比较简单,只要操作系统上装了Office套件,利用LS+VBA就可以了。大致代码如下:

Dim obj As Variant

Dim apli As Variant

Set obj = CreateObject("Excel.Application")

Set apli = obj.Application

apli.Visible=True

Dim workb As Variant

Dim works As Variant

Set workb= apli.Workbooks.Add()

Set works = workb.Worksheets(1)

Call workb.Activate

Call works.Activate

With works

.Cells(1,1).Formula="=SUMA(E1:E2)"

End With

但是如果在AIX上操作的话,没法安装office套件,就没有Excel.Application,不能创建相应的对象,前几天看到用户利用html+print的方法将输出的信息转化为excel文件,操作起来也很简单,在这里与大家分享一下:

Print {Content-type:application/vnd.ms-excel}

Print {Content-Disposition:attachment;filename=excelData.xls}

Print "Hello, this is the LotusScript web agent. I've been triggered by the form's WebQuerySave event.

Now the UNID is

"

Print "测试1 /TD>测试1"

Print "

测试1测试1

"

这样就可以直接产生excel格式文件。这应该是HTML的一个语法的问题。

但是在使用的过程中发现EXCEL的字符集选项有时候会有变化,所以需要在代码中将字符集给固定下来。只需要增加一句就好了。如下:

Print {Content-type:application/vnd.ms-excel}

Print {Content-Disposition:attachment;filename=excelData.xls}

Print {}

Print "Hello, this is the LotusScript web agent. I've been triggered by the form's WebQuerySave event.

Now the UNID is

"

Print "测试1 /TD>测试1"

Print "

测试1测试1

"

好像还有一种作法,通过js,FSO去操作本地的文件系统,但是需要设置可信任站点,对本地客户端的设置会要求高一些。

var fso = new ActiveXObject("Scripting.FileSystemObject");

var f1 = fso.createtextfile("c:\\myjstest.xls",true");

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值