litLIB Help
Product pages :
Quick links:
help index

File System - FileContents

=FileContents(File [, StartPosition, Length])

This function is both a cell and an array function. To use the array function, select a range of cells (e.g. 5 rows and 1 column). Enter the formula and press Ctrl+Shift+Enter.

Returns the contents of a file. By default 255 characters are returned. Optionally the Length parameter can be given to return more characters (up to 32,000). The StartPosition parameter can be given to return characters starting at a specific offset position.

If used as an array formula it returns a line in each cell. The StartPosition parameter is interpreted as a line number.

FileContents can send up to 32768 characters to the worksheet but only half of these will be shown visibly. Note that when passing more than 255 characters directly into another function (nesting functions ; calling one function inside another function) Excel will return a #Value error.

File : Full name and path of the file

StartPosition : Byte offset position from where the filecontents should be shown. For array formulas, StartPosition is the line number from where to start.

=FileContents("c:\myfile.txt", , 5000)

Array examples:
Select A1 to A10
Enter the following formula and press Ctrl+Shift+Enter

Result: 10 lines of the file will be shown, each in its own cell.