Skip to content

Commit

Permalink
Merge pull request #15 from shoaibkhan-aspose/master
Browse files Browse the repository at this point in the history
Aspose.Cells Java for Xlsx4j
  • Loading branch information
aspose-cells-gists committed Aug 20, 2015
2 parents c4f9723 + b4d93ca commit a929ea0
Show file tree
Hide file tree
Showing 50 changed files with 1,804 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Plugins/Aspose_Cells_Java_for_Xlsx4j/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/Java SE 7 [1.7.0_75]"/>
<classpathentry kind="lib" path="/Users/shoaibkhan/Downloads/Aspose/AsposeComponents/aspose-cells-8.5.1-java/JDK 1.6/aspose-cells-8.5.1-java/lib/aspose-cells-8.5.1.jar"/>
<classpathentry kind="lib" path="/Users/shoaibkhan/Downloads/docx4j/docx4j-3.2.1/docx4j-3.2.1.jar"/>
<classpathentry kind="lib" path="/Users/shoaibkhan/Downloads/docx4j/docx4j-3.2.1/dependencies/slf4j-api-1.7.5.jar"/>
<classpathentry kind="lib" path="/Users/shoaibkhan/Downloads/docx4j/docx4j-3.2.1/dependencies/commons-io-1.3.1.jar"/>
<classpathentry kind="lib" path="/Users/shoaibkhan/Downloads/docx4j/docx4j-3.2.1/dependencies/xmlgraphics-commons-1.5.jar"/>
<classpathentry kind="lib" path="/Users/shoaibkhan/Downloads/docx4j/commons-logging-1.1.1/commons-logging-1.1.1.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions Plugins/Aspose_Cells_Java_for_Xlsx4j/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Aspose_Cells_Java_for_Xlsx4j</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package asposefeatures.datahandlingfeatures.calculatesubtotals.java;

import com.aspose.cells.CellArea;
import com.aspose.cells.Cells;
import com.aspose.cells.ConsolidationFunction;
import com.aspose.cells.Workbook;

public class AsposeCreateSubTotals
{
public static void main(String[] args) throws Exception
{
String dataPath = "src/asposefeatures/datahandlingfeatures/calculatesubtotals/data/";

// Instantiate a new workbook
Workbook workbook = new Workbook(dataPath + "book1.xls");

// Get the Cells collection in the first worksheet
Cells cells = workbook.getWorksheets().get(0).getCells();

// Create a cellarea i.e.., B3:C19
CellArea ca = new CellArea();
ca.StartRow = 2;
ca.StartColumn = 1;
ca.EndRow = 18;
ca.EndColumn = 2;

// Apply subtotal, the consolidation function is Sum and it will applied
// to
// Second column (C) in the list
cells.subtotal(ca, 0, ConsolidationFunction.SUM, new int[] { 1 });

// Save the excel file
workbook.save(dataPath + "AsposeTotal.xls");

// Print message
System.out.println("Process completed successfully");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package asposefeatures.datahandlingfeatures.createpivottable.java;

import com.aspose.cells.Cell;
import com.aspose.cells.Cells;
import com.aspose.cells.PivotFieldType;
import com.aspose.cells.PivotTable;
import com.aspose.cells.PivotTableCollection;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;

public class AsposeCreatePivotTable
{
public static void main(String[] args) throws Exception
{
String dataPath = "src/asposefeatures/datahandlingfeatures/createpivottable/data/";

// 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(dataPath + "AsposePivotTable.xls");

// Print Message
System.out.println("Pivot Table created successfully.");
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package asposefeatures.datahandlingfeatures.exportdatafromworksheets.java;

import java.io.FileInputStream;
import java.util.Arrays;

import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;

public class ExportDataFromWorksheets
{
public static void main(String[] args) throws Exception
{
String dataPath = "src/asposefeatures/datahandlingfeatures/exportdatafromworksheets/data/";

// Creating a file stream containing the Excel file to be opened
FileInputStream fstream = new FileInputStream(dataPath + "workbook.xls");

// Instantiating a Workbook object
Workbook workbook = new Workbook(fstream);

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

// Exporting the contents of 7 rows and 2 columns starting from 1st cell
// to Array.
Object dataTable[][] = worksheet.getCells().exportArray(4, 0, 7, 8);

for (int i = 0; i < dataTable.length; i++)
{
System.out.println("[" + i + "]: " + Arrays.toString(dataTable[i]));
}
// Closing the file stream to free all resources
fstream.close();
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package asposefeatures.datahandlingfeatures.findvalueincells.java;

import com.aspose.cells.Cell;
import com.aspose.cells.Cells;
import com.aspose.cells.FindOptions;
import com.aspose.cells.LookAtType;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;

public class AsposeFindCellsWithString
{
public static void main(String[] args) throws Exception
{
String dataPath = "src/asposefeatures/datahandlingfeatures/findvalueincells/data/";

// Instantiating a Workbook object
Workbook workbook = new Workbook(dataPath + "workbook.xls");

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

// Finding the cell containing the specified formula
Cells cells = worksheet.getCells();

// Instantiate FindOptions
FindOptions findOptions = new FindOptions();

// Finding the cell containing a string value that starts with "Or"
findOptions.setLookAtType(LookAtType.START_WITH);

Cell cell = cells.find("SH", null, findOptions);

// Printing the name of the cell found after searching worksheet
System.out.println("Name of the cell containing String: "
+ cell.getName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package asposefeatures.datahandlingfeatures.formulacalculationengine.java;

import com.aspose.cells.Cell;
import com.aspose.cells.Cells;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;

public class AsposeFormulaCalculationEngine
{
public static void main(String[] args) throws Exception
{
String dataPath = "src/asposefeatures/datahandlingfeatures/formulacalculationengine/data/";

// Instantiating a Workbook object
Workbook book = new Workbook();

// Obtaining the reference of the newly added worksheet
int sheetIndex = book.getWorksheets().add();
Worksheet worksheet = book.getWorksheets().get(sheetIndex);
Cells cells = worksheet.getCells();
Cell cell = null;

// Adding a value to "A1" cell
cell = cells.get("A1");
cell.setValue(1);

// Adding a value to "A2" cell
cell = cells.get("A2");
cell.setValue(2);

// Adding a value to "A3" cell
cell = cells.get("A3");
cell.setValue(3);

// Adding a SUM formula to "A4" cell
cell = cells.get("A4");
cell.setFormula("=SUM(A1:A3)");

// Calculating the results of formulas
book.calculateFormula();

// Saving the Excel file
book.save(dataPath + "AsposeFormulaEngine.xls");
System.out.println("Done.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package asposefeatures.datahandlingfeatures.importdatatoworksheets.java;

import java.util.ArrayList;

import com.aspose.cells.Cells;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;

public class ImportDataToWorksheets
{
public static void main(String[] args) throws Exception
{
String dataPath = "src/asposefeatures/datahandlingfeatures/importdatatoworksheets/data/";

// Instantiating a Workbook object
Workbook workbook = new Workbook();

// Obtaining the reference of the newly added worksheet by passing its
// sheet index
int sheetIndex = workbook.getWorksheets().add();
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex);

// ==================================================
// Creating an array containing names as string values
String[] names = new String[] { "laurence chen", "roman korchagin",
"kyle huang" };

// Importing the array of names to 1st row and first column vertically
Cells cells = worksheet.getCells();
cells.importArray(names, 0, 0, false);

// ==================================================
ArrayList<String> list = new ArrayList<String>();

// Add few names to the list as string values
list.add("laurence chen");
list.add("roman korchagin");
list.add("kyle huang");

// Importing the contents of ArrayList to 1st row and first column
// vertically
cells.importArrayList(list, 2, 0, true);
// ==================================================

// Saving the Excel file
workbook.save(dataPath + "AsposeDataImport.xls");
System.out.println("Done.");
}
}
Binary file not shown.
Loading

0 comments on commit a929ea0

Please sign in to comment.