Package com.aspose.cells

Examples of com.aspose.cells.Workbook


public class AsposeNewWorkbook
{
  public static void main(String[] args) throws Exception
  {
    Workbook workbook = new Workbook(); // Creating a Workbook object

    //Workbooks can be saved in many formats
    workbook.save("data/newWorkBook_Aspose.xlsx", FileFormatType.XLSX);

    System.out.println("Worksheets are saved successfully."); // Print Message
  }
View Full Code Here


public class AsposeBorders
{
  public static void main(String[] args) throws Exception
  {
    //Instantiating a Workbook object
    Workbook workbook = new Workbook();

    //Accessing the worksheet in the Excel file
    Worksheet worksheet = workbook.getWorksheets().get(0);
    Cells cells = worksheet.getCells();

    //Accessing the "A1" cell from the worksheet     
    Cell cell = cells.get("B2");

    //Adding some value to the "A1" cell
    cell.setValue("Visit Aspose @ www.aspose.com!");
    Style style = cell.getStyle();

    //Setting the line of the top border
    style.setBorder(BorderType.TOP_BORDER,CellBorderType.THICK,Color.getBlack());

    //Setting the line of the bottom border
    style.setBorder(BorderType.BOTTOM_BORDER,CellBorderType.THICK,Color.getBlack());

    //Setting the line of the left border
    style.setBorder(BorderType.LEFT_BORDER,CellBorderType.THICK,Color.getBlack());

    //Setting the line of the right border
    style.setBorder(BorderType.RIGHT_BORDER,CellBorderType.THICK,Color.getBlack());

    //Saving the modified style to the "A1" cell.
    cell.setStyle(style);

    //Saving the Excel file
    workbook.save("data/AsposeBorders.xls");

    System.out.println("Aspose Borders Created.");
  }
View Full Code Here

public class AsposeNewWorksheet
{
  public static void main(String[] args) throws Exception
  {
        //Instantiating a Workbook object
        Workbook workbook = new Workbook();

    //Adding a new worksheet to the Workbook object
    WorksheetCollection worksheets = workbook.getWorksheets();
    Worksheet worksheet = worksheets.add("My Worksheet");

    //Saving the Excel file
        workbook.save("data/newWorksheet_Aspose.xls");
       
        //Print Message
        System.out.println("Sheet added successfully.");
  }
View Full Code Here

public class AsposePrintArea
{
  public static void main(String[] args) throws Exception
  {
    // Instantiating a Workbook object
    Workbook workbook = new Workbook();

    // Accessing the first worksheet in the Workbook file
    WorksheetCollection worksheets = workbook.getWorksheets();
    Worksheet sheet = worksheets.get(0);

    // Obtaining the reference of the PageSetup of the worksheet
    PageSetup pageSetup = sheet.getPageSetup();

    // Specifying the cells range (from A1 cell to F20 cell) of the print area
    pageSetup.setPrintArea("A1:F20");

    // Workbooks can be saved in many formats
    workbook.save("data/AsposePrintArea.xlsx", FileFormatType.XLSX);

    System.out.println("Print Area Set successfully."); // Print Message
  }
View Full Code Here

public class AsposeWorkingWithFonts
{
  public static void main(String[] args) throws Exception
  {
    //Instantiating a Workbook object
    Workbook workbook = new Workbook();

    //Accessing the worksheet in the Excel file
    Worksheet worksheet = workbook.getWorksheets().get(0);
    Cells cells = worksheet.getCells();

    //Adding some value to cell
    Cell cell = cells.get("A1");
    cell.setValue("This is Aspose test of fonts!");

    //Setting the font name to "Times New Roman"
    Style style = cell.getStyle();
    Font font = style.getFont();
    font.setName("Courier New");
    font.setSize(24);
    font.setBold(true);
    font.setUnderline(FontUnderlineType.SINGLE);
    font.setColor(Color.getBlue());
    font.setStrikeout(true);
    //font.setSubscript(true);

    cell.setStyle(style);

    //Saving the modified Excel file in default format
    workbook.save("data/AsposeFonts.xls");
   
    System.out.println("Aspose Fonts Created.");
  }
View Full Code Here

public class AsposeFreezePanes
{
  public static void main(String[] args) throws Exception
  {
        //Instantiating a Excel object by excel file path
        Workbook workbook = new Workbook();

        //Accessing the first worksheet in the Excel file
        WorksheetCollection worksheets = workbook.getWorksheets();

        Worksheet worksheet1 = worksheets.get(0);
        Worksheet worksheet2 = worksheets.add("Sheet2");      

        //Applying freeze panes settings
        worksheet1.freezePanes(0,2,0,2); // Freezing Columns
        worksheet2.freezePanes(2,0,2,0); // Freezing Rows    

        //Saving the modified Excel file in default format
        workbook.save("data/workbook_Aspose.xls");
       
        //Print Message
        System.out.println("Panes freeze successfull.");
  }
View Full Code Here

public class AsposeWorkingWithColors
{
  public static void main(String[] args) throws Exception
  {
    //Instantiating a Workbook object
    Workbook workbook = new Workbook();

    //Accessing the added worksheet in the Excel file
    Worksheet worksheet = workbook.getWorksheets().get(0);
    Cells cells = worksheet.getCells();

// === Setting Background Pattern ===

//Accessing cell from the worksheet
Cell cell = cells.get("B2");
Style style = cell.getStyle();

//Setting the foreground color to yellow
style.setBackgroundColor(Color.getYellow());

//Setting the background pattern to vertical stripe
style.setPattern(BackgroundType.VERTICAL_STRIPE);

//Saving the modified style to the "A1" cell.
cell.setStyle(style);

// === Setting Foreground ===

//Adding custom color to the palette at 55th index
Color color = Color.fromArgb(212,213,0);
workbook.changePalette(color,55);

//Accessing the "A2" cell from the worksheet
cell = cells.get("B3");

//Adding some value to the cell
cell.setValue("Hello Aspose!");

//Setting the custom color to the font
style = cell.getStyle();
Font font = style.getFont();
font.setColor(color);

cell.setStyle(style);
   
    //Saving the Excel file
    workbook.save("data/AsposeColors.xls");
   
    System.out.println("Aspose Colors Created.");

  }
View Full Code Here

public class AsposeHideUnHideCells
{
  public static void main(String[] args) throws Exception
  {
    Workbook workbook = new Workbook("data/workbook.xls");
   
    //Accessing the first worksheet in the Excel file
    Worksheet worksheet = workbook.getWorksheets().get(0);
    Cells cells = worksheet.getCells();
   
    cells.hideRow(2); //Hiding the 3rd row of the worksheet
    cells.hideColumn(1); //Hiding the 2nd column of the worksheet
   
    //Saving the modified Excel file in default (that is Excel 2003) format
    workbook.save("data/hideUnhideCells_Aspose.xls");

        //Print message
        System.out.println("Rows and Columns hidden successfully.");          

  }
View Full Code Here

public class AsposeCreatePivotTable
{
  public static void main(String[] args) throws Exception
  {
    //Instantiating a Workbook object
    Workbook workbook = new Workbook();

    //Obtaining the reference of the newly added worksheet
    Worksheet sheet = workbook.getWorksheets().get(0);
    sheet.setName("PivotTable");
   
    Cells cells = sheet.getCells();

    //Setting the value to the cells
    Cell cell = cells.get("A1");
    cell.setValue("Sport");
    cell = cells.get("B1");
    cell.setValue("Quarter");
    cell = cells.get("C1");
    cell.setValue("Sales");

    cell = cells.get("A2");
    cell.setValue("Golf");
    cell = cells.get("A3");
    cell.setValue("Golf");
    cell = cells.get("A4");
    cell.setValue("Tennis");
    cell = cells.get("A5");
    cell.setValue("Tennis");
    cell = cells.get("A6");
    cell.setValue("Tennis");
    cell = cells.get("A7");
    cell.setValue("Tennis");
    cell = cells.get("A8");
    cell.setValue("Golf");

    cell = cells.get("B2");
    cell.setValue("Qtr3");
    cell = cells.get("B3");
    cell.setValue("Qtr4");
    cell = cells.get("B4");
    cell.setValue("Qtr3");
    cell = cells.get("B5");
    cell.setValue("Qtr4");
    cell = cells.get("B6");
    cell.setValue("Qtr3");
    cell = cells.get("B7");
    cell.setValue("Qtr4");
    cell = cells.get("B8");
    cell.setValue("Qtr3");

    cell = cells.get("C2");
    cell.setValue(1500);
    cell = cells.get("C3");
    cell.setValue(2000);
    cell = cells.get("C4");
    cell.setValue(600);
    cell = cells.get("C5");
    cell.setValue(1500);
    cell = cells.get("C6");
    cell.setValue(4070);
    cell = cells.get("C7");
    cell.setValue(5000);
    cell = cells.get("C8");
    cell.setValue(6430);

    PivotTableCollection pivotTables = sheet.getPivotTables();

    //Adding a PivotTable to the worksheet
    int index = pivotTables.add("=A1:C8","E3","PivotTable1");

    //Accessing the instance of the newly added PivotTable
    PivotTable pivotTable = pivotTables.get(index);

    //Unshowing grand totals for rows.
    pivotTable.setRowGrand(false);

    //Dragging the first field to the row area.
    pivotTable.addFieldToArea(PivotFieldType.ROW,0);

    //Dragging the second field to the column area.
    pivotTable.addFieldToArea(PivotFieldType.COLUMN,1);

    //Dragging the third field to the data area.
    pivotTable.addFieldToArea(PivotFieldType.DATA,2);

    //Saving the Excel file
    workbook.save("data/AsposePivotTable.xls");
   
    // Print Message
    System.out.println("Pivot Table created successfully.");
  }
View Full Code Here

public class AsposeHeaderFooter
{
  public static void main(String[] args) throws Exception
  {
    //Instantiating a Workbook object
    Workbook workbook = new Workbook();

    //Obtaining the reference of the PageSetup of the worksheet
    PageSetup pageSetup = workbook.getWorksheets().get(0).getPageSetup();

    //Setting worksheet name at the left  header
    pageSetup.setHeader(0, "&A");

    //Setting current date and current time at the central header
    //and changing the font of the header
    pageSetup.setHeader(1, "&\"Times New Roman,Bold\"&D-&T");

    //Setting current file name at the right header and changing the font of the header
    pageSetup.setHeader(2, "&\"Times New Roman,Bold\"&12&F");

    //Setting a string at the left footer and changing the font of the footer
    pageSetup.setFooter(0, "Hello World! &\"Courier New\"&14 123");

    //Setting picture at the central footer
    pageSetup.setFooter(1, "&G");

    FileInputStream fis = new FileInputStream("data/footer.png");
    byte[] picData = new byte[fis.available()];
    fis.read(picData);
    pageSetup.setFooterPicture(1, picData);
    fis.close();

    //Setting the current page number and page count at the right footer
    pageSetup.setFooter(2, "&Pof&N");
   
    //Saving the workbook
    workbook.save("data/AsposeHeaderFooter.xls");

    System.out.println("Aspose Header Footer Created.");
  }
View Full Code Here

TOP

Related Classes of com.aspose.cells.Workbook

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.