function TThreadXlsFile.GetLastCell_A(OleXls, Sheet: OleVariant): OleVariant;
// Get last cell's absolute index.
// uses CurrentRegion. by zeliard
var
ColCount: Integer;
RowCount: Integer;
begin
try
Sheet.Select;
ColCount := Sheet.Cells.CurrentRegion.Columns.Count;
RowCount := Sheet.Cells.CurrentRegion.Rows.Count;
Result := Sheet.Cells.Item[RowCount, ColCount];
end;
function TThreadXlsFile.GetLastCell_B(OleXls, Sheet: OleVariant): OleVariant;
// Get last cell's absolute index.
// uses ActiveCell. by Christian Ebenegger.
var
ColCount: OleVariant;
RowCount: OleVariant;
begin
try
// In order to know the dimension of the WorkSheet, i.e the number of rows
// and the number of columns, we activate the last non-empty cell of it.
Sheet.Cells.SpecialCells(xlCellTypeLastCell, EmptyParam).Activate;
// Get the value of the last row
RowCount := OleXls.ActiveCell.Row;
// Get the value of the last column
ColCount := OleXls.ActiveCell.Column;
// Assign the Variant associated with the WorkSheet to the Delphi Variant Matrix
Result := OleXls.Cells.Item[RowCount, ColCount];
except
end;
end;
function TThreadXlsFile.GetLastCell_C(OleXls, Sheet: OleVariant): OleVariant;
// Get last cell's absolute index.
// Uses UsedRange, Intersect. by 편무학.
var
LastCol: OleVariant;
LastRow: OleVariant;
SheetCells: OleVariant;
begin
try
SheetCells := Sheet.Range[Sheet.Range['A1'], Sheet.UsedRange];
LastRow := OleXls.Intersect(Sheet.Range['A:A'], SheetCells);
LastCol := OleXls.Intersect(Sheet.Range['1:1'], SheetCells);
Result := Sheet.Cells[LastRow.Rows[LastRow.Count].Row + 3,
LastCol.Columns[LastCol.Count].Column + 3];
except
end;
end;
안녕하세요. 엑셀파일을 불러와 DB에 저장을 하고 있는데요. for i := 0 to 1000 do begin .. .. .. end; 이렇게 1000 이란 row를 임의 주지않고 자동으로 엑셀파일의 끝 Rowcount를 가져 올 수는 없나요? 아시는분 답변 부탁드립니다.
최용일
•
2002.04.25 04:16
안녕하세요. 최용일입니다.
엑셀 쉬트의 마지막 셀을 얻는 함수입니다... 조금 수정해서 사용하세요...
...
전영민
•
2002.04.25 03:15
델파이가 아니라 vba로 예전에 개발했던중에서..
저도 마지막 row를 알 수가 없어서 for 대신에
whil...
엑셀 쉬트의 마지막 셀을 얻는 함수입니다... 조금 수정해서 사용하세요...
세개 함수 모두 같은 일을 하는데... 약간씩 차이가 있습니다...
function TThreadXlsFile.GetLastCell_A(OleXls, Sheet: OleVariant): OleVariant;
// Get last cell's absolute index.
// uses CurrentRegion. by zeliard
var
ColCount: Integer;
RowCount: Integer;
begin
try
Sheet.Select;
ColCount := Sheet.Cells.CurrentRegion.Columns.Count;
RowCount := Sheet.Cells.CurrentRegion.Rows.Count;
Result := Sheet.Cells.Item[RowCount, ColCount];
end;
function TThreadXlsFile.GetLastCell_B(OleXls, Sheet: OleVariant): OleVariant;
// Get last cell's absolute index.
// uses ActiveCell. by Christian Ebenegger.
var
ColCount: OleVariant;
RowCount: OleVariant;
begin
try
// In order to know the dimension of the WorkSheet, i.e the number of rows
// and the number of columns, we activate the last non-empty cell of it.
Sheet.Cells.SpecialCells(xlCellTypeLastCell, EmptyParam).Activate;
// Get the value of the last row
RowCount := OleXls.ActiveCell.Row;
// Get the value of the last column
ColCount := OleXls.ActiveCell.Column;
// Assign the Variant associated with the WorkSheet to the Delphi Variant Matrix
Result := OleXls.Cells.Item[RowCount, ColCount];
except
end;
end;
function TThreadXlsFile.GetLastCell_C(OleXls, Sheet: OleVariant): OleVariant;
// Get last cell's absolute index.
// Uses UsedRange, Intersect. by 편무학.
var
LastCol: OleVariant;
LastRow: OleVariant;
SheetCells: OleVariant;
begin
try
SheetCells := Sheet.Range[Sheet.Range['A1'], Sheet.UsedRange];
LastRow := OleXls.Intersect(Sheet.Range['A:A'], SheetCells);
LastCol := OleXls.Intersect(Sheet.Range['1:1'], SheetCells);
Result := Sheet.Cells[LastRow.Rows[LastRow.Count].Row + 3,
LastCol.Columns[LastCol.Count].Column + 3];
except
end;
end;
^^ 항상 즐코하세요...