[ 파워빌더.DataWindow - 합계 컬럼  ]

  

 

☞   

 

합계칼럼을 일일이 손으로 만들고 있길래 ..

쉽게 합계 칼럼을 일괄 자동생성하는 법을 알려 줬지요..

(무지 좋아 하더군요...)

혹시 모르시는 분들을 위해.. 조금이라도 편하시라고.. 올려봅니다

 

1)dw의 숫자로 된 칼럼이 여러개 주욱 옆으로 있다면...

아래 그림과 같이 숫자칼럼들만 마우스로 멀티 선택합니다..

(과목수, 수강료총액, 차감총액, 실제 수강료합...)

 

2) 툴바에서 Sum을 선택하면 summary 칸에 합계 컴퓨티드 칼럼이 주르륵 자동 생성됩니다.

(리포트 만들거나 할때 숫자칼럼 많은데 합계 생성하려면 힘들고 귀찮죠... 이럴때 유용하겠죠..)

 

 

3) 그런데 summary 밴드가 아닌 footer 에 만들고 싶은데 거긴 자동 생성 안되네요..

tabular 나 freeform dw는 그냥 마우스로 드래그해서 밴드를 옮기면 되지만

그리드는 밴드 이동이 안되는 군요... 이론..

그럼 저장하고 나가서 해당 dw를 마우스 우클릭 한 다음.. Edit Source 를 선택합니다.

(파빌 7 이하는 edit source가 없군요.. 그럼 export, import 하면 되겠죠..)

 

4) source에서  band=summary 를  footer 로 바꾸고 저장합니다..

 

 

5) 아래 그림 처럼 summary 에서 footer로 합계칼럼이 생성되었습니다.... 파빌은 역시 짱입니다..

 

 

 

☞  

 

  

 

Posted by 농부지기
,

[파워빌더.DataWindow - 계산하기 ]  

 

 

☞   현재Row와 이전row 값을 비교 후 sum

 


1. summary 에 computed field 를 만들고
2. sum( if ( pum[-1] = pum[0] , 0 , value ) for all )
 

☞  

 

  데이터 윈도우의 sum() 함수 expression 에서 자주 사용하는데요..

for range 뒤에 distinct 를 붙일 수 있더군요... ;

그렇게 하니까 그룹내에서 중복으로 값이 더해지는 걸 예방할 수 있더군요.

 

참고로 first() 함수도 있더군요...

 

다음은 헬프의 내용입니다.

 

Description

Calculates the sum of the values in the specified column.

열거된 컬럼의 값을 합하여 계산한다.

 

Syntax

Sum ( column { FOR range { DISTINCT { expres1 {, expres2  {, ... } } } } } )

Argument

Description

column

The column for which you want the sum of the data values.

Column can be the column name or the column number

preceded by a pound sign (#).

Column can also be an expression that includes a reference to the column. The data type of column must be numeric.

컬럼 타입은 반드시 숫자형이여야 하고, 컬럼명이 와도 되고, 컬럼번호가 와도 된다. 또는 표현식도 가능하다.

FOR range

 (optional)

The data to be included in the sum. For most presentation styles, values for range are:

ALL (Default)

The sum of all values in column.

resultset에 있는 해당 컬럼의 모든 값의 합

GROUP n  

The sum of values in column in the specified group.

Specify the keyword GROUP followed by

the group number:

for example, GROUP 1.

특정 그룹에 속한 값의 합

sum( column_name for group 1)

PAGE

The sum of the values in column on a page.

한 페이지 내에 있는 컬럼의 값의 합

sum( column_name for page)

CROSSTAB

 (Crosstabs only)

The sum of all values in column in the crosstab.

크로스탭에서만 사용가능하다. 크로스탭의 컬럼의 값의 합

GRAPH

(Graphs only)

The sum of values in column in the range specified for the Rows option of the graph.

그래프 데이터윈도우에서만 사용가능하다.

OBJECT

(OLE objects only)

 The sum of values in column in the range specified for the Rows option of the OLE object.

OLE 에서만 사용가능하다.

 

DISTINCT (optional)

Causes Sum to consider only the distinct values in column when determining the sum. For a value of column, the first row found with the value is used and other rows that have the same value are ignored. 

합계를 구할 때 컬럼내에서 중복되는 값을 제거하여 합계를 구한다. 동일한 값이 존재할 때, 첫번째 row의 값만 가져오고, 다른 row의 동일한 값은 무시한다.       

expresn  (optional)

One or more expressions that you want to evaluate to determine distinct rows. Expresn can be the name of a column, a function, or an expression.

값을 계산하기 위해서 사용하는 하나 또는 여러개의 표현식 내용은 distinct 의 조건으로 사용된다. 표현식은 컬럼명이나 함수, 또는 수식등을 사용할 수 있다.

예) sum(  컬럼명 for all distinct 컬럼명이나 함수, 수식)

 

 

Return value

The appropriate numeric data type. Returns the sum of the data values in column.

 숫자형타입 중 알맞은 형태가 리턴된다. integer 는 interger, decimal은 decimal...머..이렇다는 말인가보다.

Usage

If you specify range, Sum returns the sum of the values in column within range. If you specify DISTINCT, Sum returns the sum of the distinct values in column, or if you specify expresn, the sum of the values of column where the value of expresn is distinct.

For graphs and OLE objects, you do not select the range when you call the function. The range has already been determined by the Rows setting on the Data property page (the Range property), and the aggregation function uses that range. Settings for Rows include:

 

-         For the Graph or OLE presentation style, Rows is always All.

-         For Graph controls, Rows can be All, Page, or Group.

-         For OLE controls, Rows can be All, Current Row, Page, or Group. The available choices depend on the layer the control occupies.

 

NULL values are ignored and are not included in the calculation.

Not in validation rules or filter expressions    You cannot use this or other aggregate functions in validation rules or filter expressions.

 

Using an aggregate function cancels the effect of setting Retrieve Rows As Needed in the painter. To do the aggregation, a DataWindow object or report always retrieves all rows.


http://cafe.naver.com/pentaeduclub.cafe

 

Posted by 농부지기
,

[ 파워빌더.DataWindow - 컬럼 내용에 따른 width 조절  ] 

 

 

☞   

 

XPlistBar 소스를 보는 도중에...발견했습니다.

 

한번 적용해 보세요..

Tahoma 8 포인트 일경우 인데요..

 

Ceiling(LenA( 컬럼명 ) / 5 * 135 )

 

뒤에 135 숫자를 적절히 조정해 보시기 바랍니다

Posted by 농부지기
,

[ 파워빌더.DataWindow - 컬럼순서 변경  ]

  

 


순순하게 변경은 불가능
전부 visible = false하시고
순서대로 visible을 true 하시면됩니다.

Posted by 농부지기
,

[ 파워빌더.DataWindow - 컬럼 속성 변경  ]

  

☞   

 

1. BackGroundColor 변경  : dw_d1.Modify("컬럼명.Background.Color = '16777215'") //rgb(255,255,255)'")

2. lable 의   Text  변경 : dw_d1.Modify("title_game_header.Text = '원하는 값'")

3. 컬럼 type length 변경 : dw_d1.Modify("컬럼명.Edit.Limit = 5")

4. 컬럼 Visible     처리 : dw_d1.Modify("컬럼명.Visible = true")

5. 컬럼 bold 굵게 설정   : dw_d1.Modify ("컬럼명.font.Weight=700") ;   //700은 굵게,   400은 보통

6. 컬럼 Y 좌료    설정   : dw_d1.Modify("컬럼명.Ya = 500")

7. 컬럼 X 좌료    설정   : dw_d1.Modify("컬럼명.X = 500")

8. 컬럼 높이      설정   : dw_d1.Modify ("컬럼명.Height = 80")

9. This.SelectText(1, len(GetText() )

☞  

 

1. dw안에 컬럼 개수          : ll_col_cnt = Integer(dw_d1.Describe("datawindow.column.count"))

2. 컬럼 index 로 컬럼명 찾기 : ls_col_name = Upper(dw_d1.Describe ( "#"+String ( li_index ) + ".Name" ))

3. 컬럼 type 알아내기        : ls_type = dw_d1.Describe("컬럼명.ColType");

4. 컬럼 tag 값 얻기          : ls_tag  = dw_d1.Describe ( "#컬럼명.Tag" )

5. 컬럼 X 좌표 값 얻기       : X = Integer(dw_d1.Describe ( "컬럼명.X" ))

6. 컬럼 Y 좌표 값 얻기       : Y = Integer(dw_d1.Describe ( "컬럼명.Y" ))

☞  

 

컬럼 순서 알아 내기 : dw_d1.Object.DataWindows.Table.GridColumns

 


1. text lable에 값을 두 줄로 만들 기 : 한글~r한글 : 즉 ~r  를 삽입
2. 두 번째 방법으로 : text입력란에서 Ctrl + Enter를 치면 밑으로 내려감

 


1. EditMast.Mask 변경하기
   dw_d1.Object.part_rope_cnt.EditMask.Mask = "###";
   dw_d1.Object.part_rope_cnt.EditMask.Mask = "##.000";

2. Format 변경하기
   dw_d1.Object.part_rope_cnt_1.format = '##.000'
   dw_d1.Modify("part_rope_cnt_.format='##.000'");   //문자값은  Modify내부에  single quote 를 찍어야 됨
 
3. 컬럼 height 변경하기
   dw_d1.Modify ("part_cd.Height         = 80")

 

1. tabOrder 속성 변경
   dw_d1.SetTabOrder("part_rope_cnt", 20)

 


1. Detail band Height 조정하기
   dw_d1.SetDetailHeight (1, 99, 102)

 

해당 데이터윈도우의 Scrollvertical() 이벤트에 아래와 같이 스크립트를 기술해 주시면 됩니다.

===================================================================================

String ls_first, ls_last

String ls_page, ls_pagecount

// 각 화면의 첫번째 Row의 번호를 얻는다.

ls_first = dw_1.Object.Datawindow.FirstRowOnPage

// 각 화면의 마지막 Row의 번호를 얻는다.

ls_last  = dw_1.Object.Datawindow.LastRowOnPage

dw_1.Title = "Rows " + ls_first + " To " + ls_last

ls_page = dw_1.Describe("Evaluate('Page()'," + ls_last + ")")

// 전체 Page수를 얻는다.

ls_pagecount = dw_1.Describe("Evaluate('PageCount()'," + ls_last + ")")

st_page.text = "총 " + ls_pagecount + " 페이지중 " + ls_page + " 페이지"

 

 

dw_1.object.Data[row, 컬럼번호]

dw_1.object.컬럼.Primary.Current[row]

dw_1.object.컬럼.Primary[row]

그외....

해당 데이터윈도우 버퍼의 데이터를 모두 받는 건?

dw_1.object.data

 

두번째 행의 모든 값을 받는 건?

dw_1.object.data[2]

 

1행의 첫컬럼부터 2행의 두번째 컬럼까지 받는 건?

dw_1.object.data[1,1, 2, 2]

 

selectrow()함수를 이용해서 선택된 행을 모두 갖고 오는 건?

dw_1.object.Data.Selected

 

모든 행의 특정컬럼 값만 갖고 오는 거?

dw_1.object.컬럼
http://cafe.naver.com/pentaeduclub.cafe

 


DataWindow에서 값을 입력하다보면 'DataWinodw Error'라는 Title의 Message Box가 나타남
영어로 쓰여져있고 일반 End User들에게는 생소한 영문이라서 눈에 거슬렸는데
이 title을 원하시는 내용으로 변경하는 방법이 있다.
DataWindow attribute에는 Message.Title이란 것이 있다.
이부분을 수정하면 된다.
  dw_1.Modify("DataWindow.Mesage.Title = '입력오류'")
 

 

- Original : 초기 조회 값
IF ( column_name <>
column_name.Original, RGB(255, 0, 0), RGB(0, 0, 0))

 

Posted by 농부지기
,

[ 파워빌더.엑셀 - Import ]

 

 

 

☞   

 
OLEObject  excel

Integer    li_RetValue, li_rtn
Boolean    lb_sheet_rtn
Long       ll_cnt


excel = create OLEObject

li_rtn = excel.ConnectToNewObject("excel.application")
IF li_rtn <> 0 THEN
    MessageBox('Excel erro','can not run Excel Program')
    DESTROY excel
    RETURN 0
END IF

excel.WorkBooks.Open( "c:\mysheet.xls" )
excel.Application.Visible = false
excel.windowstate = 2 // 1 : Normal, 2 : Minimize, 3 : Maximize

lb_sheet_rtn = excel.worksheets(1).Activate
excel.Worksheets(1).Range("A1:E5000").Copy  //  copy to clipboard
ll_cnt = dw_1.importclipboard()
IF ll_cnt <= 1 THEN
    Messagebox("Inf", "Could not find .")
END IF

excel.Worksheets(1).Range("A10000:A10000").Copy  //reset clipboard
excel.Application.Quit
excel.DisConnectObject()
DESTROY excel

Posted by 농부지기
,

[ 파워빌더.엑셀 - Export 5 ]

 

 

☞   

 

 

요새 엑셀변환 문제로 테스트를 하다가 찾아낸 방법입니다.

(검색을 안 해봐서..-- 이미 올라와 있을지도..;;)

 

아래와 같이 적용하였을 경우 엑셀 전환 후 숫자필드의 자릿수 때문에 이상하게 보여지는 것도 해결이 가능하네요.

<?xml:namespace prefix = o />

 

String   s_FileDir, s_FileName

Integer  s_Result

 

s_Result = GetFileSaveName("Select File", s_FileDir, s_FileName, "Excel", "Excel Files (*.xls), *.xls")

 

If s_result <> 1 Then RETURN

 

dw_list.setredraw(false)

//dw내의 editmask가 설정이 되어 있지 않으면 문제 발생 – default로 지정되는 xxxxxxxxxxxxxxxxxx 로라도 선택이 되어 있어야 함.

String ls_mask[], ls_col[]

Long ll_i

 

ls_col[1] = 'sim_no'  //적용할 컬럼

ls_col[2] = 'phone_id'   //적용할 컬럼

 

For ll_i = 1 To Upperbound(ls_col)

           ls_mask[ll_i] = dw_list.describe(ls_col[ll_i] + ".editmask.mask")

           dw_list.Modify( ls_col[ll_i] + ".EditMask.Mask= '" + charA(28) + ls_mask[ll_i] + "'")         

Next

 

dw_list.saveasascii(s_FileDir)

 

//원래 상태의 editmask로 돌려놓음..

For ll_i = 1 To Upperbound(ls_col)

        dw_list.Modify( ls_col[ll_i] + ".EditMask.Mask= '"  + ls_mask[ll_i] + "'")  

Next

 

dw_list.setredraw(true)

Posted by 농부지기
,

[ 파워빌더.엑셀 - Export 4 ]

 

☞   

 

안녕하십니까?

 

엑셀 저장할 때 저장하고자 하는 파일이 열려있을 경우 저장이 안되거나 오류나서 죽는 현상이 있습니다.

 

그럴때 아래 스크립트를 추가하여 체크해 보십시오.

 

String  Ls_DocName, Ls_Named, Ls_FileFormat
Integer Li_Value, Li_FileNo

Ls_DocName=''
Ls_FileFormat='MS-Excel File Format (*.xls),*.xls'          // MS-Excel 저장

Li_Value = GetFileSaveName('Save File Name', Ls_DocName, Ls_Named, 'xls', Ls_FileFormat)

If Li_Value<>1 Then
 Return -1
End If

 

// 이부분에서 선택한 파일을 그냥 FileOpen()으로 열어봅니다.

// 현재 열려있다면

If FileExists(Ls_DocName) Then

Li_FileNo = FileOpen(Ls_DocName, StreamMode!, Write!, LockReadWrite!, Append!)
If Li_FileNo = -1 Or IsNull(Li_FileNo) Then
 MessageBox('확인', '선택하신 파일이 현재 열려있습니다. 열려진 파일을 닫고 작업하십시오.')
 Return -1
End If
FileClose(Li_FileNo)

End If

....(계속)

 

이것저것 많이 찾아보다(오후내내 헤멨다는..ㅋㅋ)가 발견했네요 ㅎㅎㅎ

 

더 좋은 방법이나 이 방법에 버그가 있다면 알려주세요~~제발~~~~ ^^

=============

2010-12-21

FileOpen()을 사용하면 파일이 없을 때 해당 파일을 생성시켜주는 작용을 합니다.

따라서 FileOpen()체크시 새로운 이름의 파일일경우 해당 파일이 생성되버리는 버그가 됩니다.

그게 빨간색 부분을 추가합니다.

Posted by 농부지기
,

[  ◎ Excel로 저장하는 방법(숫자 0 살리고, Sheet별 저장) ]     

 

 

☞   

 

아래 작성내용은 이미 카페에서 oleExcel..이용하여 Sheet별 저장방법, Cell의 특성 설정방법 등..많은 글들을 올리셨던 분들의 혼합본임을 밝혀 둡니다. 질문올렸던 내용들은 대부분 안되는 부분에 대해

올린글들이었기 때문에 혹여 저를 비롯한 초보자분들은 혼란스러워 하실 것 같아 올려봅니다.

큰 도움 주셨던 건우아빠님을 비롯한 많은 분들에게 감사드리며 올립니당 ~ (__)(--)

 

Excel로 입력되는 값 Text형식 지정 방법

*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

//먼저 지정하고자 하는 셀의 위치에 값을 지정해줍니다 : (1:일반),(2:텍스트),(3:날짜)
long Array1[], Array2[]
Array1[] = {1,1,1,2,2} //ex = {A,B,C,D,E} 라면..A,B,C는 일반형식(기본)이 되고 D,E는 텍스트형식이 됩니다.
Array2[] = {1,1,1,2,2} //엑셀에 값이 먼저 들어가기전에 형식지정을 먼저 해주어 ' 0 ' 값이 사라지는것을 막습니다.

 

OleObject oleExcel , oleQuery
long li_rc

 

//하나의 Excel에 저장하려는 datawindow name 과 .txt파일을 먼저 저장할 경로 지정
dw_main.SaveAs('c:\t1.txt', TEXT!, True)
dw_main.SaveAs('c:\t2.txt', TEXT!, True)

 

//이제 Excel 생성 - .txt로 생성한 파일을 Excel로 이동

oleExcel = Create OleObject
li_rc = oleExcel.ConnectToNewObject("excel.application")
IF li_rc <> 0 THEN
 MessageBox("Information!", "File Conversion Failed!")
 MessageBox('오류!', 'Excel을 구동하면서 오류가 발생했습니다.', stopsign!)
 Destroy oleExcel
 RETURN -1
end if

 

//Cell 형식 변경 - 0 (0값이 정상적으로 표현)

//숫자 0 그대로 표현되고 Cell도 문자열로 인식하여 왼쪽 정렬 상태
oleExcel.WorkBooks.Add()
oleExcel.ActiveWorkbook.Sheets.Add.Name = 't1'
oleQuery = oleExcel.ActiveWorkbook.Sheets('t1').QueryTables.Add('TEXT;c:\t1.txt'   , oleExcel.ActiveWorkbook.Sheets('t1').Cells(1,1) )
oleQuery.TextFileColumnDataTypes = Array1
oleQuery.refresh()

 

//Cell 형식 변경 - 1 (0값 표현 안되고, 문자열로 인식)

//숫자 0 표현 안되고, Cell만 문자열로 인식하여 왼쪽 정렬 상태 (단, 아래내용보다 표기가 간단해진다.)
//oleExcel.WorkBooks.Add()
//oleExcel.ActiveWorkbook.Sheets.Add.Name = 't1'
//oleExcel.ActiveWorkbook.Sheets('t1').Range("A:Z").NumberFormatLocal = "@"
//oleQuery = oleExcel.ActiveWorkbook.Sheets('t1').QueryTables.Add('TEXT;c:\t1.txt'   , oleExcel.ActiveWorkbook.Sheets('t1').Cells(1,1) )
//oleQuery.refresh()

 

//Cell 형식 변경 - 2 (0값 표현 안되고, 문자열로 인식)

//숫자 0 표현 안되고, Cell만 문자열로 인식하여 왼쪽 정렬 상태
//oleExcel.WorkBooks.Add()
//oleExcel.ActiveWorkbook.Sheets.Add.Name = 't1'
//oleQuery = oleExcel.ActiveWorkbook.Sheets('t1').QueryTables.Add('TEXT;c:\t1.txt'   , oleExcel.ActiveWorkbook.Sheets('t1').Cells(1,1) )
//oleExcel.application.workbooks(1).worksheets(1).Range( "D:D").select
//oleExcel.application.workbooks(1).worksheets(1).Range( "D:D").NumberFormatLocal = "@"
//oleExcel.application.workbooks(1).worksheets(1).Range( "E:E").select
//oleExcel.application.workbooks(1).worksheets(1).Range( "E:E").NumberFormatLocal = "@"

//oleQuery.refresh()


 //oleExcel.ActiveWorkbook.Sheets.Add.Name = 't2'
//oleQuery = oleExcel.ActiveWorkbook.Sheets('t2').QueryTables.Add('TEXT;c:\t2.txt'   , oleExcel.ActiveWorkbook.Sheets('t2').Cells(1,1) )
//oleQuery.refresh()


oleExcel.Application.Visible = True

*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

0번 예제는 0이 표시되고, 1번과 2번 예제는 왜 0이 표시 안되는지 보시면 아시겠지만..

Excel은 자료를 넣고난 이후에 형식지정을 해주느냐 자료를 넣기 이전에 형식지정을 해주느냐에 따라 표현되는 값이 틀려집니다.

 

계좌번호나 전화번호등의 정보를 입력받을 때, 처음부터 - 이라던가, 다른 문자열이 섞여들어간다면 상관없겠으나..

들어가면 안되는 경우나 입력받을때 숫자만 기입받는 경우에는 저런 문제가 생겨 버리게 되어 난감한 경우가 많이 생기게 되죠.

 

Excel에 저장하는 함수나 방법들을 여러가지 사용해 보았으나(경우에따라 다르겠지만), dw2xls를 이용하는 방법과 위처럼 아예 형식을

미리 지정해주고 시작하는 방법이 제일 안전하고 보기 좋은 것 같다는 생각이 드네요.

 

물론, 맨 앞자리에 숫자 0이 사라지지않게하기 위해서 datawindow에서 직접 Computed Field를 이용해서 표현식에 ' 라던가

특정 문자를 삽입하여 표기하는 방법도 있으나 여의치않은 상황이라면 저렇게 사용하는게 좋다고 생각하네요.

 

아, 참고로.. 여러개의 datawindow화면을 하나의 Excel에 Sheet별로 저장하는 방법이기도 합니다.

 

Test Version : 7.0.3.10009 Build

 

☞  

 

  

 

'파워빌더 > DataWindow (Excel)' 카테고리의 다른 글

파워빌더.엑셀 - Import  (0) 2017.01.26
파워빌더.엑셀 - Export 5  (0) 2017.01.26
파워빌더.엑셀 - Export 4  (0) 2017.01.26
파워빌더.엑셀 - Export 2  (0) 2017.01.26
파워빌더.엑셀 - Export 1  (0) 2017.01.26
Posted by 농부지기
,

[ 파워빌더.엑셀 - Export 2 ]

 

 

☞   

 

어느사이트인지는 모르겠는데.. 암튼   zingga1@netian.com 이분이 올려주신 내용이었습니다.

이분의 노고에 정말  감사드립니다.

 

------------------
* Global Externa Function 선언

FUNCTION UInt FindWindowA( Ulong className, string winName )  LIBRARY "user32.dll"
FUNCTION UInt SetFocus( int winHand )  LIBRARY "user32.dll"
FUNCTION boolean DeleteFileA(ref string filename) LIBRARY "Kernel32.dll"
------------------------------------------------------------------------------
//변수 선언
int object_count, object_index, object_max
string objects, object_name, object_list[], object_select, object_band, object_type
string detail_object_spec, detail_objects[], detail_object_labels, s_header, header_text[]
string s_trailer1, s_trailer1_object[], s_footer, s_footer_object[], s_footer_data
boolean object_visible, b_detail = false, b_trailer1= false, b_summury = false, b_footer = false
int i_trailer1_count = 0, i_detail_count = 0, i_footer_count = 0


//데이터윈도우의 모든 오브젝트를 읽어온다.
objects = dw_1.describe("Datawindow.Objects" )

int i_pos, i, i_target, j, i_target_row, i_row = 1

object_max = 1
i_pos = 1

//오브젝트들을 탭을 구분으로 하나씩 분리해 저장한다.
do while(true)
  i_target = pos(objects, '~t', i_pos)
if i_target = 0 then
 object_list[object_max] = mid(objects, i_pos, len(objects))
 exit
end if
  object_list[object_max] = mid(objects, i_pos, i_target - i_pos)
i_pos = i_target + 1
object_max++
loop

//각 오브젝트들이 속해 있는 밴드와 타입, visible여부를 알아내어서
//오브젝트의 갯수와 각 변수들에 저장을 한다.
for object_index = 1 to object_max
object_name = trim(object_list[object_index])
object_band = upper(dw_1.describe( object_name + ".band" ))
object_type = upper(dw_1.describe( object_name + ".type" ))
object_visible = dw_1.describe( object_name + ".visible" ) = "1"
  if object_visible then //보이는 오브젝트만 처리
 choose case object_band
  case "TRAILER.1" //그룹밴드
   b_trailer1 = true
   if (object_type = "COLUMN" or object_type = "COMPUTE" or object_type = "TEXT") then
          i_trailer1_count++
              s_trailer1_object[i_trailer1_count] = object_name
   end if
  case "DETAIL" //Detail 밴드
           if (object_type = "COLUMN" or object_type = "COMPUTE") then
              object_select = object_select + "/" + object_name
      i_detail_count++        
         end if
  case "FOOTER" //Footer 밴드
   b_footer = true
   if (object_type = "COLUMN" or object_type = "COMPUTE" or object_type = "TEXT") then
          i_footer_count++
              s_footer_object[i_footer_count] = object_name
   end if
   end choose
  end if
next

i_target = 0 ; i_pos = 1 ; object_max = 1

dw_1.SetRedraw(false)
//컬럼의 순서를 알아내기 위한 작업을 한다.
object_select = '1/1' + object_select
dw_1.modify("datawindow.selected= '" + object_select + "'")

object_select = dw_1.describe("datawindow.selected")

detail_object_spec = right(object_select, len(object_select) - 4)

detail_object_spec = detail_object_spec + '/'
dw_1.modify(" datawindow.selected=''")
dw_1.SetRedraw(true)


i_pos = 1
object_max = 1

//각 컬럼의 이름을 배치된 순서대로 다시 저장한다.
do while(true)
  i_target = pos(detail_object_spec, '/', i_pos)
if i_target = 0 then
 detail_objects[object_max] = mid(detail_object_spec,i_pos, len(detail_object_spec))
 exit
end if
  detail_objects[object_max] = mid(detail_object_spec,i_pos, i_target - i_pos)
i_pos = i_target + 1
object_max++
loop

//헤드에 있는 텍스트들의 text값을 저장한다.
for object_index = 1 to object_max
object_name = detail_objects[object_index]
if detail_object_labels <> '' then detail_object_labels = detail_object_labels + '~t'
 if dw_1.describe( object_name + "_t.visible" ) <> '!' then
  detail_object_labels = detail_object_labels + dw_1.describe(object_name + "_t.text")
 else
    detail_object_labels = detail_object_labels + "?"
 end if
next
//요기까지 detail 밴드의 화면상에 보이는 컬럼들만 detail_objects에 담는다.

detail_object_labels = detail_object_labels + "~r~n"

//엑셀과 연결 시작
oleobject export_object
uint excel_handle, excel_state
string excel_title

export_object = create oleobject

export_object.connecttonewobject("excel.application")

excel_title = export_object.Application.Caption

export_object.Application.Visible = True
excel_handle = FindWindowA( 0, excel_title )
SetFocus( excel_handle )

//파일작성
long row_count, start_row
string data_buffer, s_select, filename, s_syn, s_trailer1_data
int file_num, ii

filename = "c:\export.txt"
start_row = 1

row_count = dw_1.rowcount()
if row_count = 0 then Return

if fileexists(filename) then
DeleteFileA(filename)
end if

file_num = fileopen(filename, streammode!, write!, lockreadwrite!, append!)

//각 로우별로 데이터를 읽어서 파일에 기록한다.
for start_row = 1 to row_count
  s_select = string(start_row) + "/" + string(start_row) + "/" +detail_object_spec
 dw_1.modify(" Datawindow.selected = '" + s_select + "'")
   data_buffer = dw_1.describe("datawindow.selected.data") + "~r~n"
 if start_row = 1 then data_buffer = detail_object_labels + data_buffer
   if b_trailer1 then //그룹이 존재한다면
  i_target_row = dw_1.FindGroupChange(start_row, 1) - 1
    if i_target_row = start_row then
   for i = 1 to i_trailer1_count
     if upper(dw_1.describe( s_trailer1_object[i] + ".type" )) = "COMPUTE" then
      s_syn = dw_1.describe(s_trailer1_object[i] + ".expression")
              s_syn = dw_1.Describe("Evaluate('" + s_syn + "',"  + string(start_row) + ")")
              if i = 1 then
      for ii = 1 to i_detail_count - i_trailer1_count - 1
       s_trailer1_data = s_trailer1_data + '~t'
        next
      end if
      s_trailer1_data = s_trailer1_data + '~t' + s_syn 
      elseif upper(dw_1.describe( s_trailer1_object[i] + ".type" )) = "COLUMN" then
      s_syn = dw_1.Describe("Evaluate('LookUpDisplay(" + s_trailer1_object[i] + ") '," + &
                          string(start_row) + ")")
              if i = 1 then
       for ii = 1 to i_detail_count - i_trailer1_count - 1
        s_trailer1_data = s_trailer1_data + '~t'
       next
      end if
      s_trailer1_data = s_trailer1_data + '~t' + s_syn          
      elseif upper(dw_1.describe( s_trailer1_object[i] + ".type" )) = "TEXT" then
      s_syn = dw_1.Describe(s_trailer1_object[i] + ".text")
              if i = 1 then
       for ii = 1 to i_detail_count - i_trailer1_count - 1
        s_trailer1_data = s_trailer1_data + '~t'
       next
      end if
      s_trailer1_data = s_trailer1_data + '~t' + s_syn                 
      end if
     next
   data_buffer = data_buffer + "~r~n" + s_trailer1_data + "~r~n"
   end if
end if
filewrite(file_num, data_buffer)
setnull(data_buffer)
s_trailer1_data = ''
next

//Footer 밴드를 마지막으로 파일에 덧붙힌다.
if b_footer then
  for i = 1 to i_footer_count
    if upper(dw_1.describe( s_footer_object[i] + ".type" )) = "COMPUTE" then
     s_syn = dw_1.describe(s_footer_object[i] + ".expression")
       s_syn = dw_1.Describe("Evaluate('" + s_syn + "',"  + string(row_count) + ")")
         if i = 1 then
    for ii = 1 to i_detail_count - i_footer_count - 1
      s_footer_data = s_footer_data + '~t'
      next
     end if
   s_footer_data = s_footer_data + '~t' + s_syn 
    elseif upper(dw_1.describe( s_footer_object[i] + ".type" )) = "COLUMN" then
   s_syn = dw_1.Describe("Evaluate('LookUpDisplay(" + s_footer_object[i] + ") '," + &
                         string(row_count) + ")")
         if i = 1 then
    for ii = 1 to i_detail_count - i_footer_count - 1
      s_footer_data = s_footer_data + '~t'
      next
     end if         
     s_footer_data = s_footer_data + '~t' + s_syn          
    elseif upper(dw_1.describe( s_footer_object[i] + ".type" )) = "TEXT" then
   s_syn = dw_1.Describe(s_footer_object[i] + ".text")
         if i = 1 then
    for ii = 1 to i_detail_count - i_footer_count - 1
      s_footer_data = s_footer_data + '~t'
      next
     end if   
       s_footer_data = s_footer_data + '~t' + s_syn                 
    end if
  next
data_buffer = "~r~n" + s_footer_data
filewrite(file_num, data_buffer)
end if

fileclose(file_num)

export_object.statusbar = "Importing data...."
export_object.workbooks.opentext(filename)
export_object.windows("export.txt").caption = "Export Workbook"

//엑셀파일의 포맷을 실시한다.

//자동 칸맞춤을 적용한다.
export_object.Worksheets[1].Columns.AutoFit

//헤드 줄은 bold로 지정한다.
export_object.rows("1:1").select
export_object.selection.font.bold = true
export_object.selection.font.italic = false


export_object.statusbar = " Formatting labels....."
export_object.rows("1:1").select
//셀들의 줄맞춤을 실시한다.
export_object.selection.wraptext  = true
export_object.selection.horizontalalignment = true
export_object.selection.verticalalignment = true

//미리보기에서 헤드셀들은 반복되어 나타나게 한다.
export_object.Activesheet.PageSetup.PrintTitleRows = "$1:$1"

export_object.DisConnectObject() //연결종료
Destroy export_object //오브젝트 제거 

 

Posted by 농부지기
,