//====================================================================================== // 函数: f_export_part //-------------------------------------------------------------------------------------- // 描述: (PB9)将datawindow中的指定列的数据导出(支持计算列的导出) //-------------------------------------------------------------------------------------- // 参数: // value datawindow adw //要导出数据的数据窗口 // value string as_cols //要导出的列,以逗号分隔 // (如:"col2,col1" ,表示导出adw中的col2和col1两列, // 即便在adw中col1列排在col2之前,导出后的excel表中 // col2列总是显示在前面) // readonly string as_path //excel文件的存储路径 // readonly boolean ab_title //是否导出标题 //-------------------------------------------------------------------------------------- // 返回: (None) //-------------------------------------------------------------------------------------- //====================================================================================== datastore lds dwobject dwo1, dwo2 string ls_objects, ls_col, ls_modify, ls_type, ls_syntax, ls_tables, ls_columns string col_type, ls_text int li, col_id = 0 long lx = 0, lw ls_objects = as_cols + "," as_cols = '' do while true li = pos(ls_objects, ',') if li <= 0 then exit ls_col = left(ls_objects, li - 1) ls_objects = mid(ls_objects, li + 1) if ls_col = '' then continue //取出来的列为空,则继续 if lower(adw.describe(ls_col + ".band")) <> 'detail' then continue //非detail域的,则继续 ls_type = lower(adw.Describe(ls_col + ".type")) if ls_type <> "column" and ls_type <> "compute" then continue //非column且非compute,则继续 col_type = lower(adw.describe(ls_col + ".ColType")) choose case col_type case 'timestamp' col_type = 'time' case 'numeric' col_type = 'decimal(7)' case 'char' col_type = 'char(255)' case else end choose ls_text = adw.describe(ls_col + "_t.text") lw = long(adw.describe(ls_col + ".width")); if lw = 0 then lw = 200 col_id ++ if ls_text = '!' or ls_text = '?' then ls_text = '' ls_tables += 'column=(type=' + col_type + ' updatewhereclause=yes name=' + ls_col + ' dbname="' + ls_col + '" )~r~n' ls_columns += 'text(band=header alignment="2" text="' + ls_text + '" border="0" color="33554432" x="' + string(lx) + '" y="8" height="76" width="' + string(lw) + '" html.valueishtml="0" name=' + ls_col + '_t visible="1" font.face="Arial" font.height="-9" font.weight="400" font.family="2" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912" ) ~r~n' ls_columns += 'column(band=detail id=' + string(col_id) + ' alignment="0" tabsequence=0 border="0" color="33554432" x="' + string(lx) + '" y="8" height="88" width="' + string(lw) + '" format="' + adw.describe(ls_col + ".width") + '" html.valueishtml="0" name=' + ls_col + ' visible="1" edit.limit=0 edit.case=any edit.focusrectangle=no edit.autoselect=yes edit.autohscroll=yes edit.imemode=0 font.face="Arial" font.height="-9" font.weight="400" font.family="2" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912" ) ~r~n' lx += lw + 4 as_cols += ls_col + ',' loop ls_syntax = 'release 9; ~r~n'+& 'datawindow(units=0 timer_interval=0 color=1073741824 processing=1 HTMLDW=no print.printername="" print.documentname="" print.orientation = 0 print.margin.left = 110 print.margin.right = 110 print.margin.top = 96 print.margin.bottom = 96 print.paper.source = 0 print.paper.size = 0 print.canusedefaultprinter=yes print.prompt=no print.buttons=no print.preview.buttons=no print.cliptext=no print.overrideprintjob=no print.collate=yes hidegrayline=no grid.lines=0 ) ~r~n'+& 'header(height=92 color="536870912" ) ~r~n'+& 'summary(height=0 color="536870912" ) ~r~n'+& 'footer(height=0 color="536870912" ) ~r~n'+& 'detail(height=104 color="536870912" ) ~r~n'+& 'table('+& ls_tables +& ' ) ~r~n'+& ls_columns +& 'htmltable(border="1" ) ~r~n'+& 'htmlgen(clientevents="1" clientvalidation="1" clientcomputedfields="1" clientformatting="0" clientscriptable="0" generatejavascript="1" encodeselflinkargs="1" netscapelayers="0" ) ~r~n'+& 'export.xml(headgroups="1" includewhitespace="0" metadatatype=0 savemetadata=0 ) ~r~n'+& 'import.xml() ~r~n'+& 'export.pdf(method=0 distill.custompostscript="0" xslfop.print="0" )' lds = create datastore lds.create(ls_syntax) ls_objects = as_cols do while true li = pos(ls_objects, ',') if li <= 0 then exit ls_col = left(ls_objects, li - 1) ls_objects = mid(ls_objects, li + 1) if ls_col = '' then continue //取出来的列为空,则继续 dwo1 = adw.object.__get_attribute(ls_col,true) dwo2 = lds.object.__get_attribute(ls_col,true) dwo2.primary = dwo1.Primary loop lds.saveas(as_path, excel!, ab_title) destroy lds
调用方法如下:
//将dw_1的zjm和address列导出到“c:/a.xls”,导的时候不导出标题栏 f_export_part(dw_1, 'zjm,address', "c:/a.xls", false)