User Guide Tutorials J#.NET tutorials Tutorial 34: How to import data from Excel to DataSet in J#.NET |
|
How to import data from Excel to DataSet in J#.NET |
| | |
package Tutorial34;
import System.*;
import System.IO.*;
import System.Data.*;
import EasyXLS.*;
public class Tutorial34
{
public Tutorial34()
{
}
public static void main(String[] args)
{
Console.WriteLine("Tutorial 34\n-----------\n");
ExcelDocument workbook = new ExcelDocument();
Console.WriteLine("Reading file C:\\Samples\\Tutorial09.xlsx.\n");
DataSet ds = workbook.easy_ReadXLSXActiveSheet_AsDataSet("C:\\Samples\\Tutorial09.xlsx");
String sError = workbook.easy_getError();
if (sError.Equals(""))
{
DataTable dt = ds.get_Tables().get_Item(0);
for (int row=0; row<dt.get_Rows().get_Count(); row++)
for (int column=0; column<dt.get_Columns().get_Count(); column++)
Console.WriteLine("At row " + (row + 1) + ", column " + (column + 1) +
" the value is '" + dt.get_Rows().get_Item(row).get_ItemArray()[column] + "'");
}
else
Console.Write("\nError encountered: " + sError );
Console.Write("\nPress Enter to Exit...");
workbook.Dispose();
Console.ReadLine();
}
}
|
|
|
|
|
|