我的excel是这样获取的
xls:=texcelapplication.Create(self);
bk:=tExcelWorkBook.Create(self);
sht:=tExcelWorkSheet.Create(self);
如何设置sht的表列宽、行高的改变或删除
xls:=texcelapplication.Create(self);
bk:=tExcelWorkBook.Create(self);
sht:=tExcelWorkSheet.Create(self);
如何设置sht的表列宽、行高的改变或删除
解决方案 »
- delphi中怎样才能取得 SQLSever 2000中text 字段类型得值呢?
- 紧急求救!!!
- 求助:如何提高程序的处理速度(筛选两个文本中不同的内容)
- 请教动态生成Label
- 一个窗体文件突然打不开啦,怎么办?
- 初学DELPHI DCOM编程,请教
- 上头给我了一个系统的源代码(delphi写的)我要怎么才能看啊?要下什么软件啊?谢谢
- 看看这段代码是否有错
- 有人试过吗???!!进来看看问题!!!(在线关注)
- 谁有Venus、WithPalette、WithStyle、WithView for Delphi 6的安装序列号?
- 关于页面过渡效果的问题,急!!!!!!!!!!!!!!!!!!!!!!!!!
- 关于动态连接colums的代码,好像不起作用哦?!
var
chexingshu:integer;
Excelx1:string;
Excelx2:string;
xl,Cell1: olevariant;
Sum:integer;
begin
if ADOQuery1.RecordCount<>0 then
begin
ExcelApp := CreateOleObject( 'Excel.Application' );
ExcelApp.Caption := '学生处罚报表打印';
ExcelApp.WorkBooks.Add;
ExcelApp.WorkSheets[1].Activate;
ExcelApp.Visible := True;
ExcelApp.ActiveWindow.Zoom := 75;
chexingshu:=9;
excelx1:=excelop(chexingshu)+'1';
excelx2:='a1';
ExcelApp.Range[excelx2, excelx1].Merge(xl);
ExcelApp.Cells[1,1].Value :='学生处罚报表';
ExcelApp.cells.Item[1, 1].font.size := 20;
ExcelApp.cells.Item[1, 1].RowHeight := 25;
ExcelApp.cells.Item[1 , 1].Font.Bold := True;
ExcelApp.cells.Item[1, 1].HorizontalAlignment := xlCenter;
ExcelApp.cells.Item[1, 1].font.Name := '隶书';
ExcelApp.cells.Item[2, 1].HorizontalAlignment := xlCenter;
ExcelApp.Range['a2', 'a3'].Merge(xl);
ExcelApp.Cells[2,1].Value :='年级';
ExcelApp.cells.Item[2 , 1].Font.Bold := True;
ExcelApp.Range['a2', 'a3'].ColumnWidth := 20;
ExcelApp.cells.Item[2, 1].RowHeight := 20;
ExcelApp.Range['b2', 'b3'].Merge(xl);
ExcelApp.Cells[2,2].Value := '班级';
ExcelApp.cells.Item[2 , 2].Font.Bold := True;
ExcelApp.Range['c2', 'c3'].Merge(xl);
ExcelApp.cells.Item[2, 2].HorizontalAlignment := xlCenter;
ExcelApp.Cells[2,3].Value := '学期';
ExcelApp.cells.Item[2 , 3].Font.Bold := True;
ExcelApp.Range['d2', 'd3'].Merge(xl);
ExcelApp.cells.Item[2, 3].HorizontalAlignment := xlCenter;
ExcelApp.Cells[2,4].Value := '姓名';
ExcelApp.cells.Item[2 , 4].Font.Bold := True;
ExcelApp.Range['e2', 'e3'].Merge(xl);
ExcelApp.Range['d2', 'd2'].ColumnWidth := 15;
ExcelApp.cells.Item[2, 4].HorizontalAlignment := xlCenter;
ExcelApp.Cells[2,5].Value := '学号';
ExcelApp.cells.Item[2 , 5].Font.Bold := True;
ExcelApp.Range['e2', 'e3'].Merge(xl);
ExcelApp.cells.Item[2, 5].HorizontalAlignment := xlCenter;
ExcelApp.Cells[2,6].Value := '性别';
ExcelApp.cells.Item[2 , 6].Font.Bold := True;
ExcelApp.Range['f2', 'f3'].Merge(xl);
ExcelApp.cells.Item[2, 6].HorizontalAlignment := xlCenter;
ExcelApp.Cells[2,7].Value := '处罚时间';
ExcelApp.cells.Item[2 , 7].Font.Bold := True;
ExcelApp.Range['g2', 'g3'].Merge(xl);
ExcelApp.cells.Item[2, 7].HorizontalAlignment := xlCenter;
ExcelApp.Cells[2,8].Value := '处罚类型';
ExcelApp.cells.Item[2 , 8].Font.Bold := True;
ExcelApp.Range['h2', 'h3'].Merge(xl);
ExcelApp.cells.Item[2, 8].HorizontalAlignment := xlCenter;
ExcelApp.Cells[2,9].Value := '处罚原因';
ExcelApp.cells.Item[2 , 9].Font.Bold := True;
ExcelApp.Range['i2', 'i3'].Merge(xl);
ExcelApp.cells.Item[2, 9].HorizontalAlignment := xlCenter;
Sum:=4; While ADOQuery1.Eof<>True do
begin
ExcelApp.Cells[sum,1].Value :=ADOQuery1.FieldByName('C_Nj').AsString;
ExcelApp.cells.Item[sum,1].HorizontalAlignment := xlCenter;
ExcelApp.Cells[sum,2].Value :=ADOQuery1.FieldByName('C_Class').AsString;
ExcelApp.cells.Item[sum,2].HorizontalAlignment := xlCenter;
ExcelApp.Cells[sum,3].Value :=ADOQuery1.FieldByName('C_Xq').AsString;
ExcelApp.cells.Item[sum,3].HorizontalAlignment := xlCenter;
ExcelApp.Cells[sum,4].Value :=ADOQuery1.FieldByName('C_Name').AsString;
ExcelApp.cells.Item[sum,4].HorizontalAlignment := xlCenter;
ExcelApp.Cells[sum,5].Value :=ADOQuery1.FieldByName('C_Xh').AsString;
ExcelApp.cells.Item[sum,5].HorizontalAlignment := xlCenter;
ExcelApp.Cells[sum,6].Value :=ADOQuery1.FieldByName('C_Sex').AsString;
ExcelApp.cells.Item[sum,6].HorizontalAlignment := xlCenter;
ExcelApp.Cells[sum,7].Value :=ADOQuery1.FieldByName('c_Date').AsString;
ExcelApp.cells.Item[sum,7].HorizontalAlignment := xlCenter;
ExcelApp.Cells[sum,8].Value :=ADOQuery1.FieldByName('C_Nx').AsString;
ExcelApp.cells.Item[sum,8].HorizontalAlignment := xlCenter;
ExcelApp.Cells[sum,9].Value :=ADOQuery1.FieldByName('C_Yy').AsString;
ExcelApp.cells.Item[sum,9].HorizontalAlignment := xlCenter;
sum:=sum+1;
ADOQuery1.next;
end;
ExcelApp.ActiveSheet.Protect(DrawingObjects:=True,Contents:=True,Scenarios:=True,AllowFormattingCells:=True,AllowFormattingColumns:=True,AllowFormattingRows:=True,PassWord:='lxdshihongchun');
end
else
MessageBox(CFtjfrm.Handle,'没有可打印的查询结果!','打印提示',MB_OK+MB_ICONINFORMATION);
end;