用Comobj控制Excel,要把第3列整列移动到第1列怎么写?
解决方案 »
- XML文件与数据库的选择
- 在文件夹空白处点击弹出的菜单,delphi中可以调用吗,怎么调用?
- 求助:SQL诗句问题
- 有关教育软件合作,大家来看看。帮忙顶顶
- ComboBox控件怎么实现与浏览器那个一样的功能?输入一个字母,就能弹出与次字母匹配的字符串!
- 各位高手,请帮帮忙!急!!急!!
- 谁有适合DELPHI7+XP系统的DevExpress类全部控件安装包吗?
- delphi开发的webservice的调用问题
- 如何删除一个目录(非空),望大虾们赐教!!!
- 谁先搞到delphi6的D盘的一定把所在地址贴上来,这样就大概可以知道中国盗版的源头啦,呵呵
- 关于类型转换问题,在线急!!!!!!!!!!!!!1
- 请教:TPageControl,属性页之间如何拖动?
ExcelApp.ActiveSheet.Used.Range.Copy;
b.拷贝指定区域:
ExcelApp.ActiveSheet.Range[ 'A1:E2' ].Copy;
c.从A1位置开始粘贴:
ExcelApp.ActiveSheet.Range.[ 'A1' ].PasteSpecial;
d.从文件尾部开始粘贴:
ExcelApp.ActiveSheet.Range.PasteSpecial;16) 插入一行或一列:
a. ExcelApp.ActiveSheet.Rows[2].Insert;
b. ExcelApp.ActiveSheet.Columns[1].Insert;17) 删除一行或一列:
a. ExcelApp.ActiveSheet.Rows[2].Delete;
b. ExcelApp.ActiveSheet.Columns[1].Delete你可以先插入一列
拷贝第3列到第一列
再删除原第3列
Columns("C:C").Select
Selection.Cut
Columns("A:A").Select
Selection.Insert Shift:=xlToRight
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(CFcxfrm.Handle,'没有可打印的查询结果!','打印提示',MB_OK+MB_ICONINFORMATION);
end;
ExcelApp.ActiveSheet.Selection.Cut
ExcelApp.ActiveSheet.Columns("A:A").Select
ExcelApp.ActiveSheet.Selection.Insert Shift:=xlToRight