EasyXLS™ library allows you to determine the sheet names of an Excel file, to identify a specific sheet and the sheet name can be used for various tasks.
Sometimes is required to find only the names of the sheets from an Excel file. If there are not required other data or objects from the Excel file, EasyXLS provides methods that are fast and very useful to achive this goal. The methods returns an array that contains the sheet names. Depending on the Excef file format, you can use:
// Create an instance of the class that imports XLSX files
ExcelDocument workbook = new ExcelDocument();
// Retrieve sheet namesstring[] sheetNames = workbook.easy_ReadXLSXFile_SheetNames("C:\\Samples\\Excel.xlsx");
// Display sheet namesfor (int sheet=0; sheet < sheetNames.Length; sheet++)
Console.WriteLine(sheetNames[sheet] + "\n");
' Create an instance of the class that imports XLSX filesDim workbook As New ExcelDocument
' Retrieve sheet namesDim sheetNames As String() = workbook.easy_ReadXLSXFile_SheetNames(
"C:\Samples\Excel.xlsx")
' Display sheet namesFor sheet As Integer = 0 To sheetNames.Length - 1
Console.WriteLine(sheetNames(sheet))
Next
C++// Create an instance of the class that imports XLSX files
EasyXLS::IExcelDocumentPtr workbook;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelDocument),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelDocument),
(void**) &workbook);
if(SUCCEEDED(hr)){
// Retrieve sheet names
SAFEARRAY* arraySheetNames = workbook->easy_ReadXLSXFile_SheetNames(
"C:\\Samples\\Excel.xlsx");
BSTR* rawSheetNames;
HRESULT hr = SafeArrayAccessData(arraySheetNames, (void**)&rawSheetNames);
int size = arraySheetNames->rgsabound->cElements;
// Display sheet namesfor (int sheet = 0; sheet < size; sheet++) {
_bstr_t wrapper(rawSheetNames[sheet]);
printf("'%s'\n", (LPCSTR)wrapper);
}
}
C++.NET// Create an instance of the class that imports XLSX files
ExcelDocument ^workbook = gcnew ExcelDocument();
// Retrieve sheet namesarray<String^>^ sheetNames = workbook.easy_ReadXLSXFile_SheetNames(
"C:\\Samples\\Excel.xlsx");
// Display sheet namesfor (int sheet = 0; sheet < sheetNames->Length; sheet++)
Console::Write(sheetNames[sheet] + "\n");
// Create an instance of the class that imports XLSX files
ExcelDocument workbook = new ExcelDocument();
// Retrieve sheet namesString[] sheetNames = workbook.easy_ReadXLSXFile_SheetNames("C:\\Samples\\Excel.xlsx");
// Display sheet namesfor (int sheet=0; sheet < sheetNames.length; sheet++)
System.out.println(sheetNames[sheet] + "\n");
COM+:// Create an instance of the class that imports XLSX files
$workbook = new COM("EasyXLS.ExcelDocument");
// Retrieve sheet names
$sheetNames = $workbook->easy_ReadXLSXFile_SheetNames("C:\Samples\Excel.xlsx");
// Display sheet namesfor ($sheet = 0; $sheet < count($sheetNames); $sheet++)
echo($sheetNames[$sheet]."<br>");
Java:// Create an instance of the class that imports XLSX files
$workbook = new java("EasyXLS.ExcelDocument");
// Retrieve sheet names
$sheetNames = $workbook->easy_ReadXLSXFile_SheetNames("C:\Samples\Excel.xlsx");
// Display sheet namesforeach($sheetNames as $sheetName)
echo($sheetName."<br>");
????????????
?????
??????????
<!-- Create an instance of the class that imports XLSX files --><cfobject type="java"class="EasyXLS.ExcelDocument"name="workbook"action="CREATE"><!-- Retrieve sheet names --><cfset sheetNames=workbook.easy_ReadXLSXFile_SheetNames("C:\Samples\Excel.xlsx")><!-- Display sheet names --><cfloop from="1"to="#arrayLen(sheetNames)#"index="sheet"><cfoutput>
#sheetNames[sheet]#<br></cfoutput></cfloop>
.NET:# Create an instance of the class that imports XLSX files
workbook = ExcelDocument()
# Retrieve sheet names
sheetNames = workbook.easy_ReadXLSXFile_SheetNames("C:\\Samples\\Excel.xlsx")
# Display sheet namesfor sheet in range(len(sheetNames)):
print(sheetNames[sheet])
Java:# Create an instance of the class that imports XLSX files
workbook = gateway.jvm.ExcelDocument()
# Retrieve sheet names
sheetNames = workbook.easy_ReadXLSXFile_SheetNames("C:\\Samples\\Excel.xlsx")
# Display sheet namesfor sheet in range(len(sheetNames)):
print(sheetNames[sheet])
Load the entire Excel file and extract sheet names
Sometimes is more convenient to load the entire Excel file data, formats or objects, if these elements are required later into the application. The Excel file is loaded wholly along with the sheet names.
// Create an instance of the class that imports XLSX files
ExcelDocument workbook = new ExcelDocument();
// Load Excel file
workbook.easy_LoadXLSXFile("C:\\Samples\\Excel.xlsx");
// Display sheet namesfor (int sheet=0; sheet < workbook.SheetCount(); sheet++)
Console.WriteLine(workbook.easy_getSheetAt(sheet).getSheetName() + "\n");
' Create an instance of the class that imports XLSX filesDim workbook As New ExcelDocument
' Load Excel file
workbook.easy_LoadXLSXFile("C:\Samples\Excel.xlsx")
' Display sheet namesFor sheet As Integer = 0 To workbook.SheetCount - 1
Console.WriteLine(workbook.easy_getSheetAt(sheet).getSheetName())
Next
C++// Create an instance of the class that imports XLSX files
EasyXLS::IExcelDocumentPtr workbook;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelDocument),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelDocument),
(void**) &workbook);
if(SUCCEEDED(hr)){
// Load Excel file
workbook->easy_LoadXLSXFile("C:\\Samples\\Excel.xlsx");
// Display sheet namesfor (int sheet = 0; sheet < workbook->SheetCount(); sheet++)
printf(workbook->easy_getSheetAt(sheet)->getSheetName() + "\n");
}
C++.NET// Create an instance of the class that imports XLSX files
ExcelDocument ^workbook = gcnew ExcelDocument();
// Load Excel file
workbook.easy_LoadXLSXFile("C:\\Samples\\Excel.xlsx");
// Display sheet namesfor (int sheet = 0; sheet < workbook->SheetCount(); sheet++)
Console::Write(workbook->easy_getSheetAt(sheet)->getSheetName() + "\n");
// Create an instance of the class that imports XLSX files
ExcelDocument workbook = new ExcelDocument();
// Load Excel file
workbook.easy_LoadXLSXFile("C:\\Samples\\Excel.xlsx");
// Display sheet namesfor (int sheet=0; sheet < workbook.SheetCount(); sheet++)
System.out.println(workbook.easy_getSheetAt(sheet).getSheetName());
COM+:// Create an instance of the class that imports XLSX files
$workbook = new COM("EasyXLS.ExcelDocument");
// Load Excel file
$workbook->easy_LoadXLSXFile("C:\Samples\Excel.xlsx");
// Display sheet namesfor ($sheet = 0; $sheet < $workbook->SheetCount(); $sheet++)
echo $workbook->easy_getSheetAt($sheet)->getSheetName()."<br>";
Java:// Create an instance of the class that imports XLSX files
$workbook = new java("EasyXLS.ExcelDocument");
// Load Excel file
$workbook->easy_LoadXLSXFile("C:\Samples\Excel.xlsx");
// Display sheet namesfor ($sheet = 0; $sheet < (int)(string)$workbook->SheetCount(); $sheet++)
echo $workbook->easy_getSheetAt($sheet)->getSheetName()."<br>";
' Create an instance of the class that imports XLSX filesset workbook = Server.CreateObject("EasyXLS.ExcelDocument")
' Load Excel file
workbook.easy_LoadXLSXFile("C:\Samples\Excel.xlsx")
' Display sheet namesfor sheet=0 to workbook.SheetCount()-1
response.write(workbook.easy_getSheetAt(sheet).getSheetName() & "<br>")
next
' Create an instance of the class that imports XLSX filesSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Load Excel file
workbook.easy_LoadXLSXFile("C:\Samples\Excel.xlsx")
' Display sheet namesFor sheet=0 To workbook.SheetCount()-1
Me.Label1.Caption = Me.Label1.Caption & vbCrLf & _
workbook.easy_getSheetAt(sheet).getSheetName()
Next
' Create an instance of the class that imports XLSX filesSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Load Excel file
workbook.easy_LoadXLSXFile("C:\Samples\Excel.xlsx")
' Display sheet namesFor sheet=0 To workbook.SheetCount()-1
WScript.StdOut.Write(vbcrlf & workbook.easy_getSheetAt(sheet).getSheetName())
Next
<!-- Create an instance of the class that imports XLSX files --><cfobject type="java"class="EasyXLS.ExcelDocument"name="workbook"action="CREATE"><!-- Load Excel file --><cfset ret = workbook.easy_LoadXLSXFile("C:\Samples\Excel.xlsx")><!-- Display sheet names --><cfloop from="1"to="#workbook.SheetCount()-1#"index="sheet"><cfoutput>
#workbook.easy_getSheetAt(sheet).getSheetName()#<br></cfoutput></cfloop>
.NET:# Create an instance of the class that imports XLSX files
workbook = ExcelDocument()
# Load Excel file
workbook.easy_LoadXLSXFile("C:\\Samples\\Excel.xlsx")
# Display sheet namesfor sheet in range(workbook.SheetCount()):
print(workbook.easy_getSheetAt(sheet).getSheetName())
Java:# Create an instance of the class that imports XLSX files
workbook = gateway.jvm.ExcelDocument()
# Load Excel file
workbook.easy_LoadXLSXFile("C:\\Samples\\Excel.xlsx")
# Display sheet namesfor sheet in range(workbook.SheetCount()):
print(workbook.easy_getSheetAt(sheet).getSheetName())