2.7.37 impMSExcel


Menu Information

Data: Import from File: Excel (XLS, XLSX, XLSM)...

This X-Function supports file re-import. See this topic for details.

Brief Information

Import Excel (XLS, XLSX....) files directly into Origin, without the need for Excel.

Note that prior to Origin 2017, Origin used another Excel X-Function (see impExcel) which launched Excel in the background in order to import XLSX files.

Command Line Usage

1. fname$="sample.xls"; impMSExcel; // import the file sample.xls

2. impMSExcel fname:="c:\test1.xlsxt%(crlf)c:\test2.xlsx" options.sparklines:=1 options.Mode:=4 options.Headers.LongName:=1 options.Headers.Units:=2;

Variables

Display Name
Variable Name
I/O
and
Type
Default Value
Description
File Name
fname

Input

string

fname$

Filename of the file to be imported.

File Info
trfiles

Input

TreeNode

<unassigned>

This is used in the dialog for displaying the file size. The information is detected by Origin automatically.

Import Options
options

Input

TreeNode

<unassigned>

This is mainly used in the dialog, for tweaking the import options.

See more details in Description

Output
orng

Output

Range

<active>

This is used to specify the output range.

Header Info
trheader

Output

TreeNode

<optional>

This is for outputting the header information. It is hidden from the GUI. Users are not advised to use this variable.

Repeat Import

reimp

Input

int

0

Specify whether the current import is a reimporting process. It is hidden from the GUI. Use of this variable is not advised.

Description

This X-Function is used for importing Microsoft Excel files. It doesn't use COM and thus works for .XLS .XLSX and .XLSM files even if Excel is not installed.

  • Menu: Select Data: Import from File: Excel (XLS, XLSX, XLSM)...
  • Command window: type
    impMSExcel -d
    in command window.

The imported Excel workbook can have more than one sheet. All sheets will be imported into separate Origin worksheets in the target workbook, using the same import settings. See Options Tree Details section for details of import settings

From Origin 2015, re-import one or multiple sheets from Excel to Origin is supported. During Excel re-importing, a link is maintained so that Origin is able to use up-to-date data. To re-import Excel files,

  • go to Data: Re-Import Directly or use Ctrl+4 keys to re-import Excel sheets with same settings as before.
  • go to Data: Re-Import... to bring up dialog box to change import settings for files to be re-imported.
  • type command
    reimport -d
    in command window to re-import Excel files.

Origin 2016 introduce a <clone> template, which allows you to import Excel workbook(s) into a prepared workbook template or analysis template to batch customize/analyze data in Excel books. See details in Options Tree Details section.

Options Tree Details

  • Import Options Tree
Please see the impMSExcel Options Treenode Information page for details on the many import options available.

Examples

Example 1

The following example imports an Excel file using factory default options:

  1. Start with a new workbook. From the Origin menu, select Data: Import from File: Excel (XLS, XLSX, XLSM)... This opens the Excel Files dialog for you to choose the import file.
  2. Select file <Origin install folder>/Samples/Import and Export/United States Energy (1980-2013).xls. Click Add File(s) button. Make sure Show Options dialog is checked and click OK.
  3. In the impMSExcel dialog box that opens, specify the header lines as image below. Click Ok to import the Excel file.
ImportMSExcel 01.png

Example 2

The following script command imports an Excel file (c:\test.xls) without opening the dialog:

newbook;
string fname$ = system.path.program$ + "Samples\Graphing\Excel Data.xls";
impMSExcel options.cellfmts:=1 options.headers.MainHeaderLines:=1 options.headers.SubHeaderLines:=1 options.headers.LongName:=1; //copy cell format of Excel file while importing

Example 3

The following script command imports the specified Excel sheets:

newbook;
string fname$ = "c:\test.xls";
impMSExcel options.sheet:=1:3:5; //Import the first, the third and the fifth Excel sheets only
newbook;
impMSExcel options.sheet:=SheetName1:SheetName2; //Import the Excel sheets named SheetName1 and SheetName2

Related X-Functions

impfile, impinfo, impExcel