我想实现把本地的excel数据导入到程序里,然后在StringGrid控件上显示,没有数据库的
有例子和源码最好!

解决方案 »

  1.   

    if FileExists(dfile) then begin
          excelapplication1.Workbooks.Open(dfile,
            EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam,
            EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam,
            EmptyParam, EmptyParam, EmptyParam, EmptyParam, 0);
          ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
          ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets['sheet1'] as _Worksheet);
          advstringgrid1.ColCount := 20;
          for i := 1 to 600 do begin
            for j := 1 to 22 do begin
              if trim(excelworksheet1.cells.item[i + 1, 1]) <> '' then begin
                advstringgrid1.rowCount := i + 1;
                advstringgrid1.Cells[j - 1, i - 1] := ExcelWorksheet1.Cells.Item[i, j];
                Application.ProcessMessages;
              end else
                break;
            end;
          end;
          excelapplication1.Quit;
          ExcelApplication1.Disconnect;
         // DeleteFile(dfile);
        end;