当前位置:数据库 > SQLServer >>

将DW数据窗口导出为EXCEL文件的方法(整理)

答案:

本文为摘自CSDN论坛帖子收集整理后汇总版本:

---2004年9月3日整理

---原贴见:

http://community.csdn.net/Expert/topic/3328/3328715.xml?temp=8.050799E-04

鉴于现在很多朋友询问 pb 数据导出到excel 中的问题,导出去后格式和数据
类型不对了,自己写了几个用户对象,
希望能抛砖引玉,加强技术交流,得到大家的支持。

1. nvo_excel 只要是两个接口函数
导出数据存储的数据,可以定义 excel 的标题
public function integer uf_toexcel (datastore ads_data, readonly string as_title)

导出数据窗口的数据,可以定义 excel 的标题
public function integer uf_toexcel (datawindow adw_data, readonly string as_title)

2. 下面是两个用户对象的 sru 文件,自己导入到工程中
$PBExportHeader$uo_ds_base.sru
$PBExportComments$数据存储基类
forward
global type uo_ds_base from datastore
end type
end forward

global type uo_ds_base from datastore
string dataobject = "d_expression"
end type
global uo_ds_base uo_ds_base

forward prototypes
public function any uf_getitemvalue (long al_row, string as_colname)
public function string uf_about ()
public function string uf_globalreplace (string as_source, string as_old, string as_new)
end prototypes

public function any uf_getitemvalue (long al_row, string as_colname);
//*************************************************//
//function : 得到任意的列的值
//parm     :
//         1. al_row       : 指定行
//         2. as_colname   : 指定列的列名
//return   : -1 is fail or success is value to you
//author   : hzh
//date     : 2002.11.05
//************************************************//

 

String s_tempcoltype
any a_ret
s_tempcoltype = Lower(THIS.Describe(as_colname + ".coltype"))

//for string type
IF Left(s_tempcoltype,4) = "char" OR Left(s_tempcoltype,4) ="varc"then
 a_ret = THIS.GetItemString(al_row,as_colname)
END IF 

//for decimal type
IF Left(s_tempcoltype,7) = "decimal" then
 a_ret = THIS.GetItemDecimal(al_row,as_colname)
END IF

//for date type
IF s_tempcoltype = "date" THEN
 a_ret = THIS.GetItemDate(al_row,as_colname)
END IF

 //for datetime type
IF s_tempcoltype = "datetime" THEN
 a_ret = THIS.GetItemDateTime(al_row,as_colname)
END IF

//for number type
IF s_tempcoltype = "number" THEN
 a_ret = THIS.GetItemNumber(al_row,as_colname)
END IF

//for time type
IF s_tempcoltype = "time" THEN
 a_ret = THIS.GetItemTime(al_row,as_colname)
END IF

//for timestamp type
IF s_tempcoltype = "timestamp" THEN
 a_ret = THIS.GetItemTime(al_row,as_colname)
END IF

//for int or long
IF s_tempcoltype = "int" OR s_tempcoltype = "long" THEN
 a_ret = THIS.GetItemnumber(al_row,as_colname)
END IF

IF IsNull(a_ret) THEN
 RETURN -1
END IF

RETURN a_ret
 
end function

public function string uf_about ();
string s_func = ""

s_func = " 1. 求得表达式的值 (uf_evaluate) " +&
   " 2. 根据 SQL ,创建数据存储 (uf_setsqlselect) ~r~n " +&
   " 3. 得到任意列的值(uf_getitemvalue) ~r~n "
  
//s_func += SUPER :: uf_about()

  
RETURN "uo_ds_base object member's functions : ~r~n" + s_func


end function
public function string uf_globalreplace (string as_source, string as_old, string as_new);
//**************************************************************//
//function                 : 用指定的字符串替换指定字符串
//parm                     :
//         1. as_source    : 原来的字符串
//         2. as_old       : 将要被替换的字符串
//         3. as_new       : 用来替换的字符串
//return   : 新的字符串
//author   : hzh
//date     : 2002.11.14
//*************************************************************//

Long     l_newlen, l_oldlen, l_start
String   s_null, s_source


IF IsNull(as_source) OR IsNull(as_old) OR IsNull(as_new) THEN
 SetNull(s_null)
 RETURN s_null
ELSE
 l_oldlen = Len(as_old)
 l_newlen = Len(as_new)
 as_Old = Lower(as_old)
 s_Source = Lower(as_source)
END IF

l_start = Pos(s_source, as_old)

DO WHILE l_start > 0
 as_source = Replace(as_source, l_start, l_oldlen, as_new)
 s_source = Lower(as_Source)
 l_start = Pos(s_source, as_old, (l_start + l_newlen))
LOOP


RETURN as_source

end function
on uo_ds_base.create
call super::create
TriggerEvent( this, "constructor" )
end on

on uo_ds_base.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on

-----------------------------------------------------------------


$PBExportHeader$nvo_excel.sru
$PBExportComments$和 excel 通讯的功能函数
forward
global type nvo_excel from nonvisualobject
end type
end forward

global type nvo_excel from nonvisualobject
end type
global nvo_excel nvo_excel

type prototypes
Private:
 Function uint GetModuleFileNameA(ulong hModule,ref string lpFilename,ulong nSize) Library "kernel32.dll"
end prototypes

type variables

Private:
//存储要导出的数据
uo_ds_base ids_data

//列名
String is_columnname[]

//列的标题
String is_columntitle[]

//列的显示格式
String is_columnformat[]

//列的类型
String is_columntype[]
end variables

forward prototypes
public function integer uf_toexcel (datastore ads_data, readonly string as_title)
public function integer uf_toexcel (datawindow adw_data, readonly string as_title)
private function integer uf_setdatasource (datawindow adw_data)
private function integer uf_setdatasource (datastore ads_data)
private function integer uf_datatoexcel (string as_title)
public function string uf_about ()
private function integer uf_initcolumn ()
end prototypes

public function integer uf_toexcel (datastore ads_data, readonly string as_title);

/**********************************************************/
//Function                 : 转换数据到 excel
//parm                     :
//        1. ads_data      : 包含源数据的对象
//        2. as_title      :  excel 的标题
//return                   : 1 is success and -1 is fail
//Author                   : hzh
//date                     : 2003.12.08
/**********************************************************/

IF THIS.uf_setdatasource(ads_data) <> 1 THEN RETURN -1

IF NOT IsValid(ids_data) THEN RETURN -1

IF ids_data.RowCount() < 1 THEN RETURN -1

THIS.uf_initcolumn()

THIS.uf_dat

上一个:创建iAS10g Report Server Cluster
下一个:关于shared pool的深入探讨(四)

Oracle
MySQL
Access
SQLServer
DB2
Excel
SQLite
SYBASE
Postgres
如果你遇到数据库难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,