I'm trying to read a spreadsheet using the HSSFWorkbook object.
First off, I know that it would probably be better to save it to a csv first,
but some of the people this is going to be used by would probably loose their
minds if they tried to save into anything other than an xls from Excel.
Ironically, this extremely computer illiterate bunch are literacy teachers, but
I digress.
Anyway, here's the problem I have. I'm trying to run the sheet through loops to
read the whole thing. The problem is that when I try to call getRow or getCell
from within a loop with the loop index as the argument, it throws an error.
Specifically, it throws "The selected method getRow was not found. Either there
are no methods with the specified method name and argument types, or the method
getRow is overloaded with arguments types that ColdFusion can't decipher
reliably." Since it works fine if I pass a number instead of a variable, I'm
assuming the method is overloaded. Frankly, I'm stuck. Here's my code (this is
just a test script, the final product will use the spreadsheet to populate a
database).
<code>
<cfscript>
infile=createObject('java','java.io.FileInputStream').init("D:\inetpub\wwwroot\non-live
code\test.xls");
fs=createObject('java','org.apache.poi.poifs.filesystem.POIFSFileSystem').init(infile);
wb=createObject('java','org.apache.poi.hssf.usermodel.HSSFWorkbook').init(fs);
sheet=wb.getSheetAt(0);
noRows=sheet.getLastRowNum();
writeOutput('<table>');
for (i=0;i LTE noRows;i=i+1){
writeOutput('<tr>');
row=sheet.getRow(i);
noCols=row.getLastCellNum();
for (j=0;j LTE noCols;j=j+1) {
writeOutput('<td>');
try {
cell=row.getCell(j);
value=cell.getStringCellValue();
} catch (Any expt) {
value="";
}
writeOutput(value);
writeOutput('</td>');
}
writeOutput('</tr>');
}
writeOutput('</table>');
</cfscript>
</code>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to
date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f
Archive:
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:319638
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4