• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

cfx_ExcelQuery: specify sheet?

Guest
Nov 27, 2006 Nov 27, 2006

Copy link to clipboard

Copied

I installed the cfx_ExcelQuery custom tag which is part of the OpenXCF project and with the help of this forum have been able to successfully read data from an Excel file.

Does anyone know if there is a way to specify a specific worksheet to read by name? By trial and error I discovered that a specific sheet can be accessed by passing an index number (sheet="0") but haven't been able to get it to take a sheet name.

If not - no big deal, it's just that the program I'm working on originally used ODBC and required the user to specify the name of the sheet with the pertinent data.

Thanks in advance,
Ken
TOPICS
Advanced techniques

Views

330

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Nov 27, 2006 Nov 27, 2006
The tag only accepts a number. You could use POI to get the sheet number.

<cfscript>
fis = createObject("java", "java.io.FileInputStream").init("c:\yourFile.xls");
wb = createObject("java", "org.apache.poi.hssf.usermodel.HSSFWorkbook").init(fis);
sheetNumber = wb.getSheetIndex("Sheet1");
fis.close();
</cfscript>
<cfx_ExcelQuery action="read" file="c:\yourFile.xls" sheet="#sheetNumber#" variable="myQuery" />


Votes

Translate

Translate
Guide ,
Nov 27, 2006 Nov 27, 2006

Copy link to clipboard

Copied

The tag only accepts a number. You could use POI to get the sheet number.

<cfscript>
fis = createObject("java", "java.io.FileInputStream").init("c:\yourFile.xls");
wb = createObject("java", "org.apache.poi.hssf.usermodel.HSSFWorkbook").init(fis);
sheetNumber = wb.getSheetIndex("Sheet1");
fis.close();
</cfscript>
<cfx_ExcelQuery action="read" file="c:\yourFile.xls" sheet="#sheetNumber#" variable="myQuery" />


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 27, 2006 Nov 27, 2006

Copy link to clipboard

Copied

LATEST
That works great, thanks so much. It even returns a trappable value (-1) if an invalid name is specified, allowing me to cleanly alert the user.

I really appreciate the help, before I got this straightened out I was about to give up and use COM which I was trying to avoid.

Ken

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation