数据导出到EXCEL的实例
tryexcelapp := createoleobject('excel.application');
workbook := excelapp.application.workbooks.add;
worksheet := excelapp.application.worksheets.add;
except
application.MessageBox('没有安装excel', '信息', mb_ok);
exit;
end;
excelapp.visible := true;
excelapp.caption := '专任教师年龄分布情况表';
worksheet.cells.HorizontalAlignment := $FFFFEFF4;
worksheet.cells.VerticalAlignment := $FFFFEFF4;
//规定整个excel需要换行
//设置预览方式
worksheet.PageSetup.Orientation := xlLandscape;
//设置纸型
worksheet.PageSetup.PaperSize := xlPaperA4; //A4纸
worksheet.range[worksheet.cells.item[1, 2], worksheet.cells.item[15000, 16]].wraptext := true;
//规定整个excel的字体都为10号字
worksheet.range[worksheet.cells.item[1, 1], worksheet.cells.item[10000, 16]].font.size := 10;
//定义列宽
excelapp.activesheet.columns[1].columnwidth := 15; //设置第一列得宽度
worksheet.range[worksheet.cells.item[1, 1], worksheet.cells.item[1, 12]].merge(worksheet.range[worksheet.cells.item[1, 1], worksheet.cells.item[1, 12]].mergecells); //worksheet.cells.item[row,1].font.bold:=true;
worksheet.cells.item[1, 1].font.bold := true;
worksheet.cells.item[1, 1].font.size := 13;
worksheet.rows[1].rowheight := 50; //设置第一行的高度
worksheet.cells.item[1, 1] := xxm + '专任教师年龄分布情况表';
worksheet.range[worksheet.cells.item[2, 11], worksheet.cells.item[2, 12]].merge(worksheet.range[worksheet.cells.item[2, 11], worksheet.cells.item[2, 12]].mergecells);
worksheet.rows[2].rowheight := 30; //设置第一行的高度
worksheet.cells.item[2, 11] := '表号:高基34' + #10#13 + '单位:人';
query1.First;
worksheet.cells.item[3, 2] := '编号';
worksheet.cells.item[3, 3] := '合计';
worksheet.cells.item[3, 4] := '30岁及以下';
worksheet.cells.item[3, 5] := '31-35岁';
worksheet.cells.item[3, 6] := '36-40';
worksheet.cells.item[3, 7] := '41-45';
worksheet.cells.item[3, 8] := '46-50';
worksheet.cells.item[3, 9] := '51-55';
worksheet.cells.item[3, 10] := '56-60';
worksheet.cells.item[3, 11] := '61-65';
worksheet.cells.item[3, 12] := '66以上';
//worksheet.cells.item[3,13]:='平均年龄';
//显示第4行
worksheet.cells.item[4, 1] := '甲';
worksheet.cells.item[4, 2] := '乙';
for i := 1 to 10 do
worksheet.cells.item[4, i + 2] := i;
//显示总计和女
worksheet.cells.item[5, 1] := '总计';
worksheet.cells.item[6, 1] := '其中:女';