with excelworkSheet1.Range[excelworksheet1.cells.item[f,e],excelworksheet1.Cells.item[f+10,e]],font do begin
Merge(true);
HorizontalAlignment:= xlCenter;
Size:='14';
Name:='隸書';
FontStyle:='Bold';
end;
Merge(true);
HorizontalAlignment:= xlCenter;
Size:='14';
Name:='隸書';
FontStyle:='Bold';
end;
是不是要合併一列要用別的方法呀
var
i, j, StartRow:Integer;
SheetName:String;
Sheet,Range,ColumnRange: Variant;
begin
if ATitle<>'' then //ATitle参数为空时,不打印标题
SheetName:=ATitle
else
SheetName:='打印资料';
try
XLApp:= CreateOleObject('Excel.Application');
XLApp.Visible := True;
XLApp.Workbooks.Add(xlWBatWorkSheet);
XLApp.Workbooks[1].WorkSheets[1].Name:=SheetName;
except
Msg_Dlg(mt_Info,'请检查您的机器上是否安装了Excel或Excel是否正确。','确定','','');
Exit;
end; Sheet:=XLApp.Workbooks[1].WorkSheets[SheetName];
Sheet.PageSetup.Orientation:=xlLandscape;
StartRow:=0;
if ATitle<>'' then begin
Sheet.Cells[1,1]:=SheetName;
Range:=XLApp.Workbooks[1].WorkSheets[SheetName].Range['A1:'+GetExcelColumnCaps(AStringGrid.ColCount)+'1'];
Range.Merge(False);
Range.VerticalAlignment:=xlVAlignCenter; //垂直居中
Range.HorizontalAlignment:=xlHAlignCenter; //水平居中
Range.Font.Size:=20;
inc(StartRow);
end; for i:=0 to AStringGrid.RowCount-1 do
for j:=0 to AStringGrid.ColCount-1 do
Sheet.Cells[i+1+StartRow,j+1]:=''''+Trim(AStringGrid.Cells[j,i]); ColumnRange:=XLApp.Workbooks[1].WorkSheets[SheetName].Columns;
for i:=1 to AStringGrid.ColCount do
ColumnRange.Columns[i].ColumnWidth:=AStringGrid.ColWidths[i-1]/7; if ATitle<>'' then
Range:=XLApp.Workbooks[1].WorkSheets[SheetName].Range['A2:'
+GetExcelColumnCaps(AStringGrid.ColCount)+IntToStr(AStringGrid.RowCount+1)]
else
Range:=XLApp.Workbooks[1].WorkSheets[SheetName].Range['A1:'
+GetExcelColumnCaps(AStringGrid.ColCount)+IntToStr(AStringGrid.RowCount)]; Range.Borders.LineStyle := xlContinuous; //设置边框线
Range.WrapText:=True; //自动换行 Sheet.PageSetUp.RightFooter:='第&P页共&N页'; //页脚
end;