Skip to content

Commit a929ea0

Browse files
Merge pull request #15 from shoaibkhan-aspose/master
Aspose.Cells Java for Xlsx4j
2 parents c4f9723 + b4d93ca commit a929ea0

File tree

50 files changed

+1804
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1804
-1
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/Java SE 7 [1.7.0_75]"/>
5+
<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"/>
6+
<classpathentry kind="lib" path="/Users/shoaibkhan/Downloads/docx4j/docx4j-3.2.1/docx4j-3.2.1.jar"/>
7+
<classpathentry kind="lib" path="/Users/shoaibkhan/Downloads/docx4j/docx4j-3.2.1/dependencies/slf4j-api-1.7.5.jar"/>
8+
<classpathentry kind="lib" path="/Users/shoaibkhan/Downloads/docx4j/docx4j-3.2.1/dependencies/commons-io-1.3.1.jar"/>
9+
<classpathentry kind="lib" path="/Users/shoaibkhan/Downloads/docx4j/docx4j-3.2.1/dependencies/xmlgraphics-commons-1.5.jar"/>
10+
<classpathentry kind="lib" path="/Users/shoaibkhan/Downloads/docx4j/commons-logging-1.1.1/commons-logging-1.1.1.jar"/>
11+
<classpathentry kind="output" path="bin"/>
12+
</classpath>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>Aspose_Cells_Java_for_Xlsx4j</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package asposefeatures.datahandlingfeatures.calculatesubtotals.java;
2+
3+
import com.aspose.cells.CellArea;
4+
import com.aspose.cells.Cells;
5+
import com.aspose.cells.ConsolidationFunction;
6+
import com.aspose.cells.Workbook;
7+
8+
public class AsposeCreateSubTotals
9+
{
10+
public static void main(String[] args) throws Exception
11+
{
12+
String dataPath = "src/asposefeatures/datahandlingfeatures/calculatesubtotals/data/";
13+
14+
// Instantiate a new workbook
15+
Workbook workbook = new Workbook(dataPath + "book1.xls");
16+
17+
// Get the Cells collection in the first worksheet
18+
Cells cells = workbook.getWorksheets().get(0).getCells();
19+
20+
// Create a cellarea i.e.., B3:C19
21+
CellArea ca = new CellArea();
22+
ca.StartRow = 2;
23+
ca.StartColumn = 1;
24+
ca.EndRow = 18;
25+
ca.EndColumn = 2;
26+
27+
// Apply subtotal, the consolidation function is Sum and it will applied
28+
// to
29+
// Second column (C) in the list
30+
cells.subtotal(ca, 0, ConsolidationFunction.SUM, new int[] { 1 });
31+
32+
// Save the excel file
33+
workbook.save(dataPath + "AsposeTotal.xls");
34+
35+
// Print message
36+
System.out.println("Process completed successfully");
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package asposefeatures.datahandlingfeatures.createpivottable.java;
2+
3+
import com.aspose.cells.Cell;
4+
import com.aspose.cells.Cells;
5+
import com.aspose.cells.PivotFieldType;
6+
import com.aspose.cells.PivotTable;
7+
import com.aspose.cells.PivotTableCollection;
8+
import com.aspose.cells.Workbook;
9+
import com.aspose.cells.Worksheet;
10+
11+
public class AsposeCreatePivotTable
12+
{
13+
public static void main(String[] args) throws Exception
14+
{
15+
String dataPath = "src/asposefeatures/datahandlingfeatures/createpivottable/data/";
16+
17+
// Instantiating a Workbook object
18+
Workbook workbook = new Workbook();
19+
20+
// Obtaining the reference of the newly added worksheet
21+
Worksheet sheet = workbook.getWorksheets().get(0);
22+
sheet.setName("PivotTable");
23+
24+
Cells cells = sheet.getCells();
25+
26+
// Setting the value to the cells
27+
Cell cell = cells.get("A1");
28+
cell.setValue("Sport");
29+
cell = cells.get("B1");
30+
cell.setValue("Quarter");
31+
cell = cells.get("C1");
32+
cell.setValue("Sales");
33+
34+
cell = cells.get("A2");
35+
cell.setValue("Golf");
36+
cell = cells.get("A3");
37+
cell.setValue("Golf");
38+
cell = cells.get("A4");
39+
cell.setValue("Tennis");
40+
cell = cells.get("A5");
41+
cell.setValue("Tennis");
42+
cell = cells.get("A6");
43+
cell.setValue("Tennis");
44+
cell = cells.get("A7");
45+
cell.setValue("Tennis");
46+
cell = cells.get("A8");
47+
cell.setValue("Golf");
48+
49+
cell = cells.get("B2");
50+
cell.setValue("Qtr3");
51+
cell = cells.get("B3");
52+
cell.setValue("Qtr4");
53+
cell = cells.get("B4");
54+
cell.setValue("Qtr3");
55+
cell = cells.get("B5");
56+
cell.setValue("Qtr4");
57+
cell = cells.get("B6");
58+
cell.setValue("Qtr3");
59+
cell = cells.get("B7");
60+
cell.setValue("Qtr4");
61+
cell = cells.get("B8");
62+
cell.setValue("Qtr3");
63+
64+
cell = cells.get("C2");
65+
cell.setValue(1500);
66+
cell = cells.get("C3");
67+
cell.setValue(2000);
68+
cell = cells.get("C4");
69+
cell.setValue(600);
70+
cell = cells.get("C5");
71+
cell.setValue(1500);
72+
cell = cells.get("C6");
73+
cell.setValue(4070);
74+
cell = cells.get("C7");
75+
cell.setValue(5000);
76+
cell = cells.get("C8");
77+
cell.setValue(6430);
78+
79+
PivotTableCollection pivotTables = sheet.getPivotTables();
80+
81+
// Adding a PivotTable to the worksheet
82+
int index = pivotTables.add("=A1:C8", "E3", "PivotTable1");
83+
84+
// Accessing the instance of the newly added PivotTable
85+
PivotTable pivotTable = pivotTables.get(index);
86+
87+
// Unshowing grand totals for rows.
88+
pivotTable.setRowGrand(false);
89+
90+
// Dragging the first field to the row area.
91+
pivotTable.addFieldToArea(PivotFieldType.ROW, 0);
92+
93+
// Dragging the second field to the column area.
94+
pivotTable.addFieldToArea(PivotFieldType.COLUMN, 1);
95+
96+
// Dragging the third field to the data area.
97+
pivotTable.addFieldToArea(PivotFieldType.DATA, 2);
98+
99+
// Saving the Excel file
100+
workbook.save(dataPath + "AsposePivotTable.xls");
101+
102+
// Print Message
103+
System.out.println("Pivot Table created successfully.");
104+
}
105+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package asposefeatures.datahandlingfeatures.exportdatafromworksheets.java;
2+
3+
import java.io.FileInputStream;
4+
import java.util.Arrays;
5+
6+
import com.aspose.cells.Workbook;
7+
import com.aspose.cells.Worksheet;
8+
9+
public class ExportDataFromWorksheets
10+
{
11+
public static void main(String[] args) throws Exception
12+
{
13+
String dataPath = "src/asposefeatures/datahandlingfeatures/exportdatafromworksheets/data/";
14+
15+
// Creating a file stream containing the Excel file to be opened
16+
FileInputStream fstream = new FileInputStream(dataPath + "workbook.xls");
17+
18+
// Instantiating a Workbook object
19+
Workbook workbook = new Workbook(fstream);
20+
21+
// Accessing the first worksheet in the Excel file
22+
Worksheet worksheet = workbook.getWorksheets().get(0);
23+
24+
// Exporting the contents of 7 rows and 2 columns starting from 1st cell
25+
// to Array.
26+
Object dataTable[][] = worksheet.getCells().exportArray(4, 0, 7, 8);
27+
28+
for (int i = 0; i < dataTable.length; i++)
29+
{
30+
System.out.println("[" + i + "]: " + Arrays.toString(dataTable[i]));
31+
}
32+
// Closing the file stream to free all resources
33+
fstream.close();
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package asposefeatures.datahandlingfeatures.findvalueincells.java;
2+
3+
import com.aspose.cells.Cell;
4+
import com.aspose.cells.Cells;
5+
import com.aspose.cells.FindOptions;
6+
import com.aspose.cells.LookAtType;
7+
import com.aspose.cells.Workbook;
8+
import com.aspose.cells.Worksheet;
9+
10+
public class AsposeFindCellsWithString
11+
{
12+
public static void main(String[] args) throws Exception
13+
{
14+
String dataPath = "src/asposefeatures/datahandlingfeatures/findvalueincells/data/";
15+
16+
// Instantiating a Workbook object
17+
Workbook workbook = new Workbook(dataPath + "workbook.xls");
18+
19+
// Accessing the first worksheet in the Excel file
20+
Worksheet worksheet = workbook.getWorksheets().get(0);
21+
22+
// Finding the cell containing the specified formula
23+
Cells cells = worksheet.getCells();
24+
25+
// Instantiate FindOptions
26+
FindOptions findOptions = new FindOptions();
27+
28+
// Finding the cell containing a string value that starts with "Or"
29+
findOptions.setLookAtType(LookAtType.START_WITH);
30+
31+
Cell cell = cells.find("SH", null, findOptions);
32+
33+
// Printing the name of the cell found after searching worksheet
34+
System.out.println("Name of the cell containing String: "
35+
+ cell.getName());
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package asposefeatures.datahandlingfeatures.formulacalculationengine.java;
2+
3+
import com.aspose.cells.Cell;
4+
import com.aspose.cells.Cells;
5+
import com.aspose.cells.Workbook;
6+
import com.aspose.cells.Worksheet;
7+
8+
public class AsposeFormulaCalculationEngine
9+
{
10+
public static void main(String[] args) throws Exception
11+
{
12+
String dataPath = "src/asposefeatures/datahandlingfeatures/formulacalculationengine/data/";
13+
14+
// Instantiating a Workbook object
15+
Workbook book = new Workbook();
16+
17+
// Obtaining the reference of the newly added worksheet
18+
int sheetIndex = book.getWorksheets().add();
19+
Worksheet worksheet = book.getWorksheets().get(sheetIndex);
20+
Cells cells = worksheet.getCells();
21+
Cell cell = null;
22+
23+
// Adding a value to "A1" cell
24+
cell = cells.get("A1");
25+
cell.setValue(1);
26+
27+
// Adding a value to "A2" cell
28+
cell = cells.get("A2");
29+
cell.setValue(2);
30+
31+
// Adding a value to "A3" cell
32+
cell = cells.get("A3");
33+
cell.setValue(3);
34+
35+
// Adding a SUM formula to "A4" cell
36+
cell = cells.get("A4");
37+
cell.setFormula("=SUM(A1:A3)");
38+
39+
// Calculating the results of formulas
40+
book.calculateFormula();
41+
42+
// Saving the Excel file
43+
book.save(dataPath + "AsposeFormulaEngine.xls");
44+
System.out.println("Done.");
45+
}
46+
}

0 commit comments

Comments
 (0)