保存为excel时,怎么会出现这么怪的问题??在线等!!!!!!!!
有这样的表:
学号,姓名,性别,文化程度。
将它保存为excel时,学号和姓名被放在最后去了
excel数据为:
性别,文化程度,学号,姓名
咋个回事?急!!!
代码如下:
string ls_temp = ""
// 创建一个 datastore 以存贮 dw_1 中各列的信息
datastore ds_col
ds_col = create datastore
ds_col.dataobject = "Dw_SaveToExcel_Columns"
ds_col.SetTransObject(sqlca)
SetPointer(HourGlass!)
// 记录 dw_1 中的对象数目
string l_objects, l_name, l_type, l_band, l_visible, l_objtype
string l_zw, l_objzw
long i, j, pp, l_x
l_objects = dw_1.Describe("DataWindow.Objects")
// 将 DETAIL 区域内的所有可见目标放到 ds_col 中,
// 并按照 object.x 属性大小排序
do while len(l_objects) > 0
pp = pos(l_objects, "~t")
if pp <= 0 then pp = len(l_objects) + 1
l_name = left(l_objects, pp - 1) // Object 名字
l_objects = mid(l_objects, pp + 1, len(l_objects))
l_type = upper(dw_1.Describe(l_name + ".coltype")) // Object 数据类型
if pos(l_type, "(") > 0 then
l_type = left(l_type, pos(l_type, "(") - 1 )
end if
l_x = long(dw_1.Describe(l_name + ".x")) // Object X 坐标
l_band = upper(dw_1.Describe(l_name + ".Band")) // Object 所属区域
l_visible = dw_1.Describe(l_name + ".visible") // Object 是否可见
l_objtype = upper(dw_1.Describe(l_name + ".Type")) // Object 类别
// 如果 object 在 Detail 区,且可见,并且是 column 或 Compute Column
if l_band = "DETAIL" and l_visible = "1" and &
( l_objtype = "COLUMN" or l_objtype = "COMPUTE" ) then
l_objzw = l_name + "_t" // Object 中文标头
l_zw = dw_1.describe(l_objzw + ".text")
// 去掉标头中多行之间的换行符
pp = Pos(l_zw , "~n")
Do While pp > 0
l_zw = Replace(l_zw, pp - 1, 2, "")
pp = Pos(l_zw , "~n")
Loop
// 去掉标头中多行之间的空格
pp = Pos(l_zw , " ")
Do While pp > 0
l_zw = Replace(l_zw, pp , 1, "")
pp = Pos(l_zw , " ")
Loop
// 去掉标头中多行之间的引号
pp = Pos(l_zw , '"')
Do While pp > 0
l_zw = Replace(l_zw, pp , 1, "")
pp = Pos(l_zw , '"')
Loop
i = ds_col.insertrow(0)
ds_col.setitem(i, "colname", l_name )
ds_col.setitem(i, "x", l_x )
ds_col.setitem(i, "coltype", l_type )
ds_col.setitem(i, "coltitle",l_zw )
ds_col.setitem(i, "objtype", l_objtype )
end if
loop
ds_col.sort()
// 将 dw_1 中的内容输出到 ds_tmp 中
datastore ds_tmp
ds_tmp = create datastore
ds_tmp.dataobject = "Dw_SaveToExcel"
ds_tmp.settransobject(sqlca)
string l_value, l_colname
long row
for i = 1 to dw_1.rowcount()
row = ds_tmp.insertrow(0)
for j = 1 to ds_col.rowcount()
l_type = upper(ds_col.object.coltype[j])
l_colname = ds_col.object.colname[j]
l_objtype = ds_col.object.objtype[j]
// 如果 dw_1 中某对象是 column 对象,则利用 Describe("evaluate ...
// 语法取出其当前显示信息。对 Edit、EditMask、DropDownDatawindow、
// DropDownListBox、CodeTable等风格均适用
if l_objtype = "COLUMN" then
l_value = dw_1.Describe("Evaluate('LookupDisplay(" + l_colname + ")'," + string(i) + ")")
else
// 对于 Compute 对象,利用前述方法会出错
choose case l_type
case "CHAR"
l_value = dw_1.GetItemString(i, l_colname )
case "DATE"
l_value = string( dw_1.GetItemDate(i, l_colname) , "yyyy.mm.dd")
case "DATETIME"
l_value = string( dw_1.GetItemDateTime(i, l_colname) , "yyyy.mm.dd")
case "INT","LONG", "NUMBER", "REAL", "UNLONG", "DECIMAL"
l_value = string( dw_1.GetItemNumber(i, l_colname) )
case "TIME", "TIMESTAMP"
l_value = string( dw_1.GetItemTime(i, l_colname) )
end choose
end if
if len(l_value) > 60 then
messagebox("提示","“" + l_value + "”超过了 60 个字符,系统将截短该项!" )
l_value = left(l_value, 60)
end if
l_colname = "A" + trim(string(j))
ds_tmp.setitem(row, l_colname, l_value)
next
next
// 插入表头
if ds_tmp.rowcount() >= 1 then
row = ds_tmp.insertrow(1)
else
row = ds_tmp.insertrow(0)
end if
for j = 1 to ds_col.rowcount()
l_value = ds_col.object.coltitle[j]
l_colname = "A" + trim(string(j))
ds_tmp.setitem(row, l_colname, l_value)
next
ds_tmp.SaveAs(filename, Excel!, false)
messagebox("提示","输出成功!")
destroy ds_tmp
SetPointer(Arrow!)
return true
dw_savetoexcel包含:A1,A2,A3,A4,A5,A6等等
dw_savetoexcel_columns包含:colname,x,coltype,coltitle,objtype