Registriert seit: 25. Nov 2005
Ort: München
1.909 Beiträge
Delphi 2010 Professional
|
AW: Wissen welches Textfeld in welcher Zelle ist ? [VBA 2010]
30. Jul 2012, 18:11
Das hier liefert dir die untere, rechte Zelle.
Delphi-Quellcode:
function FindBottomRightCellOfShape(shape, workSheet : OleVariant) : OleVariant;
var
rightColumn,
bottomRow,
currentRange : OleVariant;
right,
bottom,
columnIndex,
rowIndex : Integer;
begin
right := Integer(shape.Left + shape.Width);
bottom := Integer(shape.Top + shape.Height);
rightColumn := Variants.Null;
bottomRow := Variants.Null;
result := Variants.Null;
for columnIndex := Integer(shape.TopLeftCell.Column) to workSheet.Columns.Count do
begin
currentRange := workSheet.Columns[columnIndex];
if (Integer(currentRange.Left) <= right)
and (Integer(currentRange.Left + currentRange.Width) >= right) then
begin
rightColumn := currentRange;
break;
end;
end;
if VarIsNull(rightColumn) then
exit;
for rowIndex := Integer(shape.TopLeftCell.Row) to workSheet.Rows.Count do
begin
currentRange := workSheet.Rows[rowIndex];
if (Integer(currentRange.Top) <= bottom)
and (Integer(currentRange.Top + currentRange.Height) >= bottom) then
begin
bottomRow := currentRange;
break;
end;
end;
if VarIsNull(bottomRow) then
exit;
result := workSheet.Application.Cells[bottomRow.Row, rightColumn.Column];
end;
Die Zellen in dem Bereich kriegst du so:
Delphi-Quellcode:
procedure UseThatTextShape(shape, bottomRightCell : OleVariant);
var
allCellsRange,
currentCell : OleVariant;
cellIndex : Integer;
begin
allCellsRange := shape.Application.Range[shape.TopLeftCell, bottomRightCell].Cells;
Writeln(shape.Name, ':');
Writeln(' TL: ', string(shape.TopLeftCell.Address));
Writeln(' BR: ', string(bottomRightCell.Address));
for cellIndex := 1 to allCellsRange.Count do
begin
currentCell := allCellsRange.Cells[cellIndex];
Writeln(' -> ', currentCell.Address);
end;
end;
Robert Giesecke I’m a great believer in “Occam’s Razor,” the principle which says:
“If you say something complicated, I’ll slit your throat.”
|
|
Zitat
|