Listview de kayıtları excel aktarıyorum buraya kadar sorun yok, içeriğe göre satır rengi atama konusunda sıkıntım var;
örnek:
if Items.Item.SubItems[5] = 'ISTANBUL' then olan satır rengi kırmızı olsun, fakat SubItems ISTANBUL hangi satıra denk geleceğini bilemediğim için satır rengi atamasını nasıl yapabilirim acaba?
var col: Integer;
...
for i := 0 to Items.Count - 1 do
begin
for col := 0 to Columns.Count - 1 do
begin
if Items.Item[i].SubItems[col] = 'ISTANBUL' then
begin
ActiveSheet.Cells[Row, col + 2].Font.Color := clRed;
end;
Sheet.Cells[Row, col + 2] := Items.Item[i].SubItems[col];
end;
inc(Row);
end;
var col: Integer;
...
for i := 0 to Items.Count - 1 do
begin
for col := 0 to Columns.Count - 1 do
begin
if Items.Item[i].SubItems[col] = 'ISTANBUL' then
begin
ActiveSheet.Cells[Row, col + 2].Font.Color := clRed;
end;
Sheet.Cells[Row, col + 2] := Items.Item[i].SubItems[col];
end;
inc(Row);
end;
Hocam elinize sağlık, Row, 1 yaptığımda 1. kolon rengi değişiyor ancak diğer colonlarıda 2, 3, 4 ... 7 yapmak istediğimde bir türlü uyarlayamadım
Sheet.Cells[Row, 2] yaparsanız ikinci kolon olacaktır. Tek tek uğraşmak istemiyorsanız for döngüsü ile halledebilirsiniz.
for i=1 to 20 do Sheet.Cells[Row, i].Color := clRed; gibi
with Form1.ListView1 do
begin
for i := 0 to Items.Count - 1 do
begin
if Items.Item[i].SubItems[5] = 'İSTANBUL' then
begin
Excel.ActiveSheet.Cells[i, 1].Font.Color := clBlue;
// Sheet.Cells[row, i].Font.Color := clRed;
// Excel.ActiveSheet.Cells[Row, i].Font.Color := clBlue;
// Excel.ActiveSheet.Range['A15','a1:h1'].Font.Color := clBlue;
// Excel.Range['A8', 'h8'].Font.Color := clFuchsia;
end;