![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
excel [D7, WinXP]
Sash © (2004-11-16 09:48:00)здравствуйте! я в тупике :)
копирую таблицы с одного листа на другой
кол-во таблиц - 10 штук, а идут они сверху вниз с разрывом в 2 строки. вот в чем проблема:
начинаю копировать (в цикле) первую таблицу, до появления пустой ячейки, и когда она появляется, действие останавливается, а мне надо сделать чтобы она искала следующую таблицу и скопировала нужные мне столбцы и строки
вот кусок кода:
m:=WB.Sheets.Count;
WB.Sheets.Add(,WB.Sheets[m],1,xlWorksheet)//добавлем новый лист
i:=3;
while not VarIsEmpty(WB.Sheets[alist].Cells.Item[i,1].Value) do Inc(i);
for j:=3 to i-1 do
begin
acol1:=WB.Sheets[alist].Cells[j,2].Value;
WB.Sheets[m+1].Cells[j+1,1].Value := acol1;//здесь alist-номер листа с которого копирую, m-количество листов в книге
.......
.......
.......
и так девять колонок
Скажите плиз, как это сделать?
Заранее благодарен всем кто откликнется!
Наиль (2004-11-17 11:06:00) [21]> Sash
Возможно мой совет не кстати, но разбраться с тем кодом, что дал достаточно сложно. Поэтому я переписал его начиная сif Alist1ChBox.Checked then. Код касающийся оформления у тебя закрывает суть программы. Так как, совет тебе уже успели дать, то могут предложить только оптимизированый текст программы
Const
cw:array[1..9] of integer =(12,0,10,12,10,26,13,20,20);
txt:array[1..9] of string = ('Направление','Попытки','Ответы, %',
'Неответы, %','Занято, %','Временная неисправность, %','Нет канала, %',
'Ошибка протокола, %','Ресурс недоступен, %');
nm:array[1..9] of integer =(2,5,6,8,9,10,11,17,19);
nm2:array[1..9] of integer =(0,0,45,15,25,1,1,1,1);
nm3:array[1..9] of integer =(0,0,6,38,37,44,46,42,10);
Var
z:real;
begin
// ...
With WB.Sheets[m+1] do Begin
With Cells[1,1] do Begin
Value:='Показатели нагрузки и качества обслуживания вызовов на ';
if Alist1ChBox.Checked then Value:=Value+Alist1ChBox.Caption;
if Alist2ChBox.Checked then Value:=Value+Alist2ChBox.Caption;
if Alist3ChBox.Checked then Value:=Value+Alist3ChBox.Caption;
Font.Bold:=True;
End;
For x:=1 to 9 do Begin
With Cells[3,x] do Begin
Value:=txt[x];
Borders.LineStyle:=1;
if x=2 then Continue;
ColumnWidth:=cw[x];
End;
End;
for j:=3 to i-1 do
begin
For x:=1 to 9 do Begin
acol:=WB.Sheets[alist].Cells[j,nm[x]].Value;
With Cells[j+1,x] do Begin
Value := acol;
Borders.LineStyle:=1;
z:=strtofloat(acol);
if x=3 then
if z<nm2[x] then Interior.ColorIndex:=nm3[x];
if x in [4..9] then
if z>nm2[x] then Interior.ColorIndex:=nm3[x];
End;
End;
end;
end;
end;
Gloomer (2004-11-17 10:24:00) [22]>[7] ЮЮ
Примерно это я и имел ввиду, только мысль до конца не додумал :-(
>Sash
выкинь стоки
i:=3;
//Проверяем таблицу на появление пустой ячейки
while not VarIsEmpty(WB.Sheets[alist].Cells.Item[i,1].Value) do Inc(i);
Переменной i вообще не будет. Предложенный ЮЮ [7] код (до многоточия) вставляем
вместо строкиfor j:=3 to i-1 do
В конце
if StrToFloat(acol9)>1 then WB.Sheets[m+1].Cells[j+1,9].Interior.ColorIndex:=10; //12
end;
iStart := iEnd + 1
end;
ЮЮ (2004-11-17 10:07:00) [23]Ничего, если я не Gloomer и не Товарищ ?
Ну, например, так:
iStart := 1;
while iStart < 65000 // или сколько их там? листать тяжело :) do begin
while (iStart < 65000) and VarIsEmpty(WB.Sheets[alist].Cells.Item[iStart,1].Value) do Inc(iStart); // ищем начало таблицы
if (iStart >= 65000) then break; //новой таблицы не найдено
iEnd := iStart;
while not VarIsEmpty(WB.Sheets[alist].Cells.Item[iEnd ,1].Value) do Inc(iEnd); // ищем конец таблицы
for j := iStart to iEnd do begin
...
end;
iStart := iEnd + 1
end;
Sash (2004-11-17 09:39:00) [24]Товарищ Gloomer! Помогите!
Sash (2004-11-16 12:02:00) [25]и еще, каждая таблица имеет разное число СТРОК
Sash (2004-11-16 11:53:00) [26]вот код:
//Создаем новый лист в книге Excel
m:=WB.Sheets.Count;
WB.Sheets.Add(,WB.Sheets[m],1,xlWorksheet);//
//Даем названия листам
if Alist1ChBox.Checked then
WB.Sheets[m+1].Name:='Отчет '+Alist1ChBox.Caption;
if Alist2ChBox.Checked then
WB.Sheets[m+1].Name:='Отчет '+Alist2ChBox.Caption;
if Alist3ChBox.Checked then
WB.Sheets[m+1].Name:='Отчет '+Alist3ChBox.Caption;
i:=3;
//Проверяем таблицу на появление пустой ячейки
while not VarIsEmpty(WB.Sheets[alist].Cells.Item[i,1].Value) do Inc(i);
//Шапка таблицы
if Alist1ChBox.Checked then
begin
WB.Sheets[m+1].Cells[1,1].Value:='Показатели нагрузки и качества обслуживания вызовов на '+Alist1ChBox.Caption;
WB.Sheets[m+1].Cells[1,1].Font.Bold:=True;
end;
if Alist2ChBox.Checked then
begin
WB.Sheets[m+1].Cells[1,1].Value:='Показатели нагрузки и качества обслуживания вызовов на '+Alist2ChBox.Caption;
WB.Sheets[m+1].Cells[1,1].Font.Bold:=True;
end;
if Alist3ChBox.Checked then
begin
WB.Sheets[m+1].Cells[1,1].Value:='Показатели нагрузки и качества обслуживания вызовов на '+Alist3ChBox.Caption;
WB.Sheets[m+1].Cells[1,1].Font.Bold:=True;
end;
WB.Sheets[m+1].Cells[3,1].Value:='Направление';
WB.Sheets[m+1].Cells[3,1].Borders.LineStyle:=1;
WB.Sheets[m+1].Cells[3,1].ColumnWidth:=12;
WB.Sheets[m+1].Cells[3,2].Value:='Попытки';
WB.Sheets[m+1].Cells[3,2].Borders.LineStyle:=1;
WB.Sheets[m+1].Cells[3,3].Value:='Ответы, %';
WB.Sheets[m+1].Cells[3,3].Borders.LineStyle:=1;
WB.Sheets[m+1].Cells[3,3].ColumnWidth:=10;
WB.Sheets[m+1].Cells[3,4].Value:='Неответы, %';
WB.Sheets[m+1].Cells[3,4].Borders.LineStyle:=1;
WB.Sheets[m+1].Cells[3,4].ColumnWidth:=12;
WB.Sheets[m+1].Cells[3,5].Value:='Занято, %';
WB.Sheets[m+1].Cells[3,5].Borders.LineStyle:=1;
WB.Sheets[m+1].Cells[3,5].ColumnWidth:=10;
WB.Sheets[m+1].Cells[3,6].Value:='Временная неисправность, %';
WB.Sheets[m+1].Cells[3,6].Borders.LineStyle:=1;
WB.Sheets[m+1].Cells[3,6].ColumnWidth:=26;
WB.Sheets[m+1].Cells[3,7].Value:='Нет канала, %';
WB.Sheets[m+1].Cells[3,7].Borders.LineStyle:=1;
WB.Sheets[m+1].Cells[3,7].ColumnWidth:=13;
WB.Sheets[m+1].Cells[3,8].Value:='Ошибка протокола, %';
WB.Sheets[m+1].Cells[3,8].Borders.LineStyle:=1;
WB.Sheets[m+1].Cells[3,8].ColumnWidth:=20;
WB.Sheets[m+1].Cells[3,9].Value:='Ресурс недоступен, %';
WB.Sheets[m+1].Cells[3,9].Borders.LineStyle:=1;
WB.Sheets[m+1].Cells[3,9].ColumnWidth:=20;
for j:=3 to i-1 do
begin
acol1:=WB.Sheets[alist].Cells[j,2].Value;
WB.Sheets[m+1].Cells[j+1,1].Value := acol1;
WB.Sheets[m+1].Cells[j+1,1].Borders.LineStyle:=1;
acol2:=WB.Sheets[alist].Cells[j,5].Value;
WB.Sheets[m+1].Cells[j+1,2].Value := acol2;
WB.Sheets[m+1].Cells[j+1,2].Borders.LineStyle:=1;
acol3:=WB.Sheets[alist].Cells[j,6].Value;
WB.Sheets[m+1].Cells[j+1,3].Value := acol3;
WB.Sheets[m+1].Cells[j+1,3].Borders.LineStyle:=1;
if strtofloat(acol3)<45 then WB.Sheets[m+1].Cells[j+1,3].Interior.ColorIndex:=6;
acol4:=WB.Sheets[alist].Cells[j,8].Value;
WB.Sheets[m+1].Cells[j+1,4].Value := acol4;
WB.Sheets[m+1].Cells[j+1,4].Borders.LineStyle:=1;
if StrToFloat(acol4)>15 then WB.Sheets[m+1].Cells[j+1,4].Interior.ColorIndex:=38;
acol5:=WB.Sheets[alist].Cells[j,9].Value;
WB.Sheets[m+1].Cells[j+1,5].Value := acol5;
WB.Sheets[m+1].Cells[j+1,5].Borders.LineStyle:=1;
if StrToFloat(acol5)>25 then WB.Sheets[m+1].Cells[j+1,5].Interior.ColorIndex:=37;
acol6:=WB.Sheets[alist].Cells[j,10].Value;
WB.Sheets[m+1].Cells[j+1,6].Value := acol6;
WB.Sheets[m+1].Cells[j+1,6].Borders.LineStyle:=1;
if StrToFloat(acol6)>1 then WB.Sheets[m+1].Cells[j+1,6].Interior.ColorIndex:=44;
acol7:=WB.Sheets[alist].Cells[j,11].Value;
WB.Sheets[m+1].Cells[j+1,7].Value := acol7;
WB.Sheets[m+1].Cells[j+1,7].Borders.LineStyle:=1;
if StrToFloat(acol7)>1 then WB.Sheets[m+1].Cells[j+1,7].Interior.ColorIndex:=46;
acol8:=WB.Sheets[alist].Cells[j,17].Value;
WB.Sheets[m+1].Cells[j+1,8].Value := acol8;
WB.Sheets[m+1].Cells[j+1,8].Borders.LineStyle:=1;
if StrToFloat(acol8)>1 then WB.Sheets[m+1].Cells[j+1,8].Interior.ColorIndex:=42;
acol9:=WB.Sheets[alist].Cells[j,19].Value;
WB.Sheets[m+1].Cells[j+1,9].Value := acol9;
WB.Sheets[m+1].Cells[j+1,9].Borders.LineStyle:=1;
if StrToFloat(acol9)>1 then WB.Sheets[m+1].Cells[j+1,9].Interior.ColorIndex:=10; //12
end;
Gloomer (2004-11-16 11:42:00) [27]Т.к. нет полного исходного кода и Excel-таблицы, то я только предположил...
Действительно, ошибочка где-то в строке
for j:=3 to i-1 do
начальное значение цикла в общем случае явно не 3,необходимо его корректировать для каждого значения. Введи еще переменную i0, в которую заноси последнюю стоку предыдущей таблицы (для начала i0:=0). Тогда
for j:=i0+3 to i-1 do
в конце цила i0:=i (насчет этой стоки точно не уверен)
Sash (2004-11-16 11:06:00) [28]нет, так он 10 раз перерисовывает одно и тоже
ты поглумился? :)))
Gloomer (2004-11-16 10:05:00) [29]а может так?
i:=3;
for n:=1 to 10 do
begin
while not VarIsEmpty(WB.Sheets[alist].Cells.Item[i,1].Value) do Inc(i);
for j:=3 to i-1 do
begin
acol1:=WB.Sheets[alist].Cells[j,2].Value;
....
end