我查阅了较多的资料,利用DElphi控制Excel,每行每列的控制都没问题了,但是一个复杂的表头我始终想不出来该怎么控制。比如说在Excel中第一行显示一个标题:XXX—xxx学年度XXX考试统计表,然后是正式表,语文涵盖下一行的两个子标题:客观题,主观题,现在的问题是大标题应该放在哪一个单元格,语文放在哪一个单元格才能看起来正好盖住客观题和主观题两个子标题呢?我希望大家明白我的意思。谢谢。

解决方案 »

  1.   

    如果涉及到画线等其它操作的话,你可以先录制宏,然后再把宏的代码加到你的程序里。你看一下这个效果:
      ExcelApp := CreateOleObject( 'Excel.Application' );
      ExcelApp.Caption := '学生成绩报表打印';
      ExcelApp.WorkBooks.Add;
      ExcelApp.WorkSheets[1].Activate;
      ExcelApp.Visible := True;
      ExcelApp.ActiveWindow.Zoom := 75;
      chexingshu:=5+ADOQuery2.RecordCount;
      excelx1:=excelop(chexingshu)+'1';
      excelx2:='a1';
      ExcelApp.Range[excelx2, excelx1].Merge(xl);
      ExcelApp.Cells[1,1].Value :=Combobox2.text+Combobox3.text+Combobox4.text+'成绩报表';
      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.cells.Item[2 , 1].Font.Bold := True;
      ExcelApp.Cells[2,1].Value :='年级';
      ExcelApp.cells.Item[2, 2].HorizontalAlignment := xlCenter;
      ExcelApp.cells.Item[2 , 2].Font.Bold := True;
      ExcelApp.Cells[2,2].Value :='班级';
      ExcelApp.cells.Item[2, 3].HorizontalAlignment := xlCenter;
      ExcelApp.cells.Item[2 , 3].Font.Bold := True;
      ExcelApp.Cells[2,3].Value :='学期';
      ExcelApp.cells.Item[2, 4].HorizontalAlignment := xlCenter;
      ExcelApp.cells.Item[2 , 4].Font.Bold := True;
      ExcelApp.Cells[2,4].Value :='姓名';
      ExcelApp.cells.Item[2, 5].HorizontalAlignment := xlCenter;
      ExcelApp.cells.Item[2 , 5].Font.Bold := True;
      ExcelApp.Cells[2,5].Value :='学号';
      

  2.   

    谢谢.不过再麻烦你帮我解释一下这几行的意思.
      chexingshu:=5+ADOQuery2.RecordCount;
      excelx1:=excelop(chexingshu)+'1';
      excelx2:='a1';
      ExcelApp.Range[excelx2, excelx1].Merge(xl);
      ExcelApp.Cells[1,1].Value :=Combobox2.text+Combobox3.text+Combobox4.text+'成绩报表';
      

  3.   

    哪位大侠知道Xlcenter在哪里定义,定义成什么值?