W
wang_cai1
Unregistered / Unconfirmed
GUEST, unregistred user!
下面是我的一段代码,我想以一个excel表为模板,从中复制一个sheet至一个新的表中,并向其中插入数据,但复制后新表中的格式确丢失了,请各位帮忙看看问题出在哪?源码如下
procedure TApply_QF.B2Click(Sender: TObject);
var temp_worksheet: _Worksheet;
ww: _Workbook;
begin
EA2.Connect;
EA1.Connect;
ww := EA2.Workbooks.Open(extractFilePath(Application.ExeName) + 'Gd.xls', EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, 0);
EB2.ConnectTo(ww);
ES2.ConnectTo(EB2.Worksheets[1] as _worksheet);
ES2.Activate;
ES2.Select;
ES2.UsedRange[0].Copy(EmptyParam);
//Es2.Select;
//Es2.Copy;
EA1.Caption := '群发数据;
EA1.Visible[0] := True;
EB1.ConnectTo(EA1.Workbooks.Add(EmptyParam, 0));
Dm.SP_Apply.First;
while not Dm.SP_Apply.Eof do
begin
temp_worksheet := EB1.Worksheets.add(EmptyParam, EmptyParam, EmptyParam, EmptyParam, 0) as _Worksheet; //增加一个sheet
ES1.ConnectTo(temp_worksheet);
ES1.Activate;
ES1.Name := Dm.SP_ApplyA_ID.AsString;
ES1.PasteSpecial(EmptyParam);
EA1.Cells.Item[2, 1] := '编号:' + Dm.SP_ApplyA_ID.AsString;
EA1.Cells.Item[3, 2].value := Dm.SP_ApplyDept_Name.AsString;
EA1.Cells.Item[3, 4].value := Dm.SP_ApplyOper_Name.AsString;
EA1.Cells.Item[3, 6].value := Dm.SP_ApplyA_Time.AsString;
EA1.Cells.Item[4, 2].value := Dm.SP_ApplyA_Instancy.AsString;
EA1.Cells.Item[4, 4].value := Dm.SP_ApplyA_Type.AsString;
EA1.Cells.Item[4, 6].value := Dm.SP_ApplyA_Phone.AsString;
EA1.Cells.Item[5, 2].value := Dm.SP_ApplyA_Plan.AsString;
EA1.Cells.Item[5, 4].value := Dm.SP_ApplyA_SP_Num.AsString;
EA1.Cells.Item[6, 3].value := Dm.SP_ApplySend_Date.AsString;
EA1.Cells.Item[7, 3].value := Dm.SP_ApplySend_Time.AsString;
EA1.Cells.Item[8, 3].value := Dm.SP_ApplyTarger_File.AsString;
EA1.Cells.Item[9, 3].value := Dm.SP_ApplyTarger_user.AsString;
EA1.Cells.Item[10, 3].value := Dm.SP_ApplyData_S.AsString;
EA1.Cells.Item[11, 3].value := Dm.SP_ApplyTitle.AsString;
EA1.Cells.Item[12, 2].value := Dm.SP_ApplyContent1.AsString;
EA1.Cells.Item[13, 2].value := Dm.SP_ApplyContent2.AsString;
EA1.Cells.Item[14, 2].value := Dm.SP_ApplyContent3.AsString;
EA1.Cells.Item[16, 3].value := Dm.SP_ApplyUser_Num.AsString;
EA1.Cells.Item[17, 3].value := Dm.SP_ApplyTrans_Num.AsString;
EA1.Cells.Item[18, 3].value := Dm.SP_ApplyTS_Num.AsString;
EA1.Cells.Item[19, 3].value := Dm.SP_ApplyRefer_Num.AsString;
EA1.Cells.Item[20, 2].value := Dm.SP_ApplyDept_L_agree.AsString;
EA1.Cells.Item[21, 2].value := Dm.SP_ApplyOther_Dept_agree.AsString;
EA1.Cells.Item[22, 2].value := Dm.SP_ApplyCom_L_agree.AsString;
EA1.Cells.Item[23, 2].value := Dm.SP_ApplyCallCent_Content.AsString;
EA1.Cells.Item[24, 2].value := Dm.SP_ApplyTrySend_Result.AsString;
EA1.Cells.Item[25, 2].value := Dm.SP_ApplySend_Result.AsString;
Dm.SP_Apply.Next;
end;
end;
procedure TApply_QF.B2Click(Sender: TObject);
var temp_worksheet: _Worksheet;
ww: _Workbook;
begin
EA2.Connect;
EA1.Connect;
ww := EA2.Workbooks.Open(extractFilePath(Application.ExeName) + 'Gd.xls', EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, 0);
EB2.ConnectTo(ww);
ES2.ConnectTo(EB2.Worksheets[1] as _worksheet);
ES2.Activate;
ES2.Select;
ES2.UsedRange[0].Copy(EmptyParam);
//Es2.Select;
//Es2.Copy;
EA1.Caption := '群发数据;
EA1.Visible[0] := True;
EB1.ConnectTo(EA1.Workbooks.Add(EmptyParam, 0));
Dm.SP_Apply.First;
while not Dm.SP_Apply.Eof do
begin
temp_worksheet := EB1.Worksheets.add(EmptyParam, EmptyParam, EmptyParam, EmptyParam, 0) as _Worksheet; //增加一个sheet
ES1.ConnectTo(temp_worksheet);
ES1.Activate;
ES1.Name := Dm.SP_ApplyA_ID.AsString;
ES1.PasteSpecial(EmptyParam);
EA1.Cells.Item[2, 1] := '编号:' + Dm.SP_ApplyA_ID.AsString;
EA1.Cells.Item[3, 2].value := Dm.SP_ApplyDept_Name.AsString;
EA1.Cells.Item[3, 4].value := Dm.SP_ApplyOper_Name.AsString;
EA1.Cells.Item[3, 6].value := Dm.SP_ApplyA_Time.AsString;
EA1.Cells.Item[4, 2].value := Dm.SP_ApplyA_Instancy.AsString;
EA1.Cells.Item[4, 4].value := Dm.SP_ApplyA_Type.AsString;
EA1.Cells.Item[4, 6].value := Dm.SP_ApplyA_Phone.AsString;
EA1.Cells.Item[5, 2].value := Dm.SP_ApplyA_Plan.AsString;
EA1.Cells.Item[5, 4].value := Dm.SP_ApplyA_SP_Num.AsString;
EA1.Cells.Item[6, 3].value := Dm.SP_ApplySend_Date.AsString;
EA1.Cells.Item[7, 3].value := Dm.SP_ApplySend_Time.AsString;
EA1.Cells.Item[8, 3].value := Dm.SP_ApplyTarger_File.AsString;
EA1.Cells.Item[9, 3].value := Dm.SP_ApplyTarger_user.AsString;
EA1.Cells.Item[10, 3].value := Dm.SP_ApplyData_S.AsString;
EA1.Cells.Item[11, 3].value := Dm.SP_ApplyTitle.AsString;
EA1.Cells.Item[12, 2].value := Dm.SP_ApplyContent1.AsString;
EA1.Cells.Item[13, 2].value := Dm.SP_ApplyContent2.AsString;
EA1.Cells.Item[14, 2].value := Dm.SP_ApplyContent3.AsString;
EA1.Cells.Item[16, 3].value := Dm.SP_ApplyUser_Num.AsString;
EA1.Cells.Item[17, 3].value := Dm.SP_ApplyTrans_Num.AsString;
EA1.Cells.Item[18, 3].value := Dm.SP_ApplyTS_Num.AsString;
EA1.Cells.Item[19, 3].value := Dm.SP_ApplyRefer_Num.AsString;
EA1.Cells.Item[20, 2].value := Dm.SP_ApplyDept_L_agree.AsString;
EA1.Cells.Item[21, 2].value := Dm.SP_ApplyOther_Dept_agree.AsString;
EA1.Cells.Item[22, 2].value := Dm.SP_ApplyCom_L_agree.AsString;
EA1.Cells.Item[23, 2].value := Dm.SP_ApplyCallCent_Content.AsString;
EA1.Cells.Item[24, 2].value := Dm.SP_ApplyTrySend_Result.AsString;
EA1.Cells.Item[25, 2].value := Dm.SP_ApplySend_Result.AsString;
Dm.SP_Apply.Next;
end;
end;