PowerBuilder 将导出的EXCEL英文标题替换为汉字
/*************hy*****start*************/
/**将导出的EXCEL英文标题替换为汉字**/
long numcols,numrows,c,r
OLEObject xlapp,xlsub
int ret,ll_cnt
numcols = long(tab_1.tabpage_2.dw_2.Object.DataWindow.column.count)
numrows = tab_1.tabpage_2.dw_2.rowcount( )
//创建OLEObject实例
xlapp = CREATE OLEObject
//连接ole对象
ret = xlapp.ConnectToNewObject("excel.application")
if ret < 0 then
MessageBox("连接失败!","连接到EXCEL失败,请确认您的系统是否已经安装EXCEL!~r~n错误代码:"+string(ret))
xlapp.quit()
xlapp.disconnectobject()
Destroy xlapp
Destroy xlsub
return -1
end if
//打开Excel文件
xlapp.workbooks.open(docname)
//得到活动工作表的引用,改善程序性能
xlsub = xlapp.activeworkbook.worksheets[1]
string ls_colname,ls_text,ls_modistr,ls_col
//取字段名更改为对应的文本text值
for c=1 to numcols
ls_col="#"+string(c)+".name"
ls_colname=tab_1.tabpage_2.dw_2.describe(ls_col)
ls_modistr = ls_colname+"_t.text"
messagebox('',ls_modistr)
ls_text = string(tab_1.tabpage_2.dw_2.describe(ls_modistr))
xlsub.cells[1,c] = ls_text
next
xlapp.quit()
xlapp.disconnectobject()
Destroy xlapp
Destroy xlsub
/*************hy*****end*************/