Back    Next
// (C) On Time Computing Solutions, 2009. All Rights Reserved.

package testexceljava;

/*----------------------------------------------------------------------
 | Tutorial 34                                                                  |
 |                                                                                        |
 | This tutorial shows how to load a XLSB file (we use the file    |
 | generated in tutorial 25), modify some data and                   |
 | save it to another file (Tutorial34.xlsb).                                |
 --------------------------------------------------------------------------*/
Click here to see the Excel file.

import java.io.FileInputStream;
import ActiveXLS.*;

public class Tutorial34 {

  public static void main(String[] args) {
    try {
      System.out.println("Tutorial 34");
      System.out.println("----------");

      //Create an instance of the object that generates Excel files
      ExcelDocument xls = new ExcelDocument();

      //Read the file
      System.out.println("Reading file C:\\Samples\\Tutorial25.xlsb.");
      FileInputStream file = new FileInputStream("C:\\Samples\\Tutorial25.xlsb");
      if (xls.esd_LoadXLSBFile(file))
      {
	//Get the table of the second worksheet
        ExcelTable xlsSecondTable = ((ExcelWorksheet)xls.esd_getSheetAt(1)).esd_getExcelTable();
	//Write some data
        xlsSecondTable .esd_getCell("A1").setValue("Data added by Tutorial34");

        for (int column=0; column<5; column++)
        {
          xlsSecondTable .esd_getCell(1, column).setValue("Data " + (column + 1));
        }

        //Generate the file
        System.out.println("Writing file C:\\Samples\\Tutorial34.xlsb.");
        xls.esd_WriteXLSBFile("C:\\Samples\\Tutorial34.xlsb");

        //Confirm generation
        if (xls.esd_getError().equals(""))
          System.out.println("File successfully created.");
        else
          System.out.println("Error encountered: " + xls.esd_getError());

      }
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }
}

Back    Next