excel的例程征求。(200分)

  • 主题发起人 主题发起人 大苹果
  • 开始时间 开始时间

大苹果

Unregistered / Unconfirmed
GUEST, unregistred user!
要求:
1.有表头。
2.数据的列出。
3.要有统计项。
200分大奖。急!急!急!
 
是将数据的内容转换为Excel文件显示吗?
 
是数据库中的数据?
是的话,很简单的。
 
参考一下吧
MyworkBook:=ExcelApp.workBooks.Add;
MyWorkBook.WorkSheets[1].Cells[i,1].Value := IntToStr(i-3);
MyWorkBook.WorkSheets[1].Cells[i,13].Value := tbPrjAllCost.Value;
//设定正文栏宽等
Myworkbook.worksheets[1].Columns[1].ColumnWidth := 4;
Myworkbook.worksheets[1].Columns[5].HorizontalAlignment := $FFFFEFF4;
Myworkbook.worksheets[1].Columns[13].NumberFormat := '###,###,###,###';
s := 'A3:M'+ IntToStr(i-1);
Myworkbook.worksheets[1].Range.Font.Name := '宋体';
s := 'A2:M'+ IntToStr(i-1);
Myworkbook.worksheets[1].Range.Borders.LineStyle := 1;
//设定标题
Myworkbook.worksheets[1].range['A1:M1'].Merge(True);
Myworkbook.worksheets[1].Rows[1].RowHeight := 50;
Myworkbook.worksheets[1].Rows['1:2'].VerticalAlignment := $FFFFEFF4;
MyWorkBook.WorkSheets[1].Cells[1,1].Value := tbUnitsUNIT_NAME.Value +
'经费明细表';
Myworkbook.worksheets[1].Rows[1].Font.Color := clBlue;
Myworkbook.worksheets[1].Rows[1].Font.Name := '隶书';
Myworkbook.worksheets[1].Rows[1].Font.Size := 18;
//设定第一行为合计
Myworkbook.worksheets[1].Rows[2].HorizontalAlignment := $FFFFEFF4;
Myworkbook.worksheets[1].Rows[2].WrapText := True;
MyWorkBook.WorkSheets[1].Cells[3,8].Value := '=sum(' + 'H4:' + 'H'+IntToStr(i)+')';
MyWorkBook.WorkSheets[1].Cells[3,10].Value := '=sum(' + 'J4:' + 'J'+IntToStr(i)+')';
MyWorkBook.WorkSheets[1].Cells[3,12].Value := '=sum(' + 'L4:' + 'L'+IntToStr(i)+')';
MyWorkBook.WorkSheets[1].Cells[3,13].Value := '=sum(' + 'M4:' + 'M'+IntToStr(i)+')';

//设定栏头
i := 2;
MyWorkBook.WorkSheets[1].Cells[i,1].Value := '序号';
MyWorkBook.WorkSheets[1].Cells[i,2].Value := '工程名称';
MyWorkBook.WorkSheets[1].Rows[2].Font.Bold := true;
MyWorkBook.WorkSheets[1].Rows[2].Font.Color := clNavy;
MyWorkBook.WorkSheets[1].Rows[2].RowHeight := 30;
//页面设置
MyworkBook.WorkSheets[1].PageSetup.CenterHorizontally := true;
MyWorkBook.WorkSheets[1].PageSetup.Orientation := 2;
Myworkbook.worksheets[1].pagesetup.PrintTitleRows := 'A1:M2';
Myworkbook.worksheets[1].pagesetup.RightFooter := '第 &P 页';
 
menxin:
你能讲详细点吗?
crab:请给出变量的定义!
 
给我1分好么?
 
Const
xlDiagonalDown = 5;
xlDiagonalUp = 6;
xlEdgeLeft = 7;
xlEdgeRight = 10;
xlEdgeTop = 8;
xlEdgeBottom = 9;
xlInsideHorizontal = 12;
xlInsideVertical = 11;
xlNone = -4142 ;
xlContinuous = 1;
XLCENTER=-4108;
procedure Treportfrm.formatexcelheader(const kind :integer);
var
year,month,day:word;
begin
WSHEET.RANGE['A1:T1'].MergeCells:=TRUE;
wsheet.RANGE['A1:t1'].horizontalAlignment:=XLCENTER;
WSHEET.RANGE['A3:A5'].MergeCells:=TRUE;
wsheet.RANGE['A3:A5'].VerticalAlignment:=XLCENTER;
WSHEET.RANGE['B3:B5'].MergeCells:=TRUE;
wsheet.RANGE['B3:B5'].VerticalAlignment:=XLCENTER;
WSHEET.RANGE['C3:C5'].MergeCells:=TRUE;
wsheet.RANGE['C3:C5'].VerticalAlignment:=XLCENTER;
WSHEET.RANGE['D4:D5'].MergeCells:=TRUE;
wsheet.RANGE['D4:D5'].VerticalAlignment:=XLCENTER;
WSHEET.RANGE['E4:E5'].MergeCells:=TRUE;
wsheet.RANGE['E4:E5'].VerticalAlignment:=XLCENTER;
WSHEET.RANGE['F4:F5'].MergeCells:=TRUE;
wsheet.RANGE['F4:F5'].VerticalAlignment:=XLCENTER;
WSHEET.RANGE['M4:M5'].MergeCells:=TRUE;
wsheet.RANGE['M4:M5'].VerticalAlignment:=XLCENTER;
WSHEET.RANGE['N4:N5'].MergeCells:=TRUE;
wsheet.RANGE['N4:N5'].VerticalAlignment:=XLCENTER;
WSHEET.RANGE['R4:R5'].MergeCells:=TRUE;
wsheet.RANGE['R4:R5'].VerticalAlignment:=XLCENTER;
WSHEET.RANGE['S4:S5'].MergeCells:=TRUE;
wsheet.RANGE['S4:S5'].VerticalAlignment:=XLCENTER;
WSHEET.RANGE['T3:T5'].MergeCells:=TRUE;
wsheet.RANGE['T3:T5'].VerticalAlignment:=XLCENTER;
WSHEET.RANGE['A2:T2'].MergeCells:=TRUE;
WSHEET.CELLS[2,1]:='制表日期:'+datetostr(now);
decodedate(now,year,month,day);
if kind=0 then
WSHEET.CELLS[1,1]:=inttostr(month)+'月份库存材料分大类余额核算(月表)'
else
WSHEET.CELLS[1,1]:=inttostr(month)+'月份库存材料分大类余额核算(累表)';
WSheet.PageSetup.PrintTitleRows:='$1:$5';
wsheet.pagesetup.leftFooter :='填报单位:测井公司供应站';
wsheet.pagesetup.rightFooter :='第'+'&P'+'页';
WSHEET.PageSetup.PrintGridlines:=False;
WSHEEt.Range['A3:t69'].Borders[xlDiagonalDown].LineStyle:= xlNone;
WSHEET.Range['A3:t69'].Borders[xlDiagonalUp].LineStyle:=xlNone;
WSHEET.Range['A3:t69'].Borders[xlEdgeLeft].LineStyle:=xlContinuous;
WSHEET.Range['A3:t69'].Borders[xlEdgeTop].LineStyle:=xlContinuous;
WSHEET.Range['A3:t69'].Borders[xlEdgeBottom].LineStyle:=xlContinuous;
WSHEET.Range['A3:t69'].Borders[xlEdgeRight].LineStyle:=xlContinuous;
WSHEET.Range['A3:t69'].Borders[xlInsideVertical].LineStyle:=xlContinuous;
WSHEET.Range['A3:t69'].Borders[xlInsideHorizontal].LineStyle:=xlContinuous;
WSHEET.Rows['37:69'].RowHeight:=17;
end;
procedure Treportfrm.setgridline(startline, endline: integer;
endclomn: string);
begin
wsheet:=wbook.activesheet;
WSHEEt.PageSetup.PrintGridlines:=False;
WSHEEt.Range['A'+inttostr(startline)+':'+endclomn+inttostr(endline)].Borders[xlDiagonalDown].LineStyle:= xlNone;
WSHEET.Range['A'+inttostr(startline)+':'+endclomn+inttostr(endline)].Borders[xlDiagonalUp].LineStyle:=xlNone;
WSHEET.Range['A'+inttostr(startline)+':'+endclomn+inttostr(endline)].Borders[xlEdgeLeft].LineStyle:=xlContinuous;
WSHEET.Range['A'+inttostr(startline)+':'+endclomn+inttostr(endline)].Borders[xlEdgeTop].LineStyle:=xlContinuous;
WSHEET.Range['A'+inttostr(startline)+':'+endclomn+inttostr(endline)].Borders[xlEdgeBottom].LineStyle:=xlContinuous;
WSHEET.Range['A'+inttostr(startline)+':'+endclomn+inttostr(endline)].Borders[xlEdgeRight].LineStyle:=xlContinuous;
WSHEET.Range['A'+inttostr(startline)+':'+endclomn+inttostr(endline)].Borders[xlInsideVertical].LineStyle:=xlContinuous;
WSHEET.Range['A'+inttostr(startline)+':'+endclomn+inttostr(endline)].Borders[xlInsideHorizontal].LineStyle:=xlContinuous;
end;
procedure report;
begin
MsExcel:= CreateOleObject('Excel.Application');
WBook:=MsExcel.Application;
WBook.Visible:= True;
wbook.workbooks.Open(ExtractFileDir(paramstr(0))+'/bao2.xls');
WSheet:=WBook.ActiveSheet;
for i:=1 to 59do
for j:=1 to fieldcountdo
if fields[j-1].asstring<>'0' then
WSHEET.CELLS[i+5,j].VALUE:=fields[j-1].asstring
formatexcelheader(1);
end;
 
多人接受答案了。
 
后退
顶部