package Tutorial35;
/* ------------------------------------------------------------------
* Tutorial 35
*
* This tutorial shows how to import Excel sheet to DataSet in J#.
* The data is imported from a specific Excel sheet (For this example
* we use the Excel file generated in Tutorial 09).
* ------------------------------------------------------------------ */import System.*;
import System.IO.*;
import System.Data.*;
import EasyXLS.*;
public class Tutorial35
{
public Tutorial35()
{
}
/** @attribute System.STAThread() */public static void main(String[] args)
{
Console.WriteLine("Tutorial 35\n-----------\n");
// Create an instance of the class that imports Excel files
ExcelDocument workbook = new ExcelDocument();
// Import Excel sheet to DataSet
Console.WriteLine("Reading file C:\\Samples\\Tutorial09.xlsx.\n");
DataSet ds = workbook.easy_ReadXLSXSheet_AsDataSet("C:\\Samples\\Tutorial09.xlsx", "First tab");
String sError = workbook.easy_getError();
if (sError.Equals(""))
{
// Display imported DataSet values
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...");
// Dispose memory
workbook.Dispose();
Console.ReadLine();
}
}