[ 파워빌더.엑셀 - 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 농부지기
,

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

 

Long ll_ret

String ls_ret

String ls_string1

oleobject myoleobject

myoleobject = create oleobject

ll_ret = myoleobject.connecttoobject("c:\a.xls")

Messagebox("Result!",string(ll_ret))

myoleobject.Application.Visible = TRUE

// 쓰기

myoleobject.application.workbooks(1).worksheets(1).cells(1,1).value="Test"

// 읽기

ls_ret = myoleobject.application.workbooks(1).worksheets(1).cells(1,1).value

 

/* 추가 사항 */

//Excel File Open

myOleObject.WorkBooks.Open("c:\a.xls")

// Sheet Name

ls_string1 = myOleObject.sheets[1].Name

// Sheet 자동마춤

myOleObject.Worksheets[1].Columns.AutoFit

//읽기

ls_ret = myOleobject.application.workbooks(1).worksheets(1).Range( "A1" ).Value

//쓰기

myOleobject.application.workbooks(1).worksheets(1).Range( "A1" ).Value = 'Test'

// 시트의 이름을 지정

myoleobject.Sheets[1].Name = "Sheet명"

//저장

myoleobject.application.workbooks(1).Save()

//다른이름으로 저장

myoleobject.application.workbooks(1).SaveAs("c:\b.xls")

 

//새로열기

myoleobject.connecttonewobject("excel.application")

//파일열기

myoleobject.WorkBooks.Opentext('c:\tmpgoodef.xls')

//타이틀바 바꾸기

myoleobject.Application.caption = "My Excel"

 

// 첫번째 Row 선택후 처리

myoleobject.rows("1:1").select

//굵은글씨

myoleobject.selection.font.bold = true

//이탤릭으로

myoleobject.selection.font.italic = true

//글씨색

myoleobject.selection.font.Color = RGB (128,128,0)

//보더색

myoleobject.selection.Borders.Color = RGB (0,0,128)

//워드랩

myoleobject.selection.wraptext = true

//가로정렬

myoleobject.selection.horizontalalignment = true

//세로정렬

myoleobject.selection.verticalalignment = true

 

//상태바 표시

myoleobject.statusbar = " My Status"

//첫번째Row를 프린트시 반복으로 (헤더로 표시)

myoleobject.Activesheet.PageSetup.PrintTitleRows = "$1:$1"

 

//첫번째쉬트를 복사 - 자세한 내용은 엑셀도움말을 참조

myoleobject.Worksheets(1).copy

//저장없이 닫기

myoleobject.WorkBooks(1).Close(false)

//연결해제

myoleobject.DisConnectObject()

 

destroy myoleobject

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

oleExcel.ActiveWorkbook.saveas("파일명", 56)

56이면 97~2003용

51이면 2007용

 

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

선그리기...

OleExcel.application.workbooks[1].worksheets[1].Range('A4:D'+String(j)).Borders(1).LineStyle = 1

 

Posted by 농부지기
,

[ 파워빌더 Event - 강제로 Event 발생시키기  ]

 

☞   

 

1. 정의 : itemchanged, rowchanged 등 Event를 강제로 실행시키기

2. 방법1
    dw_detail.setfocus(
    dw_detail.setcolumn('productcode')
    dw_detail.settext(ls_productcode)
    dw_detail.accepttext()

    방법2
    dw_detail.EVENT itemchanged(row, dwo, ls_productcode)
    dw_detail.Trigger EVENT itemchanged(ll_j, dw_detail.object.productcode, ls_productcode)

 

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

파워빌더.Datawindow의 event강제 실행  (0) 2017.01.26
Posted by 농부지기
,

 [  ◎ Tab Page 이동 하기 ]     

 

☞   

 

1. 하나의 Tab에는 여러개의 Page를 추가할 수 있다.

   이때 Page를 추가 하면 필요에 따라서는 Properties에서 Page의 위치를
    자유롭게 이동시킬 수 있다.

2. 그런데

     AA Windows에 하나의 Tab과 5개의 Page가 존재 하고,
     BB는 위 AA Windows를 상속해서 BB Windows를 만들었을 경우
     이때 page1, page2, page3, page4, page5 로 지정된 Page 순서를
     Properties에서 이동시킬 수 없다.

     즉, 상속을 받은 Child는 page 순서를 변경할 수 없다. 경우에는

     해결방법 : Script에서 Dynamic하게 변경할 수 있다.

               tab_1.movetab(4,1);   //page4를 (1) 맨 앞쪽으로 이동켜라. 는 의미이다.

    참고, moveTab을 사용하였을 경우
          pageindex는  page4가 1이 되고, page1가 2, page2이 3, page3이 4, page5가 5 가 된다.
          즉, 실행시 Script로 page를 이동 시켰지만  최종page는 실행중에 눈에 보이는 index가 된다.

 

Posted by 농부지기
,