Gets the Type that is the data type of the cell value with specified row and column index.
[Visual Basic] Overloads Public Function GetCellType( _ ByVal row As Integer, _ ByVal col As Integer ) As Type [C#] public type GetCellType( int row, int col );
The value of the cell.
Exception Type | Condition |
---|---|
IndexOutOfRangeException | Row or column index is out of range of the allowed values. See Remarks for more details about valid values for the row and col parameters. |
InvalidOperationException | Connection to Excel workbook file is closed. |
GetCellType method treats spreadsheet as a two-dimensional array where all column and row indexes start with 1. Method accepts following range of values, dependng on format of source Excel file.
Excel File Format | Rows index range | Columns index range |
---|---|---|
XLS, XLT | 1-65536 | 1-256 |
XLSX, XLSM, XLTX, XLTM | 1-1048576 | 1-16384 |
[C#, Visual Basic] The following example uses the ExcelCommand, ExcelDataPicker and ExcelConnection , to retrieve type of specified cell inside of the Microsoft® Excel worksheet.
[C#]
using VM.xPort.ExcelClient;
private void GetCellType()
{
//Sample code retrieves cell type from individual cell inside of the spreadsheet
ExcelDataPicker picker;
picker = GetDataPicker("AuthorsInfo.xlsx", "xlsx", false, CommandBehavior.CloseConnection, "Authors");
//Retrieve cell type using row and column indexes (indexes are 1-based)
Debug.WriteLine("Cell Type: " + picker.GetCellType(1, 1).ToString());
//Release all opened resources
picker.Close();
picker.Dispose();
picker = null;
}
private ExcelDataPicker GetDataPicker(string fileName, string format, bool hasHeader, CommandBehavior behavior, string sheetName)
{
ExcelConnection connection;
ExcelDataPicker resultPicker;
ExcelCommand excelCommand;
//Create connection to the workbook
connection = new ExcelConnection("Data Source=" + fileName + ";HDR=" + hasHeader.ToString() + ";Format=" + format + ";");
connection.Open();
//Create command and specify from which spreadsheet to query data.
excelCommand = new ExcelCommand(sheetName, connection);
//Create DataPicker that will read values from spreadsheet
resultPicker = excelCommand.ExecutePicker(behavior);
return resultPicker;
}
[Visual Basic]
Imports VM.xPort.ExcelClient
Private Sub GetCellType()
'Sample code retrieves cell type from individual cell inside of the spreadsheet
Dim picker As ExcelDataPicker
picker = GetDataPicker("AuthorsInfo.xlsx", "xlsx", False, CommandBehavior.CloseConnection, "Authors")
'Retrieve cell type using row and column indexes (indexes are 1-based)
Debug.WriteLine("Cell Type: " & picker.GetCellType(1, 1).ToString())
'Release all opened resources
picker.Close()
picker.Dispose()
picker = Nothing
End Sub
Private Function GetDataPicker(ByVal fileName As String, ByVal format As String, ByVal hasHeader As Boolean, _
ByVal behavior As CommandBehavior, ByVal sheetName As String) As ExcelDataPicker
Dim connection As ExcelConnection
Dim resultPicker As ExcelDataPicker
Dim excelCommand As ExcelCommand
'Create connection to the workbook
connection = New ExcelConnection("Data Source=" & fileName & ";HDR=" & hasHeader.ToString() & ";Format=" & format & ";")
connection.Open()
'Create command and specify from which spreadsheet to query data.
excelCommand = New ExcelCommand(sheetName, connection)
'Create DataPicker that will read values from spreadsheet
resultPicker = excelCommand.ExecutePicker(behavior)
Return resultPicker
End Function
Supported in: 4.0, 3.5, 3.0, 2.0
VM.xPort.ExcelClient (in VM.xPort.ExcelClient.dll)
ExcelDataPicker Class | ExcelDataPicker Members | VM.xPort.ExcelClient Namespace