Reading and Writing Data from/To a File

You can read and write data using functions, or Data components, available from the Insert > Data menu and the Insert > Components menu. The Data Import Wizard, File Input and Data Table components allow you to assign data to a variable. The Wizard and File Input components establish an updatable connection to a data file; Data Tables import data once. The output of these components can be manipulated like any other Mathcad array.

The File Output and Output Table components let you write the contents of an array to a file. The functions allow you to change file names without activating the component, append data to existing files, and read and write files inside program loops.

Tutorial: Handling Data

Linking to a data file

To establish a connection for reading a data file, use the Data File Input component:

  1. Choose Data from the Insert menu, then choose File Input from the resulting list. This launches the File Input Setup Wizard.

  2. Choose the file type, and the number of rows or columns of data that are read, or, in the case of Excel worksheets, specify named ranges or cell ranges.

When you are done, enter the array variable name containing your data in the placeholder that appears at the left of the component. If you are having trouble importing your data because the File Input component doesn't recognize the file type, or you need more control over the import options, use the more sophisticated File Import Wizard.

To establish a connection for writing a data file, use the Data File Output component:

  1. Choose Data from the Insert menu, then choosing File Output from the resulting list. This launches the File Output Setup Wizard.

  2. When you are done, enter the array variable name containing your data in the placeholder that appears at the bottom of the component. The variable containing the data must be an array, or a function which produces an array.

Each time you calculate the worksheet, the data is read from/written to the specified file. You can modify the files, or change properties of these components by right-clicking and choosing Properties.

Importing/Exporting/Copying Data once from/to a File

To import data once from a data file, use a Data Table:

  1. Choose Data from the Insert menu, then choose Table from the resulting list. A table with row and column labels appears in your worksheet.

  2. Right-click on the upper left corner of the Data Table, and choose Import, or simply type data in the table cells. You can also paste tabular data into a Data Table by right-clicking on the corner and choosing Paste Table.

  3. You can further configure the Table by right-clicking on the corner and choosing Properties.

To export data once from a matrix:

  1. Display the results as an output table. Large matrices display this way automatically. For small arrays, you may have to specify the display from the Result Format dialog.

  2. Right-click on the corner of the output table and choose Export from the resulting menu to bring up the Write to File dialog box.

To copy and paste some or all of your data, select the cells you wish to copy, or right-click on the corner of the Output Table and choose Select All from the menu. Right-click again, and choose Copy Selection, to copy the contents to the clipboard.

Notes:

QuickSheet

Related Topics