FlexCel Studio for VCL/LCL
ContentsIndex
PreviousUpNext
TFlexCelImport.OpenText Method (TFileName, UTF16Char, array of XLSColumnImportTypes)

This method will create a new worksheet and load a text file into it.

Pascal
procedure OpenText(const FileName: TFileName; const Delimiter: UTF16Char; const ColumnFormats: array of XLSColumnImportTypes); overload;
C++
__fastcall OpenText(const TFileName FileName, const UTF16Char Delimiter, const array of XLSColumnImportTypes ColumnFormats);
Parameters 
Description 
const FileName: TFileName 
File to Open. 
const Delimiter: UTF16Char 
The character used to separate fields. 
const ColumnFormats: array of XLSColumnImportTypes 
An array of formats that you can supply so FlexCel knows which kind of data a column contains. For each column in the ColumnFormats array, you can specify:
  • xct_General: Try to convert it to a number, a date, etc.
  • xct_Text : Keep the column as text, even if it can be converted to a number or other things.
  • xct_Skip: Do not import this column.
 

If you need more control, for example to import a text file beginning on cell C4 of an existing worksheet, you should use the LoadFromTextDelim global method (on unit "UTextDelim").

To open a CSV file (Comma Separated Values):

OpenText('Filename', ',' );

 

To open a CSV file (Comma Separated Values) that uses ";" instead of "," to separate the fields:

//This is the way CSV is saved on countries where the "," and not the "." is the decimal separator.
OpenText('Filename', ';' );

 

To open a Tab Delimited file:

OpenText('Filename', #9 );

 

To open a Tab Delimited file, ignore the first column, try to convert the second to number, dates, etc, keep the third as text even if it is a number, and try to convert all the other columns to numbers, dates, etc:

OpenText('Filename', #9,[xct_skip, xct_General, xct_Text] )
Copyright (c) 2002-2008 TMS Software. All rights reserved.
What do you think about this topic? Send feedback!