TExcelFile.Open Method
Overloads
- TExcelFile.Open(string)
- TExcelFile.Open(TStream)
- TExcelFile.Open(string, TFileFormats, Char, Integer, Integer, TColumnImportTypeArray)
- TExcelFile.Open(TStream, TFileFormats, Char, Integer, Integer, TColumnImportTypeArray)
- TExcelFile.Open(TStream, TFileFormats, Char, Integer, Integer, TColumnImportTypeArray, Boolean)
- TExcelFile.Open(string, TFileFormats, Char, Integer, Integer, TColumnImportTypeArray, TEncoding, Boolean)
- TExcelFile.Open(TStream, TFileFormats, Char, Integer, Integer, TColumnImportTypeArray, TEncoding, Boolean)
- TExcelFile.Open(string, TFileFormats, Char, Integer, Integer, TColumnImportTypeArray, TArray<string>, TEncoding, Boolean)
- TExcelFile.Open(TStream, TFileFormats, Char, Integer, Integer, TColumnImportTypeArray, TArray<string>, TEncoding, Boolean)
TExcelFile.Open(string)
Loads a new Spreadsheet from disk.
Syntax
Unit: FlexCel.Core
procedure TExcelFile.Open(const fileName: string); overload;
Parameters
<-> | Parameter | Type | Description |
---|---|---|---|
const | fileName | string | File to open. |
See also
TExcelFile.Open(TStream)
Loads a new Spreadsheet from a stream.
Syntax
Unit: FlexCel.Core
procedure TExcelFile.Open(const aStream: TStream); overload;
Parameters
<-> | Parameter | Type | Description |
---|---|---|---|
const | aStream | TStream | Stream to Load, must be a seekable stream. Verify it is on the correct position. |
See also
TExcelFile.Open(string, TFileFormats, Char, Integer, Integer, TColumnImportTypeArray)
Loads a new Spreadsheet from disk, on one of the specified formats.
Syntax
Unit: FlexCel.Core
procedure TExcelFile.Open(const fileName: string; const fileFormat: TFileFormats; const delimiter: Char; const firstRow: Integer; const firstCol: Integer; const columnFormats: TArray<TColumnImportType>); overload;
Parameters
<-> | Parameter | Type | Description |
---|---|---|---|
const | fileName | string | File to open |
const | fileFormat | TFileFormats | List with possible file formats to try |
const | delimiter | Char | Delimiter used to separate columns, if the format is TFileFormats.Text |
const | firstRow | Integer | First row where we will copy the cells on the new sheet, for TFileFormats.Text |
const | firstCol | Integer | First column where we will copy the cells on the new sheet, for TFileFormats.Text |
const | columnFormats | TArray<TColumnImportType> | An array of TColumnImportType elements, telling how each column should be imported. |
See also
TExcelFile.Open(TStream, TFileFormats, Char, Integer, Integer, TColumnImportTypeArray)
Loads a new Spreadsheet from a stream, on one of the specified formats.
Syntax
Unit: FlexCel.Core
procedure TExcelFile.Open(const aStream: TStream; const fileFormat: TFileFormats; const delimiter: Char; const firstRow: Integer; const firstCol: Integer; const columnFormats: TArray<TColumnImportType>); overload;
Parameters
<-> | Parameter | Type | Description |
---|---|---|---|
const | aStream | TStream | Stream to open, must be a seekable stream. Verify it is on the correct position. |
const | fileFormat | TFileFormats | List with possible file formats to try. |
const | delimiter | Char | Delimiter used to separate columns, if the format is TFileFormats.Text |
const | firstRow | Integer | First row where we will copy the cells on the new sheet, for TFileFormats.Text |
const | firstCol | Integer | First column where we will copy the cells on the new sheet, for TFileFormats.Text |
const | columnFormats | TArray<TColumnImportType> | An array of TColumnImportType elements, telling how each column should be imported. See the example for more information on how to use it. |
Examples
Imagine you have a file with 20 columns, and column 2 has numbers you want to be imported as text (like phone numbers), and you don't want to import column 10.
You can use the following code to do it:
var
ColTypes: TArray<TColumnImportType>;
xls: TExcelFile;
begin
SetLength(ColTypes, 10); //You just need to define 10 items, all other columns after 10 will be imported with default formatting.
ColTypes[1] := TColumnImportType.Text; //Import whatever is in column 2 as text.
ColTypes[9] := TColumnImportType.Skip; //don't import column 10.
xls := TXlsFile.Create(true); //Create a new file.
try
xls.Open('csv.csv', TFileFormats.Text, ',', 1, 1, ColTypes); //Import the csv text.
Process(xls);
finally
xls.Free;
end;
See also
TExcelFile.Open(TStream, TFileFormats, Char, Integer, Integer, TColumnImportTypeArray, Boolean)
Loads a new Spreadsheet from a stream, on one of the specified formats.
Syntax
Unit: FlexCel.Core
procedure TExcelFile.Open(const aStream: TStream; const fileFormat: TFileFormats; const delimiter: Char; const firstRow: Integer; const firstCol: Integer; const columnFormats: TArray<TColumnImportType>; const detectEncodingFromByteOrderMarks: Boolean); overload;
Parameters
<-> | Parameter | Type | Description |
---|---|---|---|
const | aStream | TStream | Stream to open, must be a seekable stream. Verify it is on the correct position. |
const | fileFormat | TFileFormats | List with possible file formats to try. |
const | delimiter | Char | Delimiter used to separate columns, if the format is TFileFormats.Text |
const | firstRow | Integer | First row where we will copy the cells on the new sheet, for TFileFormats.Text |
const | firstCol | Integer | First column where we will copy the cells on the new sheet, for TFileFormats.Text |
const | columnFormats | TArray<TColumnImportType> | An array of TColumnImportType elements, telling how each column should be imported. See the example for more information on how to use it. |
const | detectEncodingFromByteOrderMarks | Boolean | This parameter only applies when reading Text files. It is the same on the constructor of a StreamReader, and it says if BOM must be used at the beginning of the file. It defaults to true. |
Examples
Imagine you have a file with 20 columns, and column 2 has numbers you want to be imported as text (like phone numbers), and you don't want to import column 10.
You can use the following code to do it:
var
ColTypes: TArray<TColumnImportType>;
xls: TExcelFile;
begin
SetLength(ColTypes, 10); //You just need to define 10 items, all other columns after 10 will be imported with default formatting.
ColTypes[1] := TColumnImportType.Text; //Import whatever is in column 2 as text.
ColTypes[9] := TColumnImportType.Skip; //don't import column 10.
xls := TXlsFile.Create(true); //Create a new file.
try
xls.Open('csv.csv', TFileFormats.Text, ',', 1, 1, ColTypes); //Import the csv text.
Process(xls);
finally
xls.Free;
end;
See also
TExcelFile.Open(string, TFileFormats, Char, Integer, Integer, TColumnImportTypeArray, TEncoding, Boolean)
Loads a new Spreadsheet from disk, on one of the specified formats.
Syntax
Unit: FlexCel.Core
procedure TExcelFile.Open(const fileName: string; const fileFormat: TFileFormats; const delimiter: Char; const firstRow: Integer; const firstCol: Integer; const columnFormats: TArray<TColumnImportType>; const fileEncoding: TEncoding; const detectEncodingFromByteOrderMarks: Boolean); overload;
Parameters
<-> | Parameter | Type | Description |
---|---|---|---|
const | fileName | string | File to open |
const | fileFormat | TFileFormats | List with possible file formats to try |
const | delimiter | Char | Delimiter used to separate columns, if the format is TFileFormats.Text |
const | firstRow | Integer | First row where we will copy the cells on the new sheet, for TFileFormats.Text |
const | firstCol | Integer | First column where we will copy the cells on the new sheet, for TFileFormats.Text |
const | columnFormats | TArray<TColumnImportType> | An array of TColumnImportType elements, telling how each column should be imported. |
const | fileEncoding | TEncoding | Encoding used by the file we are reading, when opening a Text-delimited file (csv or txt). If you specify an encoding for xls95 files, it will overwrite the default encoding specified in the file, and this can be used to read buggy or corrupted xls95 files. But in general for xls95 you should keep this parameter null. This parameter has no effect on xls 97 files or xlsx. If null when reading text files, it is assumed to be Encoding.UTF8. |
const | detectEncodingFromByteOrderMarks | Boolean | This parameter only applies when reading Text files. It is the same on the constructor of a StreamReader, and it says if BOM must be used at the beginning of the file. It defaults to true. |
See also
TExcelFile.Open(TStream, TFileFormats, Char, Integer, Integer, TColumnImportTypeArray, TEncoding, Boolean)
Loads a new Spreadsheet from a stream, on one of the specified formats.
Syntax
Unit: FlexCel.Core
procedure TExcelFile.Open(const aStream: TStream; const fileFormat: TFileFormats; const delimiter: Char; const firstRow: Integer; const firstCol: Integer; const columnFormats: TArray<TColumnImportType>; const fileEncoding: TEncoding; const detectEncodingFromByteOrderMarks: Boolean); overload;
Parameters
<-> | Parameter | Type | Description |
---|---|---|---|
const | aStream | TStream | Stream to open, must be a seekable stream. Verify it is on the correct position. |
const | fileFormat | TFileFormats | List with possible file formats to try. |
const | delimiter | Char | Delimiter used to separate columns, if the format is TFileFormats.Text |
const | firstRow | Integer | First row where we will copy the cells on the new sheet, for TFileFormats.Text |
const | firstCol | Integer | First column where we will copy the cells on the new sheet, for TFileFormats.Text |
const | columnFormats | TArray<TColumnImportType> | An array of TColumnImportType elements, telling how each column should be imported. See the example for more information on how to use it. |
const | fileEncoding | TEncoding | Encoding used by the file we are reading, when opening a Text-delimited file (csv or txt). If you specify an encoding for xls95 files, it will overwrite the default encoding specified in the file, and this can be used to read buggy or corrupted xls95 files. But in general for xls95 you should keep this parameter null. This parameter has no effect on xls 97 files or xlsx. If null when reading text files, it is assumed to be Encoding.UTF8. |
const | detectEncodingFromByteOrderMarks | Boolean | This parameter only applies when reading Text files. It is the same on the constructor of a StreamReader, and it says if BOM must be used at the beginning of the file. It defaults to true. |
Examples
Imagine you have a file with 20 columns, and column 2 has numbers you want to be imported as text (like phone numbers), and you don't want to import column 10.
You can use the following code to do it:
var
ColTypes: TArray<TColumnImportType>;
xls: TExcelFile;
begin
SetLength(ColTypes, 10); //You just need to define 10 items, all other columns after 10 will be imported with default formatting.
ColTypes[1] := TColumnImportType.Text; //Import whatever is in column 2 as text.
ColTypes[9] := TColumnImportType.Skip; //don't import column 10.
xls := TXlsFile.Create(true); //Create a new file.
try
xls.Open('csv.csv', TFileFormats.Text, ',', 1, 1, ColTypes); //Import the csv text.
Process(xls);
finally
xls.Free;
end;
See also
TExcelFile.Open(string, TFileFormats, Char, Integer, Integer, TColumnImportTypeArray, TArray<string>, TEncoding, Boolean)
Loads a new Spreadsheet from disk, on one of the specified formats.
Syntax
Unit: FlexCel.Core
procedure TExcelFile.Open(const fileName: string; const fileFormat: TFileFormats; const delimiter: Char; const firstRow: Integer; const firstCol: Integer; const columnFormats: TArray<TColumnImportType>; const dateFormats: TArray<string>; const fileEncoding: TEncoding; const detectEncodingFromByteOrderMarks: Boolean); overload; virtual; abstract;
Parameters
<-> | Parameter | Type | Description |
---|---|---|---|
const | fileName | string | File to open |
const | fileFormat | TFileFormats | List with possible file formats to try |
const | delimiter | Char | Delimiter used to separate columns, if the format is TFileFormats.Text |
const | firstRow | Integer | First row where we will copy the cells on the new sheet, for TFileFormats.Text |
const | firstCol | Integer | First column where we will copy the cells on the new sheet, for TFileFormats.Text |
const | columnFormats | TArray<TColumnImportType> | An array of TColumnImportType elements, telling how each column should be imported. |
const | dateFormats | TArray<string> | Note:This format must be expressed with .NET notation, as specified here: http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx .A list of formats allowed for dates and times, when opening text files. Windows is a little liberal in what it thinks can be a date, and it can convert things like "1.2" into dates. By setting this property, you can ensure the dates are only in the formats you expect. If you leave it null, we will trust "DateTime.TryParse" to guess the correct values. This value has no meaning in normal xls files, only text files. |
const | fileEncoding | TEncoding | Encoding used by the file we are reading, when opening a Text-delimited file (csv or txt). If you specify an encoding for xls95 files, it will overwrite the default encoding specified in the file, and this can be used to read buggy or corrupted xls95 files. But in general for xls95 you should keep this parameter null. This parameter has no effect on xls 97 files or xlsx. If null when reading text files, it is assumed to be Encoding.UTF8. |
const | detectEncodingFromByteOrderMarks | Boolean | This parameter only applies when reading Text files. It is the same on the constructor of a StreamReader, and it says if BOM must be used at the beginning of the file. It defaults to true. |
See also
TExcelFile.Open(TStream, TFileFormats, Char, Integer, Integer, TColumnImportTypeArray, TArray<string>, TEncoding, Boolean)
Loads a new Spreadsheet from a stream, on one of the specified formats.
Syntax
Unit: FlexCel.Core
procedure TExcelFile.Open(const aStream: TStream; const fileFormat: TFileFormats; const delimiter: Char; const firstRow: Integer; const firstCol: Integer; const columnFormats: TArray<TColumnImportType>; const dateFormats: TArray<string>; const fileEncoding: TEncoding; const detectEncodingFromByteOrderMarks: Boolean); overload; virtual; abstract;
Parameters
<-> | Parameter | Type | Description |
---|---|---|---|
const | aStream | TStream | Stream to open, must be a seekable stream. Verify it is on the correct position. |
const | fileFormat | TFileFormats | List with possible file formats to try. |
const | delimiter | Char | Delimiter used to separate columns, if the format is TFileFormats.Text |
const | firstRow | Integer | First row where we will copy the cells on the new sheet, for TFileFormats.Text |
const | firstCol | Integer | First column where we will copy the cells on the new sheet, for TFileFormats.Text |
const | columnFormats | TArray<TColumnImportType> | An array of TColumnImportType elements, telling how each column should be imported. See the example for more information on how to use it. |
const | dateFormats | TArray<string> | Note:This format must be expressed with .NET notation, as specified here: http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx .A list of formats allowed for dates and times, when opening text files. Windows is a little liberal in what it thinks can be a date, and it can convert things like "1.2" into dates. By setting this property, you can ensure the dates are only in the formats you expect. If you leave it null, we will trust "DateTime.TryParse" to guess the correct values. This value has no meaning in normal xls files, only text files. |
const | fileEncoding | TEncoding | Encoding used by the file we are reading, when opening a Text-delimited file (csv or txt). If you specify an encoding for xls95 files, it will overwrite the default encoding specified in the file, and this can be used to read buggy or corrupted xls95 files. But in general for xls95 you should keep this parameter null. This parameter has no effect on xls 97 files or xlsx. If null when reading text files, it is assumed to be Encoding.UTF8. |
const | detectEncodingFromByteOrderMarks | Boolean | This parameter only applies when reading Text files. It is the same on the constructor of a StreamReader, and it says if BOM must be used at the beginning of the file. It defaults to true. |
Examples
Imagine you have a file with 20 columns, and column 2 has numbers you want to be imported as text (like phone numbers), and you don't want to import column 10.
You can use the following code to do it:
var
ColTypes: TArray<TColumnImportType>;
xls: TExcelFile;
begin
SetLength(ColTypes, 10); //You just need to define 10 items, all other columns after 10 will be imported with default formatting.
ColTypes[1] := TColumnImportType.Text; //Import whatever is in column 2 as text.
ColTypes[9] := TColumnImportType.Skip; //don't import column 10.
xls := TXlsFile.Create(true); //Create a new file.
try
xls.Open('csv.csv', TFileFormats.Text, ',', 1, 1, ColTypes); //Import the csv text.
Process(xls);
finally
xls.Free;
end;