procedure Twonjang2F.SpeedButton10Click(Sender: TObject);
const
xlleft = -4131;
xlright = -4152;
xltop = -4160;
xlbottom = -4107;
xlline = 1;
xlbline = 9;
xlcenter = -4108;
var i, j, m_Ex_Row, m_Ex_Col: integer;
m_ExTitle, m_ExFile : string;
begin
IBCQuery1.Last;
if IBCQuery1.RecordCount <= 0 then Exit;
try
ExcelApplication1.Connect;
except
MessageDlg('Excel과 연결되지 않습니다.', mtError, [mbOk], 0);
Abort;
end;
m_ExFile := '임시화일';
m_ExTitle := '샘플자료';
try
ExcelApplication1.Caption := m_ExTitle;
ExcelApplication1.Workbooks.Add(xlWBATWorksheet,0);
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks.Item[1]);
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Sheets[1] as _Worksheet);
m_Ex_Row := IBCQuery1.RecordCount + 30;
m_Ex_Col := DBGrid1.Columns.Count;
with ExcelWorksheet1 do
begin
Range[Cells.Item[1,1], Cells.Item[m_Ex_Row,m_Ex_Col]].Font.Name := '굴림체';
Range[Cells.Item[1,1], Cells.Item[m_Ex_Row,m_Ex_Col]].Font.Bold := False;
Range[Cells.Item[1,1], Cells.Item[m_Ex_Row,m_Ex_Col]].Font.Size := 10;
Range[Cells.Item[1,1], Cells.Item[m_Ex_Row,m_Ex_Col]].VerticalAlignment := xlcenter;
Range[Cells.Item[1,1], Cells.Item[m_Ex_Row,m_Ex_Col]].NumberFormatLocal := '@';
Range[Cells.Item[1,1],Cells.Item[1,m_Ex_Col]].MergeCells := True;
Cells.Item[1,1] := m_ExTitle;
Cells.Item[1,1].HorizontalAlignment := xlcenter;
Range[Cells.Item[2,1],Cells.Item[2,m_Ex_Col]].MergeCells := True;
Cells.Item[2,1] := '기간 : ' + DateToStr(DateTimePicker1.Date) + ' - ' + DateToStr(DateTimePicker2.Date);
Cells.Item[2,1].HorizontalAlignment := xlleft;
for i := 1 to m_Ex_Col do
begin
Cells.Item[4,i] := DBGrid1.Columns[i-1].Title.Caption;
Range[Cells.Item[4,1], Cells.Item[4,m_Ex_Col]].HorizontalAlignment := xlcenter;
if DBGrid1.Columns[i-1].Alignment = taRightJustify then
Range[Cells.Item[5,i], Cells.Item[m_Ex_Row,i]].HorizontalAlignment := xlright;
if DBGrid1.Columns[i-1].Alignment = taLeftJustify then
Range[Cells.Item[5,i], Cells.Item[m_Ex_Row,i]].HorizontalAlignment := xlleft;
if DBGrid1.Columns[i-1].Alignment = taCenter then
Range[Cells.Item[5,i], Cells.Item[m_Ex_Row,i]].HorizontalAlignment := xlcenter;
end;
IBCQuery1.First;
i := 5;
while not IBCQuery1.Eof do
begin
for j := 1 to m_Ex_Col do
begin
Cells.Item[i,j] := DBGrid1.Fields[j-1].Value;
end;
i := i + 1;
IBCQuery1.Next;
end;
if not DirectoryExists(jesmain.m_excelpath) then CreateDir(jesmain.m_excelpath);
m_ExFile := jesmain.m_excelpath + m_ExFile + '.xls';
if fileexists(m_ExFile) then deletefile(pchar(m_ExFile)) ;
SaveAs(m_ExFile);
ExcelApplication1.Disconnect;
ExcelApplication1.Quit;
MessageDlg(m_ExFile+'로 저장되었습니다.', mtConfirmation, [mbOk], 0) ;
end;
except
on E: Exception do
begin
ShowMessage(E.Message);
ExcelApplication1.Disconnect;
ExcelApplication1.Quit;
end;
end;
지금까지 보통 위와같이 엑셀로 전환시키곤 했는데 여기서 새로운 시트들을 추가해서 자료들을 분류별로 전환하고자 합니다...
그런데 시트추가를 어떻게 하는지 방법을 모르겠습니다...ㅜㅠ
사용자 선택에 따라 시트추가수가 달라지기는 하지만 다중으로 시트를 추가할 수 있는 방법이...
수고하십시요...^^
|