Skip to content

Commit 0bc6c29

Browse files
Merge pull request #24 from shoaibkhan-aspose/master
Aspose.Cells vs Apache POI SS (HSSF + XSSF) - v1.5
2 parents 797e4dc + 255d4c7 commit 0bc6c29

File tree

223 files changed

+4851
-0
lines changed

Some content is hidden

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

223 files changed

+4851
-0
lines changed

Plugins/Aspose_Cells_for_Apache_POI/Aspose-Cells-for-Apache-POI/Examples.xml

Lines changed: 785 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Aspose
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package asposefeatures.datahandlingfeatures.sortdata.java;
2+
3+
import com.aspose.cells.CellArea;
4+
import com.aspose.cells.Cells;
5+
import com.aspose.cells.DataSorter;
6+
import com.aspose.cells.SortOrder;
7+
import com.aspose.cells.Workbook;
8+
import com.aspose.cells.Worksheet;
9+
10+
public class AsposeDataSort
11+
{
12+
public static void main(String[] args) throws Exception
13+
{
14+
String dataPath = "src/asposefeatures/datahandlingfeatures/sortdata/data/";
15+
16+
// Instantiating a Workbook object
17+
Workbook workbook = new Workbook(dataPath + "AsposeDataInput.xls");
18+
19+
// Accessing the first worksheet in the Excel file
20+
Worksheet worksheet = workbook.getWorksheets().get(0);
21+
22+
// Get the cells collection in the sheet
23+
Cells cells = worksheet.getCells();
24+
25+
// Obtain the DataSorter object in the workbook
26+
DataSorter sorter = workbook.getDataSorter();
27+
28+
// Set the first order
29+
sorter.setOrder1(SortOrder.ASCENDING);
30+
31+
// Define the first key.
32+
sorter.setKey1(0);
33+
34+
// Set the second order
35+
sorter.setOrder2(SortOrder.ASCENDING);
36+
37+
// Define the second key
38+
sorter.setKey2(1);
39+
40+
// Create a cells area (range).
41+
CellArea ca = new CellArea();
42+
43+
// Specify the start row index.
44+
ca.StartRow = 1;
45+
// Specify the start column index.
46+
ca.StartColumn = 0;
47+
// Specify the last row index.
48+
ca.EndRow = 9;
49+
// Specify the last column index.
50+
ca.EndColumn = 2;
51+
52+
// Sort data in the specified data range (A2:C10)
53+
sorter.sort(cells, ca);
54+
55+
// Saving the excel file
56+
workbook.save(dataPath + "AsposeSortedData.xls");
57+
System.out.println("Done.");
58+
}
59+
}

0 commit comments

Comments
 (0)