excelapp.worksheets['山东'].activate;//将名为“山东”的工作簿 设为活动工作簿。这个是对的
为什么用变量Str来代替 就出错呢。str的值已经赋值为 山东 了
excelapp.worksheets[Str].activate; 出错
excelapp.worksheets['Str'].activate; 出错
excelapp.worksheets['+Str+'].activate; 出错 该怎样赋值呢
为什么用变量Str来代替 就出错呢。str的值已经赋值为 山东 了
excelapp.worksheets[Str].activate; 出错
excelapp.worksheets['Str'].activate; 出错
excelapp.worksheets['+Str+'].activate; 出错 该怎样赋值呢
解决方案 »
- TQuery调用带参数的查询存储过程,怎么在DBgird中返回的是空表
- win2003运行文件的函数是哪个
- 急!!各位大虾帮帮忙!!谢谢
- 如何在编程环境下生成和编辑pdf文件
- 有关语音引擎的问题!还望各位大侠救我于痛苦之中!
- http://expert.csdn.net/Expert/topic/1386/1386215.xml?temp=.449856
- =====如何实现table组件的模糊查询?
- ★★★还是关于那个特殊的for循环!你们说的不对!!这是答案,看看吧!!
- delphi加tts的语音没有声音
- 快要疯掉了!服务器端与客户端的文件传送问题,请高手千万援助!
- 在安装fastReport控件出现的问题,请大家帮帮忙
- 如何得到qq三国游戏窗口的句柄?
用序号试试看
var
ExcelApp:variant;
iLoop,i,k:Integer;
begin
if CheckBox1.Checked then
begin
if (cx_kssj.Text='')or(cx_jssj.Text='') then
begin
MessageDlg('導出報表開始日期和結束日期不能為空!',mtWarning,[mbOK],0);
Exit;
end;
end
else
begin
if (cx_planer.Text='')or(cx_kssj.Text='')or(cx_jssj.Text='') then
begin
MessageDlg('導出報表條件不能為空!',mtWarning,[mbOK],0);
Exit;
end;
end;
try
Application.ProcessMessages;
ExcelApp:=CreateOleObject('Excel.Application');
except
MessageDlg('對不起,你電腦上沒有安裝Excel,請確認!',mtWarning,[mbOK],0);
Exit;
end;
try
ExcelApp.Caption:='昆盈生管週排程';
ExcelApp.Visible:=False;
ExcelApp.WorkBooks.Add;
ExcelApp.WorkBooks[1].WorkSheets[1].name:='生管週排程報表';
ExcelApp.WorkBooks[1].WorkSheets[1].Activate;
Screen.Cursor:=crSQLWait;
lab_age.Caption:='正在創建Excel格式';
lab_age.Font.Color:=$00FF8000;
Application.ProcessMessages;
ExcelApp.cells.Interior.ColorIndex:=2;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[1,8].font.name:='新細明體';
ExcelApp.WorkBooks[1].WorkSheets[1].cells.font.size:=9;
ExcelApp.WorkBooks[1].WorkSheets[1].Columns[11].ColumnWidth:=11.63;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[1,8].font.name:='標楷體';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[1,8]:='昆 盈 生 管 週 排 程';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[1,8].font.size:=14;
ExcelApp.Range['A1:N1'].MergeCells:=True;
ExcelApp.Range['A1:N1'].HorizontalAlignment:=xlCenter;
lab_age.Caption:='正在創建Excel表頭';
lab_age.Font.Color:=$00FF8000;
Application.ProcessMessages;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,1]:='線別';
ExcelApp.Range['A2:A3'].MergeCells:=True;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,2]:='工令';
ExcelApp.Range['B2:B3'].MergeCells:=True;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,3]:='料號';
ExcelApp.Range['C2:C3'].MergeCells:=True;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,4]:='成本中心';
ExcelApp.Range['D2:D3'].MergeCells:=True;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,5]:='工單量';
ExcelApp.Range['E2:E3'].MergeCells:=True;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,6]:='標準工時';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[3,6]:='PMC';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,7]:='實際工時';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[3,7]:='MFD';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,8]:='排程日期';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[3,8]:='PMC';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,9]:='上線日期';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[3,9]:='MFD';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,10]:='物料狀況';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[3,10]:='MAT';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,11]:='週數';
ExcelApp.Range['K2:K3'].MergeCells:=True;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,12]:='加總的標准工時';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[3,12]:='線別';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,13]:='週數';
ExcelApp.Range['M2:O2'].MergeCells:=True;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[3,13]:=inttostr(weekof(now))+'週';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[3,14]:=inttostr(weekof(now)+1)+'週';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[3,15]:='總計'; for i:=0 to DaysBetween(cx_kssj.Date,cx_jssj.Date) do
begin
lab_age.Caption:='開始導出"'+ FormatDateTime('yyyy/mm/dd',IncDay(cx_kssj.Date,i))+'"的數據';
Application.ProcessMessages;
if CheckBox1.Checked then
begin
adoq_wko_pdreport.Close;
adoq_wko_pdreport.SQL.Text:='select * from WKO_SCHEDULE where WKO_SDATE between '''+ FormatDateTime('yyyy/mm/dd',cx_kssj.Date)+''' and '''+ FormatDateTime('yyyy/mm/dd',cx_jssj.Date)+''' order by WKO_XB,WKO_SDATE';
adoq_wko_pdreport.Open;
end
else
begin
adoq_wko_pdreport.Close;
adoq_wko_pdreport.SQL.Text:='select * from WKO_SCHEDULE where wko_planer='''+ trim(cx_planer.Text)+''' and WKO_SDATE between '''+ FormatDateTime('yyyy/mm/dd',cx_kssj.Date)+''' and '''+ FormatDateTime('yyyy/mm/dd',cx_jssj.Date)+''' order by WKO_XB,WKO_SDATE';
adoq_wko_pdreport.Open;
end; pb1.Min:=0;
pb1.Max:=adoq_wko_pdreport.RecordCount; Application.ProcessMessages;
adoq_wko_pdreport.First;
for iLoop:=0 to adoq_wko_pdreport.RecordCount -1 do
begin
ExcelApp.cells[4+iLoop,1].RowHeight:=12;
ExcelApp.cells[4+iLoop,1].value:=adoq_wko_pdreport.FieldByName('WKO_XB').AsString;
ExcelApp.cells[4+iLoop,2].value:=adoq_wko_pdreport.FieldByName('WKO_ORDERNO').AsString;
ExcelApp.cells[4+iLoop,3].value:=adoq_wko_pdreport.FieldByName('WKO_ITEMNO').AsString;
ExcelApp.cells[4+iLoop,4].value:=adoq_wko_pdreport.FieldByName('WKO_CBZX').AsString;
ExcelApp.cells[4+iLoop,5].value:=adoq_wko_pdreport.FieldByName('WKO_QTY').AsString;
ExcelApp.cells[4+iLoop,6].value:=adoq_wko_pdreport.FieldByName('WKO_HS').AsString;
ExcelApp.cells[4+iLoop,8].value:=adoq_wko_pdreport.FieldByName('WKO_SDATE').AsString;
ExcelApp.cells[4+iLoop,11].value:=IntToStr(WeekOf(adoq_wko_pdreport.FieldValues['WKO_SDATE']));
pb1.Position:=pb1.Position+1;
Application.ProcessMessages;
adoq_wko_pdreport.Next;
end;
adoq_wko_pdreport.Close;
adoq_wko_pdreport.SQL.Text:='select distinct WKO_XB from WKO_SCHEDULE where WKO_XB IS NOT NULL';
adoq_wko_pdreport.Open;
Application.ProcessMessages;
adoq_wko_pdreport.First;
for k:=0 to adoq_wko_pdreport.RecordCount -1 do
begin
ExcelApp.cells[4+k,12].value:=adoq_wko_pdreport.FieldByName('WKO_XB').AsString;
Application.ProcessMessages;
adoq_wko_pdreport.Next;
end; end; ExcelApp.Range['A1:O'+inttostr(ExcelApp.WorkBooks[1].WorkSheets[1].usedrange.rows.count)].HorizontalAlignment:=xlCenter ;
ExcelApp.Range['A1:O'+inttostr(ExcelApp.WorkBooks[1].WorkSheets[1].usedrange.rows.count)].Borders.linestyle:=xlContinuous;
Screen.Cursor:=crDefault;
ExcelApp.Visible:=True;
pb1.Position:=0;
ModalResult:=mrOk;
lab_age.Caption:='';
except
ExcelApp.ActiveWorkBook.Saved:=True;
ExcelApp.WorkBooks.Close;
ExcelApp.Quit;
end;
end;
var
ExcelApp:variant;
iLoop,i,k:Integer;
begin
if CheckBox1.Checked then
begin
if (cx_kssj.Text='')or(cx_jssj.Text='') then
begin
MessageDlg('導出報表開始日期和結束日期不能為空!',mtWarning,[mbOK],0);
Exit;
end;
end
else
begin
if (cx_planer.Text='')or(cx_kssj.Text='')or(cx_jssj.Text='') then
begin
MessageDlg('導出報表條件不能為空!',mtWarning,[mbOK],0);
Exit;
end;
end;
try
Application.ProcessMessages;
ExcelApp:=CreateOleObject('Excel.Application');
except
MessageDlg('對不起,你電腦上沒有安裝Excel,請確認!',mtWarning,[mbOK],0);
Exit;
end;
try
ExcelApp.Caption:='昆盈生管週排程';
ExcelApp.Visible:=False;
ExcelApp.WorkBooks.Add;
ExcelApp.WorkBooks[1].WorkSheets[1].name:='生管週排程報表';
ExcelApp.WorkBooks[1].WorkSheets[1].Activate;
Screen.Cursor:=crSQLWait;
lab_age.Caption:='正在創建Excel格式';
lab_age.Font.Color:=$00FF8000;
Application.ProcessMessages;
ExcelApp.cells.Interior.ColorIndex:=2;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[1,8].font.name:='新細明體';
ExcelApp.WorkBooks[1].WorkSheets[1].cells.font.size:=9;
ExcelApp.WorkBooks[1].WorkSheets[1].Columns[11].ColumnWidth:=11.63;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[1,8].font.name:='標楷體';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[1,8]:='昆 盈 生 管 週 排 程';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[1,8].font.size:=14;
ExcelApp.Range['A1:N1'].MergeCells:=True;
ExcelApp.Range['A1:N1'].HorizontalAlignment:=xlCenter;
lab_age.Caption:='正在創建Excel表頭';
lab_age.Font.Color:=$00FF8000;
Application.ProcessMessages;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,1]:='線別';
ExcelApp.Range['A2:A3'].MergeCells:=True;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,2]:='工令';
ExcelApp.Range['B2:B3'].MergeCells:=True;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,3]:='料號';
ExcelApp.Range['C2:C3'].MergeCells:=True;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,4]:='成本中心';
ExcelApp.Range['D2:D3'].MergeCells:=True;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,5]:='工單量';
ExcelApp.Range['E2:E3'].MergeCells:=True;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,6]:='標準工時';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[3,6]:='PMC';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,7]:='實際工時';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[3,7]:='MFD';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,8]:='排程日期';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[3,8]:='PMC';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,9]:='上線日期';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[3,9]:='MFD';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,10]:='物料狀況';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[3,10]:='MAT';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,11]:='週數';
ExcelApp.Range['K2:K3'].MergeCells:=True;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,12]:='加總的標准工時';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[3,12]:='線別';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,13]:='週數';
ExcelApp.Range['M2:O2'].MergeCells:=True;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[3,13]:=inttostr(weekof(now))+'週';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[3,14]:=inttostr(weekof(now)+1)+'週';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[3,15]:='總計'; for i:=0 to DaysBetween(cx_kssj.Date,cx_jssj.Date) do
begin
lab_age.Caption:='開始導出"'+ FormatDateTime('yyyy/mm/dd',IncDay(cx_kssj.Date,i))+'"的數據';
Application.ProcessMessages;
if CheckBox1.Checked then
begin
adoq_wko_pdreport.Close;
adoq_wko_pdreport.SQL.Text:='select * from WKO_SCHEDULE where WKO_SDATE between '''+ FormatDateTime('yyyy/mm/dd',cx_kssj.Date)+''' and '''+ FormatDateTime('yyyy/mm/dd',cx_jssj.Date)+''' order by WKO_XB,WKO_SDATE';
adoq_wko_pdreport.Open;
end
else
begin
adoq_wko_pdreport.Close;
adoq_wko_pdreport.SQL.Text:='select * from WKO_SCHEDULE where wko_planer='''+ trim(cx_planer.Text)+''' and WKO_SDATE between '''+ FormatDateTime('yyyy/mm/dd',cx_kssj.Date)+''' and '''+ FormatDateTime('yyyy/mm/dd',cx_jssj.Date)+''' order by WKO_XB,WKO_SDATE';
adoq_wko_pdreport.Open;
end; pb1.Min:=0;
pb1.Max:=adoq_wko_pdreport.RecordCount; Application.ProcessMessages;
adoq_wko_pdreport.First;
for iLoop:=0 to adoq_wko_pdreport.RecordCount -1 do
begin
ExcelApp.cells[4+iLoop,1].RowHeight:=12;
ExcelApp.cells[4+iLoop,1].value:=adoq_wko_pdreport.FieldByName('WKO_XB').AsString;
ExcelApp.cells[4+iLoop,2].value:=adoq_wko_pdreport.FieldByName('WKO_ORDERNO').AsString;
ExcelApp.cells[4+iLoop,3].value:=adoq_wko_pdreport.FieldByName('WKO_ITEMNO').AsString;
ExcelApp.cells[4+iLoop,4].value:=adoq_wko_pdreport.FieldByName('WKO_CBZX').AsString;
ExcelApp.cells[4+iLoop,5].value:=adoq_wko_pdreport.FieldByName('WKO_QTY').AsString;
ExcelApp.cells[4+iLoop,6].value:=adoq_wko_pdreport.FieldByName('WKO_HS').AsString;
ExcelApp.cells[4+iLoop,8].value:=adoq_wko_pdreport.FieldByName('WKO_SDATE').AsString;
ExcelApp.cells[4+iLoop,11].value:=IntToStr(WeekOf(adoq_wko_pdreport.FieldValues['WKO_SDATE']));
pb1.Position:=pb1.Position+1;
Application.ProcessMessages;
adoq_wko_pdreport.Next;
end;
adoq_wko_pdreport.Close;
adoq_wko_pdreport.SQL.Text:='select distinct WKO_XB from WKO_SCHEDULE where WKO_XB IS NOT NULL';
adoq_wko_pdreport.Open;
Application.ProcessMessages;
adoq_wko_pdreport.First;
for k:=0 to adoq_wko_pdreport.RecordCount -1 do
begin
ExcelApp.cells[4+k,12].value:=adoq_wko_pdreport.FieldByName('WKO_XB').AsString;
Application.ProcessMessages;
adoq_wko_pdreport.Next;
end; end; ExcelApp.Range['A1:O'+inttostr(ExcelApp.WorkBooks[1].WorkSheets[1].usedrange.rows.count)].HorizontalAlignment:=xlCenter ;
ExcelApp.Range['A1:O'+inttostr(ExcelApp.WorkBooks[1].WorkSheets[1].usedrange.rows.count)].Borders.linestyle:=xlContinuous;
Screen.Cursor:=crDefault;
ExcelApp.Visible:=True;
pb1.Position:=0;
ModalResult:=mrOk;
lab_age.Caption:='';
except
ExcelApp.ActiveWorkBook.Saved:=True;
ExcelApp.WorkBooks.Close;
ExcelApp.Quit;
end;
end;
var
ExcelApp:variant;
iLoop,i,k:Integer;
begin
if CheckBox1.Checked then
begin
if (cx_kssj.Text='')or(cx_jssj.Text='') then
begin
MessageDlg('導出報表開始日期和結束日期不能為空!',mtWarning,[mbOK],0);
Exit;
end;
end
else
begin
if (cx_planer.Text='')or(cx_kssj.Text='')or(cx_jssj.Text='') then
begin
MessageDlg('導出報表條件不能為空!',mtWarning,[mbOK],0);
Exit;
end;
end;
try
Application.ProcessMessages;
ExcelApp:=CreateOleObject('Excel.Application');
except
MessageDlg('對不起,你電腦上沒有安裝Excel,請確認!',mtWarning,[mbOK],0);
Exit;
end;
try
ExcelApp.Caption:='昆盈生管週排程';
ExcelApp.Visible:=False;
ExcelApp.WorkBooks.Add;
ExcelApp.WorkBooks[1].WorkSheets[1].name:='生管週排程報表';
ExcelApp.WorkBooks[1].WorkSheets[1].Activate;
Screen.Cursor:=crSQLWait;
lab_age.Caption:='正在創建Excel格式';
lab_age.Font.Color:=$00FF8000;
Application.ProcessMessages;
ExcelApp.cells.Interior.ColorIndex:=2;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[1,8].font.name:='新細明體';
ExcelApp.WorkBooks[1].WorkSheets[1].cells.font.size:=9;
ExcelApp.WorkBooks[1].WorkSheets[1].Columns[11].ColumnWidth:=11.63;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[1,8].font.name:='標楷體';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[1,8]:='昆 盈 生 管 週 排 程';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[1,8].font.size:=14;
ExcelApp.Range['A1:N1'].MergeCells:=True;
ExcelApp.Range['A1:N1'].HorizontalAlignment:=xlCenter;
lab_age.Caption:='正在創建Excel表頭';
lab_age.Font.Color:=$00FF8000;
Application.ProcessMessages;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,1]:='線別';
ExcelApp.Range['A2:A3'].MergeCells:=True;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,2]:='工令';
ExcelApp.Range['B2:B3'].MergeCells:=True;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,3]:='料號';
ExcelApp.Range['C2:C3'].MergeCells:=True;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,4]:='成本中心';
ExcelApp.Range['D2:D3'].MergeCells:=True;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,5]:='工單量';
ExcelApp.Range['E2:E3'].MergeCells:=True;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,6]:='標準工時';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[3,6]:='PMC';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,7]:='實際工時';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[3,7]:='MFD';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,8]:='排程日期';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[3,8]:='PMC';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,9]:='上線日期';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[3,9]:='MFD';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,10]:='物料狀況';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[3,10]:='MAT';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,11]:='週數';
ExcelApp.Range['K2:K3'].MergeCells:=True;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,12]:='加總的標准工時';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[3,12]:='線別';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[2,13]:='週數';
ExcelApp.Range['M2:O2'].MergeCells:=True;
ExcelApp.WorkBooks[1].WorkSheets[1].cells[3,13]:=inttostr(weekof(now))+'週';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[3,14]:=inttostr(weekof(now)+1)+'週';
ExcelApp.WorkBooks[1].WorkSheets[1].cells[3,15]:='總計'; for i:=0 to DaysBetween(cx_kssj.Date,cx_jssj.Date) do
begin
lab_age.Caption:='開始導出"'+ FormatDateTime('yyyy/mm/dd',IncDay(cx_kssj.Date,i))+'"的數據';
Application.ProcessMessages;
if CheckBox1.Checked then
begin
adoq_wko_pdreport.Close;
adoq_wko_pdreport.SQL.Text:='select * from WKO_SCHEDULE where WKO_SDATE between '''+ FormatDateTime('yyyy/mm/dd',cx_kssj.Date)+''' and '''+ FormatDateTime('yyyy/mm/dd',cx_jssj.Date)+''' order by WKO_XB,WKO_SDATE';
adoq_wko_pdreport.Open;
end
else
begin
adoq_wko_pdreport.Close;
adoq_wko_pdreport.SQL.Text:='select * from WKO_SCHEDULE where wko_planer='''+ trim(cx_planer.Text)+''' and WKO_SDATE between '''+ FormatDateTime('yyyy/mm/dd',cx_kssj.Date)+''' and '''+ FormatDateTime('yyyy/mm/dd',cx_jssj.Date)+''' order by WKO_XB,WKO_SDATE';
adoq_wko_pdreport.Open;
end; pb1.Min:=0;
pb1.Max:=adoq_wko_pdreport.RecordCount; Application.ProcessMessages;
adoq_wko_pdreport.First;
for iLoop:=0 to adoq_wko_pdreport.RecordCount -1 do
begin
ExcelApp.cells[4+iLoop,1].RowHeight:=12;
ExcelApp.cells[4+iLoop,1].value:=adoq_wko_pdreport.FieldByName('WKO_XB').AsString;
ExcelApp.cells[4+iLoop,2].value:=adoq_wko_pdreport.FieldByName('WKO_ORDERNO').AsString;
ExcelApp.cells[4+iLoop,3].value:=adoq_wko_pdreport.FieldByName('WKO_ITEMNO').AsString;
ExcelApp.cells[4+iLoop,4].value:=adoq_wko_pdreport.FieldByName('WKO_CBZX').AsString;
ExcelApp.cells[4+iLoop,5].value:=adoq_wko_pdreport.FieldByName('WKO_QTY').AsString;
ExcelApp.cells[4+iLoop,6].value:=adoq_wko_pdreport.FieldByName('WKO_HS').AsString;
ExcelApp.cells[4+iLoop,8].value:=adoq_wko_pdreport.FieldByName('WKO_SDATE').AsString;
ExcelApp.cells[4+iLoop,11].value:=IntToStr(WeekOf(adoq_wko_pdreport.FieldValues['WKO_SDATE']));
pb1.Position:=pb1.Position+1;
Application.ProcessMessages;
adoq_wko_pdreport.Next;
end;
adoq_wko_pdreport.Close;
adoq_wko_pdreport.SQL.Text:='select distinct WKO_XB from WKO_SCHEDULE where WKO_XB IS NOT NULL';
adoq_wko_pdreport.Open;
Application.ProcessMessages;
adoq_wko_pdreport.First;
for k:=0 to adoq_wko_pdreport.RecordCount -1 do
begin
ExcelApp.cells[4+k,12].value:=adoq_wko_pdreport.FieldByName('WKO_XB').AsString;
Application.ProcessMessages;
adoq_wko_pdreport.Next;
end; end; ExcelApp.Range['A1:O'+inttostr(ExcelApp.WorkBooks[1].WorkSheets[1].usedrange.rows.count)].HorizontalAlignment:=xlCenter ;
ExcelApp.Range['A1:O'+inttostr(ExcelApp.WorkBooks[1].WorkSheets[1].usedrange.rows.count)].Borders.linestyle:=xlContinuous;
Screen.Cursor:=crDefault;
ExcelApp.Visible:=True;
pb1.Position:=0;
ModalResult:=mrOk;
lab_age.Caption:='';
except
ExcelApp.ActiveWorkBook.Saved:=True;
ExcelApp.WorkBooks.Close;
ExcelApp.Quit;
end;
end;
excelapp.worksheets[QuotedStr(Str)].activate;
我也是同样用的,沒事啊。是不是給str值時的事,貼出代码吧
Str,p:String;
begin
assignFile(f,'d:\mm.txt'); //mm.txt里边只有山东 两个字符
reset(f);
read(f,p);
Str:=Str+p;
closeFile(f);
ShowMessage(Str);//输出的是 山东 两个字符串 。可见赋值没问题。
excelapp:=createoleobject('excel.application');
excelapp.visible:=true; //显示当前窗口
excelapp.workbooks.open('D:\客户列表.xls'); //打开一个已经存在的工作簿
excelapp.worksheets[Str].activate; //就是这个地方 *****
var
excelapp: variant;
str: string;
begin
excelapp:=createoleobject('excel.application');
excelapp.visible:=true; //显示当前窗口
excelapp.workbooks.open('D:\1.xls'); //打开一个已经存在的工作簿
str:='山东';
excelapp.worksheets[Str].activate; //就是这个地方 *****
end;
procedure TForm1.Button2Click(Sender: TObject);
var F:TextFile;
Str,p:String;
excelapp: variant;
begin
assignFile(f,'d:\1.txt'); //mm.txt里边只有山东 两个字符
reset(f);
read(f,p);
Str:=Str+p;
closeFile(f);
ShowMessage(Str);//输出的是 山东 两个字符串 。可见赋值没问题。
excelapp:=createoleobject('excel.application');
excelapp.visible:=true; //显示当前窗口
excelapp.workbooks.open('D:\1.xls'); //打开一个已经存在的工作簿
excelapp.worksheets[Str].activate; //就是这个地方 *****end;