// Create an instance of the class that imports TXT files
ExcelDocument workbook = new ExcelDocument();
// Import TXT file with tab column delimiters
workbook.easy_LoadTXTFile("C:\\Samples\\Excel.txt", "\r\n", "\t");
' Create an instance of the class that imports TXT filesDim workbook As New ExcelDocument
' Import TXT file with tab column delimiters
workbook.easy_LoadTXTFile("C:\Samples\Excel.txt",
Convert.ToChar(13) + Convert.ToChar(10), Convert.ToChar(9))
C++// Create an instance of the class that imports TXT files
EasyXLS::IExcelDocumentPtr workbook;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelDocument),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelDocument),
(void**) &workbook) ;
// Import TXT file with tab column delimiters
workbook->easy_LoadTXTFile("C:\\Samples\\Excel.txt", "\r\n", "\t");
C++.NET// Create an instance of the class that imports TXT files
ExcelDocument ^workbook = gcnew ExcelDocument();
// Import TXT file with tab column delimiters
workbook->easy_LoadTXTFile("C:\\Samples\\Excel.txt", "\r\n", "\t");
// Create an instance of the class that imports TXT files
ExcelDocument workbook = new ExcelDocument();
// Import TXT file with tab column delimiters
workbook.easy_LoadTXTFile("C:\\Samples\\Excel.txt", "\r\n", "\t");
.NET:// Create an instance of the class that imports TXT files
$workbook = new COM("EasyXLS.ExcelDocument");
// Import TXT file with tab column delimiters
$workbook->easy_LoadTXTFile("C:\\Samples\\Excel.txt", "\r\n", "\t");
Java:// Create an instance of the class that imports TXT files
$workbook = new java("EasyXLS.ExcelDocument");
// Import TXT file with tab column delimiters
$workbook->easy_LoadTXTFile("C:\\Samples\\Excel.txt", "\r\n", "\t");
' Create an instance of the class that imports TXT filesSet workbook = Server.CreateObject("EasyXLS.ExcelDocument")
' Import TXT file with tab column delimiters
workbook.easy_LoadTXTFile "C:\Samples\Excel.txt", chr(13) & chr(10), chr(9)
' Create an instance of the class that imports TXT filesSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Import TXT file with tab column delimiters
workbook.easy_LoadTXTFile "C:\Samples\Excel.txt", Chr(13) & Chr(10), Chr(9)
' Create an instance of the class that imports TXT filesset workbook = CreateObject("EasyXLS.ExcelDocument")
' Import TXT file with tab column delimiters
workbook.easy_LoadTXTFile "C:\Samples\Excel.txt", chr(13) & chr(10), chr(9)
<!-- Create an instance of the class that imports TXT files --><cfobject type="java"class="EasyXLS.ExcelDocument"name="workbook"action="CREATE"><!-- Import TXT file with tab column delimiters --><cfset success = workbook.easy_LoadTXTFile("C:\Samples\Excel.txt",
#chr(13)# & #chr(10)#, #chr(9)#)>
.NET:# Create an instance of the class that imports TXT files
workbook = ExcelDocument()
# Import TXT file with tab column delimiters
workbook.easy_LoadTXTFile("C:\\Samples\\Excel.txt", "\r\n", "\t")
Java:# Create an instance of the class that imports TXT files
workbook = gateway.jvm.ExcelDocument()
# Import TXT file with tab column delimiters
workbook.easy_LoadTXTFile("C:\\Samples\\Excel.txt", "\r\n", "\t")
// Create an instance of the class that imports TXT files
ExcelDocument workbook = new ExcelDocument();
// Import TXT file with specific encoding
System.IO.StreamReader streamReader =
new System.IO.StreamReader("C:\\Samples\\Excel.txt", System.Text.Encoding.Unicode);
workbook.easy_LoadTXTFile(streamReader, "\r\n", "\t");
' Create an instance of the class that imports TXT filesDim workbook As New ExcelDocument
' Import TXT file with specific encodingDim streamReader As System.IO.StreamReader =
New System.IO.StreamReader("C:\\Samples\\Excel.txt", System.Text.Encoding.Unicode)
workbook.easy_LoadTXTFile(streamReader,
Convert.ToChar(13) + Convert.ToChar(10), Convert.ToChar(9))
C++// Create an instance of the class that imports TXT files
EasyXLS::IExcelDocumentPtr workbook;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelDocument),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelDocument),
(void**) &workbook) ;
// Import TXT file with specific encoding
workbook->easy_LoadTXTFile("C:\\Samples\\Excel.txt", "Unicode", "\r\n", "\t");
C++.NET// Create an instance of the class that imports TXT files
ExcelDocument ^workbook = gcnew ExcelDocument();
// Import TXT file with specific encoding
System::IO::StreamReader ^streamReader = gcnew System::IO::StreamReader
("C:\\Samples\\Excel.txt", System::Text::Encoding::Unicode);
workbook->easy_LoadTXTFile(streamReader, "\r\n", "\t");
// Create an instance of the class that imports TXT files
ExcelDocument workbook = new ExcelDocument();
// Import TXT file with specific encoding
java.io.InputStream inputStream = new java.io.FileInputStream("C:\\Samples\\Excel.txt");
java.io.InputStreamReader inputStreamReader = new java.io.InputStreamReader(
inputStream, java.nio.charset.Charset.forName("Unicode"));
workbook.easy_LoadTXTFile(inputStreamReader, "\r\n", "\t");
.NET:// Create an instance of the class that imports TXT files
$workbook = new COM("EasyXLS.ExcelDocument");
// Import TXT file with specific encoding
$workbook->easy_LoadTXTFile_4("C:\\Samples\\Excel.txt", "Unicode", "\r\n", "\t");
Java:// Create an instance of the class that imports TXT files
$workbook = new java("EasyXLS.ExcelDocument");
// Import TXT file with specific encoding
$workbook->easy_LoadTXTFile("C:\\Samples\\Excel.txt", "Unicode", "\r\n", "\t");
' Create an instance of the class that imports TXT filesSet workbook = Server.CreateObject("EasyXLS.ExcelDocument")
' Import TXT file with specific encoding
workbook.easy_LoadTXTFile_4 "C:\Samples\Excel.txt", "Unicode", chr(13) & chr(10), chr(9)
' Create an instance of the class that imports TXT filesSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Import TXT file with specific encoding
workbook.easy_LoadTXTFile_4 "C:\Samples\Excel.txt", "Unicode", Chr(13) & Chr(10), Chr(9)
' Create an instance of the class that imports TXT filesset workbook = CreateObject("EasyXLS.ExcelDocument")
' Import TXT file with specific encoding
workbook.easy_LoadTXTFile_4 "C:\Samples\Excel.txt", "Unicode", chr(13) & chr(10), chr(9)
<!-- Create an instance of the class that imports TXT files --><cfobject type="java"class="EasyXLS.ExcelDocument"name="workbook"action="CREATE"><!-- Import TXT file with specific encoding --><cfset success = workbook.easy_LoadTXTFile("C:\Samples\Excel.txt",
"Unicode", #chr(13)# & #chr(10)#, #chr(9)#)>
.NET:# Create an instance of the class that imports TXT files
workbook = ExcelDocument()
# Import TXT file with specific encoding
streamReader = System.IO.StreamReader("C:\\Samples\\Excel.txt",
System.Text.Encoding.Unicode);
workbook.easy_LoadTXTFile(streamReader, "\r\n", "\t");
Java:# Create an instance of the class that imports TXT files
workbook = gateway.jvm.ExcelDocument()
# Import TXT file with specific encoding
workbook.easy_LoadTXTFile("C:\\Samples\\Excel.txt", "Unicode", "\r\n", "\t")
Read text file into DataTable in C# and VB.NET
EasyXLS library can be used to import TXT 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 TXT files
ExcelDocument workbook = new ExcelDocument();
// Read TXT file to DataTable
DataSet ds = workbook.easy_ReadTXTFile_AsDataSet(
"C:\\Samples\\TXT to DataTable.txt", "\r\n", "\t");
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 TXT filesDim workbook As New ExcelDocument
' Read TXT file to DataTableDim ds As DataSet = workbook.easy_ReadTXTFile_AsDataSet(
"C:\Samples\TXT to DataTable.txt",
Convert.ToChar(13) + Convert.ToChar(10), Convert.ToChar(9))
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 text file into GridView in C# and VB.NET from ASP.NET
EasyXLS library can be used to import TXT data into GridView from ASP.NET web applications.
The data from the TXT file can be read using ExcelDocument.easy_ReadTXTFile_AsDataSet method and then the DataTable for the GridView can be obtained from the imported DataSet.
EasyXLS library can be used to import TXT data into DataGridView from windows applications and windows forms.
The data from the TXT file can be read using ExcelDocument.easy_ReadTXTFile_AsDataSet method and then the DataTable for the DataGridView can be obtained from the imported DataSet.
// Create an instance of the class that reads TXT files
ExcelDocument workbook = new ExcelDocument();
// Read TXT file to DataSet
DataSet dataSet = workbook.easy_ReadTXTFile_AsDataSet(
"C:\\Samples\\TXT to DataSet.txt", "\r\n", "\t");
// 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 TXT filesDim workbook As New ExcelDocument
' Read TXT file to DataSetDim dataSet As DataSet = workbook.easy_ReadTXTFile_AsDataSet(
"C:\Samples\TXT to DataSet.txt",
Convert.ToChar(13) + Convert.ToChar(10), Convert.ToChar(9))
' 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 TXT files
ExcelDocument workbook = new ExcelDocument();
// Read TXT file to List
EasyXLS.Util.List rows =
workbook.easy_ReadTXTFile_AsList("C:\\Samples\\TXT to List.txt", "\r\n", "\t");
// 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 TXT filesDim workbook As New ExcelDocument
' Read TXT file to ListDim rows = workbook.easy_ReadTXTFile_AsList("C:\Samples\TXT to List.txt",
Convert.ToChar(13) + Convert.ToChar(10), Convert.ToChar(9))
' 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 TXT files
EasyXLS::IExcelDocumentPtr workbook;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelDocument),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelDocument),
(void**) &workbook);
// Read TXT file to List
EasyXLS::IListPtr rows =
workbook->easy_ReadTXTFile_AsList("C:\\Samples\\TXT to List.txt", "\r\n", "\t");
// 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 TXT files
ExcelDocument ^workbook = gcnew ExcelDocument();
// Read TXT file to List
EasyXLS::Util::List ^rows =
workbook->easy_ReadTXTFile_AsList("C:\\Samples\\TXT to List.txt", "\r\n", "\t");
// 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 TXT files
ExcelDocument workbook = new ExcelDocument();
// Read TXT file to List
EasyXLS.Util.List rows =
workbook.easy_ReadTXTFile_AsList("C:\\Samples\\TXT to List.txt", "\r\n", "\t");
// 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 TXT files
$workbook = new COM("EasyXLS.ExcelDocument");
// Read TXT file to List
$rows = $workbook->easy_ReadTXTFile_AsList("C:\\Samples\\TXT to List.txt", "\r\n", "\t");
// 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 TXT files
$workbook = new java("EasyXLS.ExcelDocument");
// Read TXT file to List
$rows = $workbook->easy_ReadTXTFile_AsList("C:\\Samples\\TXT to List.txt", "\r\n", "\t");
// 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 TXT filesset workbook = Server.CreateObject("EasyXLS.ExcelDocument")
' Read TXT file to Listset rows = workbook.easy_ReadTXTFile_AsList("C:\Samples\TXT to List.txt", _
chr(13) & chr(10), chr(9))
' 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 TXT filesSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Read TXT file to ListSet rows = workbook.easy_ReadTXTFile_AsList("C:\Samples\TXT to List.txt", _
Chr(13) & Chr(10), Chr(9))
' 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 TXT filesset workbook = CreateObject("EasyXLS.ExcelDocument")
' Read TXT file to ListSet rows = workbook.easy_ReadTXTFile_AsList("C:\Samples\TXT to List.txt", _
chr(13) & chr(10), chr(9))
' 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 TXT files --><cfobject type="java"class="EasyXLS.ExcelDocument"name="workbook"action="CREATE"><!-- Read TXT file to List --><cfset rows = workbook.easy_ReadTXTFile_AsList("C:\Samples\TXT to List.txt",
#chr(13)# & #chr(10)#, #chr(9)#)><!-- 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 TXT files
workbook = ExcelDocument()
# Read TXT file to List
rows = workbook.easy_ReadTXTFile_AsList("C:\\Samples\\TXT to List.txt", "\r\n", "\t")
# 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 TXT files
workbook = gateway.jvm.ExcelDocument()
# Read TXT file to List
rows = workbook.easy_ReadTXTFile_AsList("C:\\Samples\\TXT to List.txt", "\r\n", "\t")
# 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 TXT data into DataGrid from windows applications and windows forms.
The data from the TXT file can be read using ExcelDocument.easy_ReadTXTFile_AsDataSet method and then the DataTable for the DataGrid can be obtained from the imported DataSet.