Skip to content

Commit f3cfae0

Browse files
Merge pull request #6 from shoaibkhan-aspose/master
Aspose Features missing in Apache POI HSSF and XSSF v1.4
2 parents 6287cee + b062dbe commit f3cfae0

File tree

58 files changed

+1646
-4
lines changed

Some content is hidden

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

58 files changed

+1646
-4
lines changed
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
33
<classpathentry kind="src" path="src"/>
4-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
5-
<classpathentry kind="lib" path="D:/Banckle/workspaces/ApachePOI_GitHub/lib/Aspose/aspose-cells-8.3.0.jar"/>
6-
<classpathentry kind="lib" path="D:/Banckle/workspaces/ApachePOI_GitHub/lib/ApachePOI/poi-3.11-beta1-20140306.jar"/>
7-
<classpathentry kind="lib" path="D:/Banckle/workspaces/ApachePOI_GitHub/lib/ApachePOI/poi-ooxml-3.11-beta1-20140306.jar"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
5+
<classpathentry kind="lib" path="/Users/shoaibkhan/Downloads/Aspose/AsposeComponents/aspose-cells-8.3.2-java/JDK 1.6/aspose-cells-8.3.2-java/lib/aspose-cells-8.3.2.jar"/>
6+
<classpathentry kind="lib" path="/Users/shoaibkhan/Downloads/ApachePOI/poi-3.11/poi-3.11-20141221.jar"/>
7+
<classpathentry kind="lib" path="/Users/shoaibkhan/Downloads/ApachePOI/poi-3.11/poi-ooxml-3.11-20141221.jar"/>
8+
<classpathentry kind="lib" path="/Users/shoaibkhan/Downloads/ApachePOI/poi-3.11/poi-ooxml-schemas-3.11-20141221.jar"/>
9+
<classpathentry kind="lib" path="/Users/shoaibkhan/Downloads/ApachePOI/poi-3.11/ooxml-lib/xmlbeans-2.6.0.jar"/>
810
<classpathentry kind="output" path="bin"/>
911
</classpath>
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,36 @@
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: " + cell.getName());
35+
}
36+
}
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package asposefeatures.datahandlingfeatures.importdatatoworksheets.java;
2+
3+
import java.util.ArrayList;
4+
5+
import com.aspose.cells.Cells;
6+
import com.aspose.cells.Workbook;
7+
import com.aspose.cells.Worksheet;
8+
9+
public class ImportDataToWorksheets
10+
{
11+
public static void main(String[] args) throws Exception
12+
{
13+
String dataPath = "src/asposefeatures/datahandlingfeatures/importdatatoworksheets/data/";
14+
15+
// Instantiating a Workbook object
16+
Workbook workbook = new Workbook();
17+
18+
// Obtaining the reference of the newly added worksheet by passing its
19+
// sheet index
20+
int sheetIndex = workbook.getWorksheets().add();
21+
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex);
22+
23+
// ==================================================
24+
// Creating an array containing names as string values
25+
String[] names = new String[] { "laurence chen", "roman korchagin", "kyle huang" };
26+
27+
// Importing the array of names to 1st row and first column vertically
28+
Cells cells = worksheet.getCells();
29+
cells.importArray(names, 0, 0, false);
30+
31+
// ==================================================
32+
ArrayList<String> list = new ArrayList<String>();
33+
34+
// Add few names to the list as string values
35+
list.add("laurence chen");
36+
list.add("roman korchagin");
37+
list.add("kyle huang");
38+
39+
// Importing the contents of ArrayList to 1st row and first column
40+
// vertically
41+
cells.importArrayList(list, 2, 0, true);
42+
// ==================================================
43+
44+
// Saving the Excel file
45+
workbook.save(dataPath + "AsposeDataImport.xls");
46+
System.out.println("Done.");
47+
}
48+
}

0 commit comments

Comments
 (0)