看看下面的代码,应该知道怎么合并了
Procedure TForm14.ProcSaveToFile;
Var
myQsny,myZzNy,myDwmc:String;
myExcelApp,myWorkBook,mySheet,myRange:Variant;
myTempFileName:String;
I,J,K:Integer;
DjCount1,DjCount2,QkCount1,QkCount2
ouble;
m1,m2:String;
Begin
If KID=0 Then //保存
Begin
if length(ExtractFileExt(trim(AeFileName.Text)))=0 Then
myTempFileName:=trim(AeFileName.text)+'.xls'
Else
myTempFileName:=trim(AeFileName.text);
end;
If ((KID=1) or (KID=2)) Then
Begin
myTempFileName:='c:/tempwzquan04.xls';
If Fileexists(mytempfilename) Then
DeleteFile(myTempFileName);
End;
Try
myExcelApp:=CreateOleObject('Excel.Application');
If KID=0 Then
myExcelApp.Visible:=False
Else
myExcelapp.visible:=true;
myWorkBook:=CreateOleObject('Excel.Sheet');
Except
application.MessageBox('打开excel文件错误,请确认您的计算机上是否安装了Excel程序','错误',MB_OK+MB_ICONSTOP);
Exit;
End;
myWorkBook:=myexcelapp.WorkBooks.Add;
mySheet:=myWorkBook.Sheets[1];
//合并单元格 标题
myRange:=mySheet.Range[mysheet.cells[1,1],mysheet.cells[1,10]];
myRange.select;
myRange.merge;
myRange.font.size:=16;
myRange.font.name:='黑体';
myRange.rows.rowheight:=26; //行高
mySheet.cells[1,1].value:=Trim(Aend.Text)+'年不同油价敏感性分析';
myRange.HorizontalAlignment:=xlCenter; //水平对齐方式
myRange.VerticalAlignment:=xlCenter; //垂直对齐方式
//合并单元格 填报单位
myRange:=mySheet.Range[mysheet.cells[2,1],mysheet.cells[2,5]];
myRange.select;
myRange.merge;
myRange.font.size:=10;
myRange.font.name:='宋体';
myRange.rows.rowheight:=16; //行高
//mySheet.cells[2,1].value:='填报单位:'+G_SbDw;
myRange:=mySheet.Range[mysheet.cells[2,8],mysheet.cells[2,10]];
myRange.select;
myRange.merge;
myRange.font.size:=10;
myRange.font.name:='宋体';
mySheet.Cells[2,8].Value:='表14';
myRange.HorizontalAlignment:=xlCenter; //水平对齐方式
myRange.VerticalAlignment:=xlCenter; //垂直对齐方式
//下面的代码画表格
myrange:=mysheet.range[mysheet.cells[3,1],mysheet.cells[14,10]];
myrange.select;
myrange.borders.linestyle:=xlcontinuous; //置边框线可见
myRange.Font.Name:='宋体';
myrange.font.size:=10;
myRange.rows.rowheight:=20; //行高
myRange.HorizontalAlignment:=xlCenter; //水平对齐方式
myRange.VerticalAlignment:=xlCenter; //垂直对齐方式
// myRange.WrapText:=True;
mysheet.PageSetup.PaperSize:=xlPaperA4; //A4的纸张
mysheet.PageSetUp.Orientation:=2; //纵向
myRange:=mySheet.Range[mysheet.cells[3,1],mysheet.cells[3,2]];
myRange.select;
myRange.merge;
myRange.rows.rowheight:=40;
mySheet.cells[3,1]:='类别';
mySheet.cells[4,2]:='效益一类井'; mySheet.cells[5,2]:='效益二类井';
mySheet.cells[6,2]:='效益三类井'; mySheet.cells[7,2]:='边际效益井';
mySheet.cells[8,2]:='无效益井'; mySheet.cells[9,2]:='合计';
mySheet.cells[10,2]:='效益一类'; mySheet.cells[11,2]:='效益二类';
mySheet.cells[12,2]:='效益三类'; mySheet.cells[13,2]:='无效益';
mySheet.cells[14,2]:='合计';
//合并表头
//For I:=0 to G_CbfjList.count-1 do
// mySheet.cells[3,I+3]:=G_CbFjList.Strings
;
mySheet.cells[3,3]:='16.5';
mySheet.cells[3,4]:='20';
mySheet.cells[3,5]:='25';
mySheet.cells[3,6]:='30';
mySheet.cells[3,7]:='35';
mySheet.cells[3,8]:='40';
mySheet.cells[3,9]:='45';
mySheet.cells[3,10]:='50';
myRange:=mySheet.Range[mysheet.cells[4,1],mysheet.cells[9,1]];
myRange.select;
myRange.merge;
mySheet.cells[4,1]:='油井';
myRange:=mySheet.Range[mysheet.cells[10,1],mysheet.cells[14,1]];
myRange.select;
myRange.merge;
mySheet.cells[10,1]:='区块';
//下面的代码写数据
K:=4;
For I:=0 to 5 do //单井数据
Begin
For J:=0 to 7 do
Begin
If myArrayDjXylb[I,J]<>0 Then
mySheet.cells[K+I,J+3]:=Strtofloat(Format('%8.4f',[myArrayDjXylb[I,J]/10000]));
end;
end;
K:=10;
For I:=0 to 4 do //区块数据
Begin
For J:=0 to 7 do
Begin
If myArrayQkXylb[I,J]<>0 Then
mySheet.cells[K+I,J+3]:=Strtofloat(Format('%8.4f',[myArrayQkXylb[I,J]/10000]));
end;
end;
mySheet.PageSetup.Draft := False; //非草稿模式
mySheet.PageSetup.FirstPageNumber := xlAutomatic;
mySheet.PageSetup.BlackAndWhite := True; //黑白稿
mySheet.PageSetup.Zoom := 100; //缩放
mysheet.PageSetup.RightMargin:=2.5/0.035;
mysheet.PageSetup.LeftMargin:=4/0.035;
mysheet.PageSetup.PaperSize:=xlPaperA4; //A4的纸张
mysheet.PageSetUp.Orientation:=2; //纵向
If KID=1 Then //打印
Begin
mySheet.PrintOut;
end;
if KID=2 Then //预览
Begin
mysheet.PrintPreview; //打印预览
end;
myWorkBook.saveas(myTempFileName); //保存文件为临时文件
If KID=0 Then
Application.messagebox(pchar('数据保存成功,保存后的文件名:'+myTempFileName),'恭喜',MB_OK+MB_IconInformation);
If not varIsEmpty(myExcelApp) then myExcelApp.Quit;
end;