Menu

Looking for a simple read example

2016-07-29
2016-07-29
  • Leigh Harrison

    Leigh Harrison - 2016-07-29

    I want to use OExport to read a simple XLSX file row by row within a non-graphical application (DLL). The file is a report in a fixed format with a known number of columns but a variable number of rows.

    All the examples I can find assume a graphical environment where OExport populates grids and tabsheets. Is there an example of reading a simple spreadsheet row by row (cell by cell)?

     
    • Ondrej Pokorny

      Ondrej Pokorny - 2016-07-29
      procedure TForm1.Button6Click(Sender: TObject);
      var
        xExp: TOExport;
        xWS: TExportWorkSheet;
        R, C: Integer;
        xRow: TExportRow;
        xCell: TExportCell;
        xCellValue: Double;
        xCellText: OWideString;
      begin
        xExp := TOExport.Create;
        try
          xExp.LoadFromFile('myfile.xlsx');
      
          xWS := xExp.OpenWorkSheet;
      
          for R := 0 to xWS.Rows.Count-1 do
          begin
            xRow := xWS.Rows[R];
            for C := 0 to xRow.Cells.Count-1 do
            begin
              xCell := xRow.Cells[C];
      
              // do whatever you want with the cell
              if xCell is TExportCellNumber then
              begin
                xCellValue := TExportCellNumber(xCell).Value;
              end else
              begin
                xCellText := xCell.SqlText;
              end;
            end;
          end;
        finally
          xExp.Free;
        end;
      end;
      
       
  • Leigh Harrison

    Leigh Harrison - 2016-07-29

    In attempting to read an XLSX file I'm also getting this error:

    The file extension is not assigned to any exporter.
    

    However, I can't see how to assign the file extension. If anyone can point me in the right direction that would be appreciated.

     
    • Ondrej Pokorny

      Ondrej Pokorny - 2016-07-29

      Add OExport_VCL to your uses clause.

       

Anonymous
Anonymous

Add attachments
Cancel