Chinaunix首页 | 论坛 | 博客
  • 博客访问: 963616
  • 博文数量: 232
  • 博客积分: 10010
  • 博客等级: 上将
  • 技术积分: 2315
  • 用 户 组: 普通用户
  • 注册时间: 2005-11-02 11:43
文章分类

全部博文(232)

文章存档

2009年(6)

2008年(22)

2007年(72)

2006年(85)

2005年(47)

我的朋友

分类:

2007-03-09 17:56:57

以前在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 "


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

"

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

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

Print {Content-type:application/vnd.ms-excel}
Print {Content-Disposition:attachment;filename=excelData.xls}
Print {<
META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=gb2312">}

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

"
 Print "


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

"

 

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

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

 



阅读(1588) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~