Page 1 of 1

Importing from Excel 2007

Posted: Mon Apr 18, 2011 11:47 am
by LanceCarey
I am trying to import data from Excel 2007 (.xlsx) in a program. Is there a way to only import only the first three columns (or a certain range) in command mode?

Re: Importing from Excel 2007

Posted: Mon Apr 18, 2011 1:20 pm
by EViews Glenn
From the documentation for wfopen. The syntax for reading Excel and Lotus files is:

wfopen(options) source_description [table_description] [variables_description]

The following table_description elements may be used when reading Excel and Lotus data:

"range = arg", where arg is a range of cells to read from the Excel workbook, following the standard Excel format [worksheet!][topleft_cell[:bottomright_cell]].

If the worksheet name contains spaces, it should be placed in single quotes. If the worksheet name is omitted, the cell range is assumed to refer to the currently active sheet. If only a top left cell is provided, a bottom right cell will be chosen automatically to cover the range of non-empty cells adjacent to the specified top left cell. If only a sheet name is provided, the first set of non-empty cells in the top left corner of the chosen worksheet will be selected automatically. As an alternative to specifying an explicit range, a name which has been defined inside the excel workbook to refer to a range or cell may be used to specify the cells to read.

The same syntax should work for import and xlsx files.

Re: Importing from Excel 2007

Posted: Thu Dec 22, 2016 9:03 am
by denolo
Hi,

I have an question related to importing Excel files (2007) with worksheet names containing spaces.
Placing the name in single quotes works fine in the command box. However in a program file the single quotes start a comment section directly after range='...

import... .xlsx range='CUP N'!$B$19:$AZ$166 colhead=4 na="#N/A" @freq Q 1995Q1 @smpl @all

When I rename the worksheet omitting the space, the code works fine. However, renaming all my worksheets is not really an option.

Is there something I can do? or maybe a workaround. I'm using Eviews 9.

Thanks in advance and Merry Chrismas.

Re: Importing from Excel 2007

Posted: Thu Dec 22, 2016 9:32 am
by EViews Steve
Use double-quotes around the page name:

Code: Select all

import... .xlsx range="CUP N"!$B$19:$AZ$166 colhead=4 na="#N/A" @freq Q 1995Q1 @smpl @all
If you perform the import using our import wizard (File/Import/Import from file...), the captured command will use double quotes in the final output. If you're not seeing this properly from the captured command, I believe there was a fix recently made to resolve sheetnames with spaces in them. Update your copy of EViews 9 to the latest version.

Steve