Hello John
Can I ask you please are you getting the error at compile time or runtime?
>From your message, I would expect the former but cannot begin to understand
why.
Just as a double check, I threw together some code this morning and had a
play. Forgive the method name please, I used it earlier to test something
else and did not feel it would be important to change it;
package xssftest;
import java.io.File;
import java.io.FileInputStream;
import java.util.Iterator;
//import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Hyperlink;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new Main().addHyperlinks();
}
public void addHyperlinks() {
File inputFile = null;
FileInputStream fis = null;
Workbook workbook = null;
Sheet sheet = null;
int numSheets = 0;
try {
inputFile = new File("C:/temp/sample.xlsx");
fis = new FileInputStream(inputFile);
workbook = WorkbookFactory.create(fis);
numSheets = workbook.getNumberOfSheets();
for(int i = 0; i < numSheets; i++) {
sheet = workbook.getSheetAt(i);
System.out.println(sheet.getSheetName());
}
}
catch(Exception ex) {
}
finally {
}
}
}
Vile as this piece of code is, it iterates through the sheets in a workbook
and prints out their names. Perhaps you could throw it into your compiler
and see what happens just to remove the possibility of some odd interaction
with the other code in your class(es) dirtying the test?
I am currently running version 3.5 beta 7 and added the following libraries
to my classpath in order for the code to compile (the exact names of the
libraries may differ because it does depend a little on the date they were
compiled and you download them of course)
poi-3.5-beta7-20090613.jar
poi-ooxml-3.5-beta7-20090613.jar
xmlbeans-2.3.0.jar
ooxml-schemas-1.0.jar
dom4j-1.6.1.jar
Finally, and just to be through, I ran the code using both a binary (.xls)
and OpenXML (.xlsx) file as input.
If this code still does not produce the output you expect using your version
of POI, then the obvious advice would be 'download version 3.5 Beta 7'.
Yours
Mark B
John Musbach-3 wrote:
>
> I'm trying to create a ArrayList<String> containing my sheet names, but
> have run
> into a issue in that the Sheet getSheetName() method
> (http://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/Sheet.html#getSheetName())
> doesn't seem to exist per the javadocs. I'm using the 3.5 beta5 binaries,
> the
> following code seems like it should compile but it doesn't. What am I
> doing
> wrong? Thanks!
>
> CODE
> ----
> import javax.swing.*;
> import java.awt.*;
> import org.apache.poi.*;
> import org.apache.poi.hssf.model.*;
> import org.apache.poi.ss.usermodel.*;
> import java.io.*;
> import java.util.*;
> public class GMotionCharts
> {
> private org.apache.poi.ss.usermodel.Workbook wb=null;
> public boolean openXLS(String fName,JLabel jStatus)
> {
> //This method is OK and need not be investigated so the code
> body has been removed
> }
> public ArrayList<String> getCities()
> {
> ArrayList<String> cities=new ArrayList<String>();
> int numSheets=wb.getNumberOfSheets();
> for(int i=0;i<numSheets;i++)
> {
> org.apache.poi.ss.usermodel.Sheet s=wb.getSheetAt(i);
> cities.add(s.getSheetName());
> //<-- This line has the error "The method
> getSheetName() is undefined for the
> type Sheet", even though I've specifically typed the Sheet variable to
> that
> which the javadocs indicates the method exists } } }
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
>
--
View this message in context:
http://www.nabble.com/Bug--tp24063371p24068251.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]