Q&A

  • sql -> 엑셀 . 엑셀은 열리는데 뻗어버려서. (소스포함)
엑셀 파일은 열리는데 그 후로 뻗어버리고 진행이 안됩니다.
델파이 초보라..^^:

뭐가 문제일까요?

낼까지해야되는데 큰일이네요 ㅠ ㅠ

procedure TUfrmMain.Query_Data(Sender: TObject) ;
var
   i               : Integer;
   sSQL1           : String;
   Index, Row, Column: Integer;
   lcid: integer;


begin


try
        ExcelApplication1.Connect;
    except
        MessageDlg('Excel may not be installed', mtError, [mbOk], 0);
        Abort;
    end;

    lcid := GetUserDefaultLCID;
     ExcelApplication1.Visible[lcid] := True;
    ExcelApplication1.Caption := 'Excel Application';
    ExcelApplication1.Workbooks.Add(TOleEnum(xlWBATWorksheet), lcid);
    ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
    ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1] as _Worksheet);
    //ADOQuery1.Open;
    Row := 1;

  //  i := 0;
    sSQL1 := 'select subinventory, item, scan_qty '+
             ' from MES.ONHAND_GPACK_STOCK '+
             'where rownum < 10';

      dbQh.Open;

    qrySendHost.DatabaseName:=dbQh.DatabaseName;
    dbQh.StartTransaction;


qryP_Exam.sql.clear;

      qryP_Exam.close;
      qryP_Exam.sql.add(sSQL1);
      qryP_Exam.Open;

   while not(qryP_Exam.Eof) do
    begin
        Column := 1;
        for Index := 1 to qryP_Exam.FieldCount do
        begin
          ExcelWorksheet1.Cells.Item[Row,Column] := qryP_Exam.Fields[Index-1].AsString;
          Column := Column + 1;
        end;
      qryP_Exam.Next;
      Row := Row + 1;
    end;


        qryP_Exam.Close;

        dbQh.close;

   end;
2  COMMENTS
  • Profile
    bong bong 2004.07.30 21:03
  • Profile
    bong bong 2004.07.30 23:56
    이소스는 퀵레포트로 내용을 보여준후 Excel파일로 생성하는건데..
    참조가 되실지 모르겠네요..
    위에 잘 못 올린내용은 삭제 하겠습니다..죄송합니다..
    procedure TFormMgrCode_R1.tb_ExcelClick(Sender: TObject);
    const
       WS_Name    = '워크시트명';
    var
       celcnt,   // 엑셀의 col위치.
       rowcnt,   // 엑셀의 row위치.
       i :integer;
       lcid : integer;
    begin
       lcid := -1;
       try
          ExcelApplication1.Connect;
       except
          messagedlg('엑셀 프로그램이 존재하는지 점검하세요.', mtWarning,[mbYes], 0);
          abort;
          exit;
       end;

       // 엑셀로 보낼 제목.
       try
          lcid := GetUserDefaultLCID;
          ExcelApplication1.Visible[lcid]:= False;

          { Create a new workbook }
          { The TOleEnum cast in the next line just prevents compiler range warnings }
          WkBk.ConnectTo(ExcelApplication1.Workbooks.Add(TOleEnum(xlWBATWorksheet), lcid));
          WS.ConnectTo(WkBk.Worksheets[1] as _Worksheet);
          WS.Name := WS_Name;

          ExcelApplication1.ScreenUpdating[lcid] := False;

          { Using the Range object, you can enter one cell at a time ... }
    //      WS.Range['A1', 'A1'].EntireRow.Interior.Color := titlecolor;
          WS.Range['B1', 'B1'].Value := qrTitle.caption;
          with WS.Range['B1', 'B1'].Font do
          begin
             Size := 13;
             Name := 'Times New Roman';
             FontStyle := 'Bold';
          end;

          for i:=1 to sgFields.RowCount-1 do
          begin
             if sgFields.cells[0,i] = selvalue then
                Qry_Master.Fields[i-1].Visible := true
             else  Qry_Master.Fields[i-1].Visible := false;
          end;

          celcnt := 1;
          for i:=0 to Qry_Master.Fields.Count-1 do
          begin
             if not Qry_Master.Fields[i].Visible then continue;

             WS.Cells.Item[3, celcnt].value := Qry_Master.Fields[i].DisplayLabel;
             WS.Cells.item[3, celcnt].font.bold := true;
             inc(celcnt);
          end;

          rowcnt := 4;
          Qry_Master.first;
          while not  Qry_Master.eof do
          begin
             celcnt := 1;
             for i:=0 to Qry_Master.Fields.Count-1 do
             begin
                if not Qry_Master.Fields[i].Visible then continue;

                case Qry_Master.FieldByName(Qry_Master.Fields[i].FieldName).DataType of
                ftString, ftFixedChar, ftWideString :
                   WS.Cells.Item[rowcnt, celcnt].value := Qry_Master.Fields[i].AsString+#32;
                else WS.Cells.Item[rowcnt, celcnt].value := Qry_Master.Fields[i].AsString;
                end;

                inc(celcnt);
             end;

             Qry_Master.next;
             inc(rowcnt);
          end;

          showmessage('Transpert 완료');
       finally
          ExcelApplication1.Visible[lcid]:=True;
          ExcelApplication1.ScreenUpdating[lcid] := True;
       end;

    end;