(Java) XLSX Get Sheet Names
Open an Excel spreadsheet (.xlsx) and get the names of the sheets. Note: This example requires Chilkat v11.3.0 or greater.
import com.chilkatsoft.*;
public class ChilkatExample {
static {
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
boolean success = false;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// .xlsx files are Zip archives
CkZip zip = new CkZip();
success = zip.OpenZip("qa_data/excel/fakeCompanies.xlsx");
if (success == false) {
System.out.println(zip.lastErrorText());
return;
}
CkCsv csv = new CkCsv();
CkStringTable sheetNames = new CkStringTable();
success = csv.XlsxGetSheets(zip,sheetNames);
if (success == false) {
System.out.println(csv.lastErrorText());
return;
}
int i = 0;
while (i < sheetNames.get_Count()) {
System.out.println(sheetNames.stringAt(i));
i = i+1;
}
}
}
|