package Tutorial37;
/* ---------------------------------------------------------------------------
* Tutorial 37
*
* This tutorial shows how to read an Excel XLS file in J# (the
* XLS file generated by Tutorial 28 as base template), modify
* some data and save it to another XLS file (Tutorial37 - read XLS file.xls).
* ------------------------------------------------------------------------ */import System.*;
import System.IO.*;
import System.Data.*;
import EasyXLS.*;
public class Tutorial37
{
public Tutorial37()
{
}
/** @attribute System.STAThread() */public static void main(String[] args)
{
Console.WriteLine("Tutorial 37\n-----------\n");
// Create an instance of the class that reads Excel files
ExcelDocument workbook = new ExcelDocument();
// Read XLS file
Console.WriteLine("Reading file C:\\Samples\\Tutorial28.xls");
if (workbook.easy_LoadXLSFile("C:\\Samples\\Tutorial28.xls"))
{
// Get the table of data for the second worksheet
ExcelTable xlsSecondTable =
((ExcelWorksheet)workbook.easy_getSheet("Second tab")).easy_getExcelTable();
// Write some data to the second sheet
xlsSecondTable.easy_getCell("A1").setValue("Data added by Tutorial37");
for (int column=0; column<5; column++)
{
xlsSecondTable.easy_getCell(1, column).setValue("Data " + (column + 1));
}
// Export the new XLS file
Console.WriteLine("\nWriting file C:\\Samples\\Tutorial37 - read XLS file.xls.");
workbook.easy_WriteXLSFile("C:\\Samples\\Tutorial37 - read XLS file.xls");
// Confirm export of Excel file
String sError = workbook.easy_getError();
if (sError.Equals(""))
Console.Write("\nFile successfully created.");
else
Console.Write("\nError encountered: " + sError);
}
else
{
Console.WriteLine("\nError reading file C:\\Samples\\Tutorial28.xls \n" +
workbook.easy_getError());
}
Console.WriteLine("\nPress Enter to exit ...");
// Dispose memory
workbook.Dispose();
Console.ReadLine();
}
}