Java Requires Chilkat v11.3.0+
Chilkat2 Java
XLSX Get Sheet Names
Open an Excel spreadsheet (.xlsx) and get the names of the sheets.Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Csv;
import com.chilkatsoft.chilkat2.StringTable;
import com.chilkatsoft.chilkat2.Zip;
public class ChilkatExample {
public static void main(String[] args) {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// .xlsx files are Zip archives
Zip zip = new Zip();
try {
zip.openZip("qa_data/excel/fakeCompanies.xlsx");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
Csv csv = new Csv();
StringTable sheetNames = new StringTable();
try {
csv.xlsxGetSheets(zip, sheetNames);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
int i = 0;
while (i < sheetNames.getCount()) {
System.out.println(sheetNames.stringAt(i));
i = i + 1;
}
}
}