如下操作:
   系统中有一个人事表,包括如下字段:no,name,address等:
   一个excel表,也包括以上一部分字段信息,人事表和excel表有一部分字段相同。
   要求:
          从excel表中选择与人事表相应的字段值,并导入人事表。
      问题:
       1.怎样实现比较 容易?
     2.怎样记录我选择的excel 表的sheet及列

解决方案 »

  1.   

    给你点思路,用server里的excelapplication,excelworksheet,excelworkbook控件。自己试式
      

  2.   

    var
        ExcelApp: Variant;
        i, j: integer;
    begin
        ExcelApp := CreateOleObject('Excel.Application');
        ExcelApp.Visible := True;
        ExcelApp.Caption := report_Form.Caption;
        ExcelApp.WorkBooks.Add;
        ExcelApp.WorkSheets[1].Activate;
        F1BOOK61.sheet := 1;
        for i := 1 to F1BOOK61.lastRow do
            for j := 1 to F1BOOK61.lastCol do
            begin
                F1BOOK61.SetActiveCell(i, j);
                ExcelApp.Cells[i, j].Value := F1BOOK61.TextRC[i, j];
                ExcelApp.Cells[i, j].font.name := F1BOOK61.fontname;
                ExcelApp.Cells[i, j].font.Bold := F1BOOK61.FontBold;
                ExcelApp.Cells[i, j].font.Italic := F1BOOK61.FontItalic;
                ExcelApp.Cells[i, j].font.Underline := F1BOOK61.FontUnderline;
                ExcelApp.Cells[i, j].font.color := F1BOOK61.fontcolor;
    //          ExcelApp.Cells[i, j].font.size := F1BOOK61.fontsize;
            end;//    ExcelApp.WorkBooks.Add;
        ExcelApp.WorkSheets[2].Activate;
        F1BOOK61.sheet := 2;
        for i := 1 to F1BOOK61.lastRow do
            for j := 1 to F1BOOK61.lastCol do
            begin
                F1BOOK61.SetActiveCell(i, j);
                ExcelApp.Cells[i, j].Value := F1BOOK61.TextRC[i, j];
                ExcelApp.Cells[i, j].font.name := F1BOOK61.fontname;
                ExcelApp.Cells[i, j].font.Bold := F1BOOK61.FontBold;
                ExcelApp.Cells[i, j].font.Italic := F1BOOK61.FontItalic;
                ExcelApp.Cells[i, j].font.Underline := F1BOOK61.FontUnderline;
                ExcelApp.Cells[i, j].font.color := F1BOOK61.fontcolor;        end;
    //    ExcelApp.WorkBooks.Add;
        ExcelApp.WorkSheets[1].Activate;
    //以上是一个报F1BOOK控件中的数据导入EXCEL中,你替换以下