// Create an instance of the class that imports CSV files
ExcelDocument workbook = new ExcelDocument();
// Import CSV file
workbook.easy_LoadCSVFile("C:\\Samples\\Tutorial30.csv");
' Create an instance of the class that imports CSV filesDim workbook As New ExcelDocument
' Import CSV file
workbook.easy_LoadCSVFile("C:\Samples\Tutorial30.csv")
C++// Create an instance of the class that imports CSV files
EasyXLS::IExcelDocumentPtr workbook;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelDocument),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelDocument),
(void**) &workbook);
// Import CSV file
workbook->easy_LoadCSVFile("C:\\Samples\\Tutorial30.csv");
Click here to see Continuous Code ListingC++.NET// Create an instance of the class that imports CSV files
ExcelDocument ^workbook = gcnew ExcelDocument();
// Import CSV file
workbook->easy_LoadCSVFile("C:\\Samples\\Tutorial30.csv");
Click here to see Continuous Code Listing
// Create an instance of the class that imports CSV files
ExcelDocument workbook = new ExcelDocument();
// Import CSV file
workbook.easy_LoadCSVFile("C:\\Samples\\Tutorial30.csv");
.NET:// Create an instance of the class that imports CSV files
$workbook = new COM("EasyXLS.ExcelDocument");
// Import CSV file
$workbook->easy_LoadCSVFile("C:\\Samples\\Tutorial30.csv");
Click here to see Continuous Code ListingJava:// Create an instance of the class that imports CSV files
$workbook = new java("EasyXLS.ExcelDocument");
// Import CSV file
$workbook->easy_LoadCSVFile("C:\\Samples\\Tutorial30.csv");
Click here to see Continuous Code Listing
' Create an instance of the class that imports CSV filesSet workbook = Server.CreateObject("EasyXLS.ExcelDocument")
' Import CSV file
workbook.easy_LoadCSVFile("C:\Samples\Tutorial30.csv")
' Create an instance of the class that imports CSV filesSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Import CSV file
workbook.easy_LoadCSVFile("C:\Samples\Tutorial30.csv")
' Create an instance of the class that imports CSV filesSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Import CSV file
workbook.easy_LoadCSVFile("C:\Samples\Tutorial30.csv")
<!-- Create an instance of the class that imports CSV files --><cfobject type="java"class="EasyXLS.ExcelDocument"name="workbook"action="CREATE"><!-- Import CSV file --><cfset success = workbook.easy_LoadCSVFile("C:\Samples\Tutorial30.csv")>
.NET:# Create an instance of the class used to import/export Excel files
workbook = ExcelDocument()
# Import CSV file
workbook.easy_LoadCSVFile("C:\\Samples\\Tutorial30.csv")
Click here to see Continuous Code ListingJava:# Create an instance of the class used to import/export Excel files
workbook = gateway.jvm.ExcelDocument()
# Import CSV file
workbook.easy_LoadCSVFile("C:\\Samples\\Tutorial30.csv")
Click here to see Continuous Code Listing
The screen shot below represents the imported CSV file in the above code sample.
// Create an instance of the class that imports CSV files
ExcelDocument workbook = new ExcelDocument();
// Import CSV file with specific encoding
System.IO.StreamReader streamReader =
new System.IO.StreamReader("C:\\Samples\\File.csv", System.Text.Encoding.Unicode);
workbook.easy_LoadCSVFile(streamReader);
' Create an instance of the class that imports CSV filesDim workbook As New ExcelDocument
' Import CSV file with specific encodingDim streamReader As System.IO.StreamReader =
New System.IO.StreamReader("C:\\Samples\\File.csv", System.Text.Encoding.Unicode)
workbook.easy_LoadCSVFile(streamReader)
C++// Create an instance of the class that imports CSV files
EasyXLS::IExcelDocumentPtr workbook;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelDocument),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelDocument),
(void**) &workbook);
// Import CSV file with specific encoding
workbook->easy_LoadCSVFile_4("C:\\Samples\\File.csv", "Unicode");
C++.NET// Create an instance of the class that imports CSV files
ExcelDocument ^workbook = gcnew ExcelDocument();
// Import CSV file with specific encoding
System::IO::StreamReader ^streamReader = gcnew System::IO::StreamReader
("C:\\Samples\\File.csv", System::Text::Encoding::Unicode);
workbook->easy_LoadCSVFile(streamReader);
// Create an instance of the class that imports CSV files
ExcelDocument workbook = new ExcelDocument();
// Import CSV file with specific encoding
java.io.InputStream inputStream = new java.io.FileInputStream("C:\\Samples\\File.csv");
java.io.InputStreamReader inputStreamReader = new java.io.InputStreamReader(
inputStream, java.nio.charset.Charset.forName("Unicode"));
workbook.easy_LoadCSVFile(inputStreamReader);
.NET:// Create an instance of the class that imports CSV files
$workbook = new COM("EasyXLS.ExcelDocument");
// Import CSV file with specific encoding
$workbook->easy_LoadCSVFile_4("C:\\Samples\\File.csv", "Unicode");
Java:// Create an instance of the class that imports CSV files
$workbook = new java("EasyXLS.ExcelDocument");
// Import CSV file with specific encoding
$workbook->easy_LoadCSVFile("C:\\Samples\\File.csv", "Unicode");
' Create an instance of the class that imports CSV filesSet workbook = Server.CreateObject("EasyXLS.ExcelDocument")
' Import CSV file with specific encoding
workbook.easy_LoadCSVFile_4 "C:\Samples\File.csv", "Unicode"
' Create an instance of the class that imports CSV filesSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Import CSV file with specific encoding
workbook.easy_LoadCSVFile_4 "C:\\Samples\\File.csv", "Unicode"
' Create an instance of the class that imports CSV filesSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Import CSV file with specific encoding
workbook.easy_LoadCSVFile_4 "C:\Samples\File.csv", "Unicode"
<!-- Create an instance of the class that imports CSV files --><cfobject type="java"class="EasyXLS.ExcelDocument"name="workbook"action="CREATE"><!-- Import CSV file with specific encoding --><cfset success = workbook.easy_LoadCSVFile("C:\Samples\File.csv", "Unicode")>
.NET:# Create an instance of the class that imports CSV files
workbook = ExcelDocument()
# Import CSV file with specific encoding
streamReader = System.IO.StreamReader("C:\\Samples\\File.csv",
System.Text.Encoding.Unicode);
workbook.easy_LoadCSVFile(streamReader);
Java:# Create an instance of the class that imports CSV files
workbook = gateway.jvm.ExcelDocument()
# Import CSV file with specific encoding
workbook.easy_LoadCSVFile("C:\\Samples\\File.csv", "Unicode")
Read CSV file into DataTable in C# and VB.NET
EasyXLS library can be used to import CSV file into DataTable. The DataTable can be the used as data source of a GridView, DataGridView, DataGrid or for any other purposes.
// Create an instance of the class that reads CSV files
ExcelDocument workbook = new ExcelDocument();
// Read CSV file to DataTable
DataSet ds = workbook.easy_ReadCSVFile_AsDataSet("C:\\Samples\\CSV to DataTable.csv");
DataTable dataTable = ds.Tables[0];
// Display imported DataTable valuesfor (int row=0; row < dataTable.Rows.Count; row++)
for (int column=0; column < dataTable.Columns.Count; column++)
Console.WriteLine("At row " + (row + 1) + ", column " + (column + 1) +
" the value is '" + dataTable.Rows[row].ItemArray[column] + "'");
' Create an instance of the class that reads CSV filesDim workbook As New ExcelDocument
' Read CSV file to DataTableDim ds As DataSet = workbook.easy_ReadCSVFile_AsDataSet(
"C:\Samples\CSV to DataTable.csv")
Dim dataTable As DataTable = ds.Tables(0)
' Display imported DataTable valuesFor row As Integer = 0 To dataTable.Rows.Count - 1
For column As Integer = 0 To dataTable.Columns.Count - 1
Console.WriteLine("At row " & (row + 1) & ", column " & (column + 1) &
" the value is '" & dataTable.Rows(row).ItemArray(column) & "'")
NextNext
Read CSV file into GridView in C# and VB.NET from ASP.NET
EasyXLS library can be used to import CSV data into GridView from ASP.NET web applications.
The data from the CSV file can be read using ExcelDocument.easy_ReadCSVFile_AsDataSet method and then the DataTable for the GridView can be obtained from the imported DataSet.
EasyXLS library can be used to import CSV data into DataGridView from windows applications and windows forms.
The data from the CSV file can be read using ExcelDocument.easy_ReadCSVFile_AsDataSet method and then the DataTable for the DataGridView can be obtained from the imported DataSet.
// Create an instance of the class that reads CSV files
ExcelDocument workbook = new ExcelDocument();
// Read CSV file to DataSet
DataSet dataSet =
workbook.easy_ReadCSVFile_AsDataSet("C:\\Samples\\CSV to DataSet.csv");
// Display imported DataSet values
DataTable dt = dataSet.Tables[0];
for (int row=0; row < dt.Rows.Count; row++)
for (int column=0; column < dt.Columns.Count; column++)
Console.WriteLine("At row " + (row + 1) + ", column " + (column + 1) +
" the value is '" + dt.Rows[row].ItemArray[column] + "'");
' Create an instance of the class that reads CSV filesDim workbook As New ExcelDocument
' Read CSV file to DataSetDim dataSet As DataSet = workbook.easy_ReadCSVFile_AsDataSet(
"C:\Samples\CSV to DataSet.csv")
' Display imported DataSet valuesDim dt As DataTable = dataSet.Tables(0)
For row As Integer = 0 To dt.Rows.Count - 1
For column As Integer = 0 To dt.Columns.Count - 1
Console.WriteLine("At row " & (row + 1) & ", column " & (column + 1) &
" the value is '" & dt.Rows(row).ItemArray(column) & "'")
NextNext
// Create an instance of the class that reads CSV files
ExcelDocument workbook = new ExcelDocument();
// Read CSV file to List
EasyXLS.Util.List rows =
workbook.easy_ReadCSVFile_AsList("C:\\Samples\\CSV to List.csv");
// Display imported List values
EasyXLS.Util.List row;
for (int rowIndex=0; rowIndex < rows.size(); rowIndex++)
{
row = (EasyXLS.Util.List)rows.elementAt(rowIndex);
for (int cellIndex=0; cellIndex < row.size(); cellIndex++)
{
Console.WriteLine("At row " + (rowIndex + 1) +
", column " + (cellIndex + 1)
+ " the value is '" + row.elementAt(cellIndex));
}
}
' Create an instance of the class that reads CSV filesDim workbook As New ExcelDocument
' Read CSV file to ListDim rows = workbook.easy_ReadCSVFile_AsList("C:\Samples\CSV to List.csv")
' Display imported List valuesDim row
For rowIndex As Integer = 0 To rows.size() - 1
row = rows.elementAt(rowIndex)
For cellIndex As Integer = 0 To row.size() - 1
Console.WriteLine(vbCrLf & "At row " & (rowIndex + 1) & ", column " _
& (cellIndex + 1) & " the value is '" & row.elementAt(cellIndex))
NextNext
C++// Create an instance of the class that reads CSV files
EasyXLS::IExcelDocumentPtr workbook;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelDocument),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelDocument),
(void**) &workbook);
// Read CSV file to List
EasyXLS::IListPtr rows =
workbook->easy_ReadCSVFile_AsList("C:\\Samples\\CSV to List.csv");
// Display imported List valuesfor (int rowIndex=0; rowIndex<rows->size(); rowIndex++)
{
EasyXLS::IListPtr row = (EasyXLS::IListPtr) rows->elementAt(rowIndex);
for (int cellIndex=0; cellIndex<row->size(); cellIndex++)
{
printf("At row %d, column %d the value is '%s'\n",
(rowIndex+ 1), (cellIndex+ 1),
(LPCSTR)((_bstr_t)row->elementAt(cellIndex)));
}
}
C++.NET// Create an instance of the class that reads CSV files
ExcelDocument ^workbook = gcnew ExcelDocument();
// Read CSV file to List
EasyXLS::Util::List ^rows =
workbook->easy_ReadCSVFile_AsList("C:\\Samples\\CSV to List.csv");
// Display imported List values
EasyXLS::Util::List ^row;
StringBuilder ^str;
for (int rowIndex=0; rowIndex < rows->size(); rowIndex++)
{
row = safe_cast<EasyXLS::Util::List^>(rows->elementAt(rowIndex));
for (int cellIndex=0; cellIndex < row->size(); cellIndex++)
{
str = gcnew StringBuilder();
str->Append(String::Concat("At row ", (rowIndex + 1).ToString(),
", column ", (cellIndex + 1).ToString()));
str->Append(String::Concat(" the value is '",
row->elementAt(cellIndex)->ToString()));
Console::WriteLine(str);
}
}
// Create an instance of the class that reads CSV files
ExcelDocument workbook = new ExcelDocument();
// Read CSV file to List
EasyXLS.Util.List rows =
workbook.easy_ReadCSVFile_AsList("C:\\Samples\\CSV to List.csv");
// Display imported List values
EasyXLS.Util.List row;
for (int rowIndex=0; rowIndex < rows.size(); rowIndex++)
{
row = (EasyXLS.Util.List)rows.elementAt(rowIndex);
for (int cellIndex=0; cellIndex < row.size(); cellIndex++)
{
System.out.println("At row " + (rowIndex + 1) +
", column " + (cellIndex + 1) +
" the value is '" + row.elementAt(cellIndex));
}
}
.NET:// Create an instance of the class that reads CSV files
$workbook = new COM("EasyXLS.ExcelDocument");
// Read CSV file to List
$rows = $workbook->easy_ReadCSVFile_AsList("C:\\Samples\\CSV to List.csv");
// Display imported List valuesfor ($rowIndex=0; $rowIndex<$rows->size(); $rowIndex++)
{
$row = $rows->elementAt($rowIndex);
for ($cellIndex=0; $cellIndex<$row->size(); $cellIndex++)
{
echo"At row ".($rowIndex + 1).", column ".($cellIndex + 1).
" the value is '".$row->elementAt($cellIndex)."'<br>";
}
}
Java:// Create an instance of the class that reads CSV files
$workbook = new java("EasyXLS.ExcelDocument");
// Read CSV file to List
$rows = $workbook->easy_ReadCSVFile_AsList("C:\\Samples\\CSV to List.csv");
// Display imported List valuesfor ($rowIndex=0; $rowIndex<(int)(string)$rows->size(); $rowIndex++)
{
$row = $rows->elementAt($rowIndex);
for ($cellIndex=0; $cellIndex<(int)(string)$row->size(); $cellIndex++)
{
echo"At row ".($rowIndex + 1).", column ".($cellIndex + 1).
" the value is '".$row->elementAt($cellIndex)."'<br>";
}
}
' Create an instance of the class that reads CSV filesset workbook = Server.CreateObject("EasyXLS.ExcelDocument")
' Read CSV file to Listset rows = workbook.easy_ReadCSVFile_AsList("C:\Samples\CSV to List.csv")
' Display imported List valuesfor rowIndex = 0 to rows.size() - 1
set row = rows.elementAt(rowIndex)
for cellIndex = 0 to row.size - 1
response.write("At row " & (rowIndex + 1) & _
", column " & (cellIndex + 1) & _
" the value is '" & row.elementAt(cellIndex) & "'<br>")
nextnext
' Create an instance of the class that reads CSV filesSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Read CSV file to ListSet rows = workbook.easy_ReadCSVFile_AsList("C:\Samples\CSV to List.csv"")
' Display imported List valuesFor rowIndex = 0 To rows.Size() - 1
Set row = rows.elementAt(rowIndex)
For cellIndex = 0 To row.Size - 1
Me.Text1 = Me.Text1 & _
"At row " & (rowIndex + 1) & ", column " & (cellIndex + 1) & _
" the value is '" & row.elementAt(cellIndex) & "'" & vbCrLf
NextNext
' Create an instance of the class that reads CSV filesset workbook = CreateObject("EasyXLS.ExcelDocument")
' Read CSV file to ListSet rows = workbook.easy_ReadCSVFile_AsList("C:\Samples\CSV to List.csv")
' Display imported List valuesFor rowIndex = 0 To rows.Size() - 1
Set row = rows.elementAt(rowIndex)
For cellIndex = 0 To row.Size - 1
WScript.StdOut.WriteLine("At row " & (rowIndex + 1) & _
", column " & (cellIndex + 1) & _
" the value is '" & row.elementAt(cellIndex) & "'")
NextNext
<!-- Create an instance of the class that reads CSV files --><cfobject type="java"class="EasyXLS.ExcelDocument"name="workbook"action="CREATE"><!-- Read CSV file to List --><cfset rows = workbook.easy_ReadCSVFile_AsList("C:\Samples\CSV to List.csv")><!-- Display imported List values --><cfobject type="java"class="EasyXLS.Util.List"name="row"action="CREATE"><cfloop from="0"to="#rows.size()-1#"index="rowIndex"><cfset row = rows.elementAt(rowIndex)><cfloop from="0"to="#row.size()-1#"index="cellIndex"><cfoutput>
At row #evaluate(rowIndex + 1)#, column #evaluate(cellIndex + 1)#
the value is '#row.elementAt(cellIndex)#'<br>
</cfoutput>
</cfloop>
</cfloop>
.NET:# Create an instance of the class that reads CSV files
workbook = ExcelDocument()
# Read CSV file to List
rows = workbook.easy_ReadCSVFile_AsList("C:\\Samples\\CSV to List.csv")
# Display imported List valuesfor rowIndex in range(rows.size()):
row = rows.elementAt(rowIndex)
for cellIndex in range(row.size()):
print("At row " + str(rowIndex + 1) + ", column " + str(cellIndex + 1) +
" the value is '" + str(row.elementAt(cellIndex)) + "'"Java:# Create an instance of the class that reads CSV files
workbook = gateway.jvm.ExcelDocument()
# Read CSV file to List
rows = workbook.easy_ReadCSVFile_AsList("C:\\Samples\\CSV to List.csv")
# Display imported List valuesfor rowIndex in range(rows.size()):
row = rows.elementAt(rowIndex)
for cellIndex in range(row.size()):
print("At row " + str(rowIndex + 1) + ", column " + str(cellIndex + 1) +
" the value is '" + str(row.elementAt(cellIndex)) + "'")
EasyXLS library can be used to import CSV data into DataGrid from windows applications and windows forms.
The data from the CSV file can be read using ExcelDocument.easy_ReadCSVFile_AsDataSet method and then the DataTable for the DataGrid can be obtained from the imported DataSet.