Spread Windows Forms 12.0 Product Documentation
Opening a Custom Text File
Spread Windows Forms 12.0 Product Documentation > Developer's Guide > Managing File Operations > Opening Existing Files > Opening a Custom Text File

You can open existing text files that are delimited, either files saved from Spread or delimited text files from other sources. The data from the file you open is placed in the sheet for which you call the method.

If the file uses custom delimiters (such as commas in csv files), you must specify the delimiters so the component can correctly place the data within the sheet. If your file uses standard tab-delimited format, you need not use a method that lets you specify delimiters.

If you upgraded from a version prior to version 5, then you may wish to replace any obsolete parameters in the LoadTextFile methods.

For more details and current parameters, refer to the LoadTextFile or LoadTextFileRange methods in the SheetView class.

For instructions for saving to text files, see Saving to a Text File.

Using Code

Use any of the LoadTextFile methods in the SheetView class (for the ActiveSheet or Sheets object).

Example

This example opens a text file and handles the headers and specifies the delimiters.

C#
Copy Code
fpSpread1.ActiveSheet.LoadTextFile("C:\\textfile.txt", FarPoint.Win.Spread.TextFileFlags.Unformatted, FarPoint.Win.Spread.Model.IncludeHeaders.BothCustomOnly, "\n", ",", "");
VB
Copy Code
fpSpread1.ActiveSheet.LoadTextFile("C:\textfile.txt", FarPoint.Win.Spread.TextFileFlags.Unformatted, FarPoint.Win.Spread.Model.IncludeHeaders.BothCustomOnly, Chr(10), ",", "")

Using the Spread Designer

  1. From the File menu, select Open.
  2. A dialog appears warning you that this overwrites your existing settings if you open a file. Click Yes to continue with the file open.

    The Open dialog appears.

  3. Change the Files of type box to Custom text files (*.txt).

    To open a comma-delimited file, change the Files of type box to Comma-delimited files (*.csv).

  4. Specify the path and file name of the file to open, and then click Open.

    If the file is opened successfully, a message appears stating the file has been opened.

  5. Click OK to close the Spread Designer.