Skip to content

Commit bdeed20

Browse files
committed
Restructure Aspose.Cells Java for Xlsx4j
1 parent 1b62ad3 commit bdeed20

File tree

52 files changed

+1874
-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.

52 files changed

+1874
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2001-2015 Aspose Pty Ltd
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.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
## Aspose.Cells Java for Xlsx4j
2+
3+
Aspose.Cells Java for Xlsx4j is a project to provide comparative source code examples to do the same file processing tasks using Aspose.Cells for Java API and Xlsx4j. Additionally, this project provides source code examples for advanced features offered by Aspose.Cells for Java which are missing in Xlsx4j.
4+
5+
Below are some code comparisons and features of Aspose.Cells for Java that are not available in Xlsx4j.
6+
7+
* [Code Comparison for common features in **Aspose.Cells** and **Xlsx4j**](http://www.aspose.com/docs/display/cellsjava/2.2+Code+Comparison+for+Common+Features+in+Aspose.Cells+and+xlsx4j)
8+
* [Missing Features of **Xlsx4j** available in **Aspose.Cells**](http://www.aspose.com/docs/display/cellsjava/2.3+Missing+Features+of+xlsx4j+in+Aspose.Cells)
9+
10+
These examples are helpful for developers who want to compare Xlsx4j with Aspose.Cells OR migrate from Xlsx4j to Aspose.
11+
12+
### Feedback and Suggestions
13+
14+
* Many more examples are yet to come. [Keep visiting us](http://www.aspose.com/java/total-component.aspx).
15+
* Raise your queries and suggest more examples via [Aspose Forums](http://www.aspose.com/community/forums/default.aspx) or via this social coding site.
16+
17+
## Why Aspose for Xlsx4j ?
18+
19+
The developers looking for file format libraries may need to walk through the features provided by the libraries available on the market. Mainly, two factors are considered when choosing an option:
20+
21+
* Features
22+
* Efforts required to use the library
23+
24+
If you are a Java developer looking to choose a file format library to process files, you may want to compare Xlsx4j library with Aspose. In this case, this project will help you to compare features and code in both libraries. Please visit project documentation for a comprehensive comparison.
25+
26+
## What is Doc4j ?
27+
28+
docx4j is an open source (ASLv2) Java library for creating and manipulating Microsoft Open XML (Word docx, Powerpoint pptx, and Excel xlsx) files.
29+
30+
It is similar to Microsoft's OpenXML SDK, but for Java. docx4j uses JAXB to create the in-memory object representation.
31+
32+
Its emphasis is on power: if the file format supports it, you can do it with docx4j. But first, you'll need to take the time to understand JAXB, and the Open XML file structure
33+
34+
docx4j was created by Plutext Pty Ltd in 2008 - using OpenXML4J for the OPC piece. Plutext still drives the project, but since then docx4j has benefited from contributions from many individuals. The contributors are listed in docx4j's pom.xml.
35+
36+
Read More at [docx4java.org](http://www.docx4java.org/)
37+
38+
## What is the use of Aspose Java Products?
39+
40+
Aspose are file format experts and provide APIs and components for various file formats including MS Office, OpenOffice, PDF and Image formats.
41+
42+
These APIs are available on a number of development platforms including Java. If you are a Java developer, you can use Aspose native Java APIs in your Java applications to process various file formats in just a few lines of codes.
43+
44+
All the Aspose APIs don’t have any dependency over any other engine. For example, you don’t need to have MS Office installed on the server to process MS Office files. Below you can read mor about Aspose.Cells for Java:
45+
46+
### Aspose.Cells for Java
47+
48+
[![Aspose.Cells for Java](http://www.aspose.com/App_Themes/V2/images/productLogos/JAVA/aspose_cells-for-java.jpg)](http://www.aspose.com/java/excel-component.aspx)
49+
50+
Aspose.Cells for Java is an Excel® spreadsheet reporting component that enables Java applications to create and manage Excel® spreadsheets without using Microsoft Excel®.
51+
52+
Aspose.Cells for Java is an incredibly feature rich component that offers much more than just basic data export functions.
53+
54+
[Learn More](http://www.aspose.com/java/excel-component.aspx)
55+
56+
## Download Latest Versions?
57+
58+
* [Latest Releases on Codeplex](https://asposecellsjavaxlsx4j.codeplex.com/releases/view/618923)
59+
60+
## Clone Plugin SourceCodes?
61+
62+
This project is also hosted and maintained at CodePlex. To clone navigate to:
63+
64+
* [Aspose.Cells Java for Xlsx4j on CodePlex - click here](https://asposecellsjavaxlsx4j.codeplex.com/SourceControl/latest)
65+
66+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.aspose</groupId>
5+
<artifactId>AsposeCellsJavaForXlsx4j</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
<packaging>jar</packaging>
8+
<properties>
9+
<maven.compiler.source>1.7</maven.compiler.source>
10+
<maven.compiler.target>1.7</maven.compiler.target>
11+
</properties>
12+
<dependencies>
13+
<dependency>
14+
<groupId>com.aspose</groupId>
15+
<artifactId>aspose-cells</artifactId>
16+
<version>8.6.0</version>
17+
</dependency>
18+
<dependency>
19+
<groupId>org.docx4j</groupId>
20+
<artifactId>docx4j</artifactId>
21+
<version>3.2.2</version>
22+
</dependency>
23+
</dependencies>
24+
<repositories>
25+
<repository>
26+
<id>aspose-maven-repository</id>
27+
<url>http://maven.aspose.com/repository/repo/</url>
28+
</repository>
29+
</repositories>
30+
</project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.aspose.cells.examples;
2+
3+
import java.io.File;
4+
5+
public class Utils {
6+
7+
public static String getDataDir(Class c) {
8+
File dir = new File(System.getProperty("user.dir"));
9+
dir = new File(dir, "src");
10+
dir = new File(dir, "main");
11+
dir = new File(dir, "resources");
12+
13+
for (String s : c.getName().split("\\.")) {
14+
dir = new File(dir, s);
15+
if (dir.isDirectory() == false)
16+
dir.mkdir();
17+
}
18+
19+
System.out.println("Using data directory: " + dir.toString());
20+
return dir.toString() + File.separator;
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package com.aspose.cells.examples.asposefeatures.charts.convertcharttoimage;
2+
3+
import java.io.FileOutputStream;
4+
5+
import com.aspose.cells.Cells;
6+
import com.aspose.cells.Chart;
7+
import com.aspose.cells.ChartPoint;
8+
import com.aspose.cells.ChartPointCollection;
9+
import com.aspose.cells.ChartType;
10+
import com.aspose.cells.Color;
11+
import com.aspose.cells.ImageFormat;
12+
import com.aspose.cells.ImageOrPrintOptions;
13+
import com.aspose.cells.Workbook;
14+
import com.aspose.cells.Worksheet;
15+
import com.aspose.cells.examples.Utils;
16+
17+
public class AsposeChartToImage
18+
{
19+
public static void main(String[] args) throws Exception
20+
{
21+
// The path to the documents directory.
22+
String dataDir = Utils.getDataDir(AsposeChartToImage.class);
23+
24+
//Create a new Workbook.
25+
Workbook workbook = new Workbook();
26+
27+
//Get the first worksheet.
28+
Worksheet sheet = workbook.getWorksheets().get(0);
29+
30+
//Set the name of worksheet
31+
sheet.setName("Data");
32+
33+
//Get the cells collection in the sheet.
34+
Cells cells = workbook.getWorksheets().get(0).getCells();
35+
36+
//Put some values into a cells of the Data sheet.
37+
cells.get("A1").setValue("Region");
38+
cells.get("A2").setValue("France");
39+
cells.get("A3").setValue("Germany");
40+
cells.get("A4").setValue("England");
41+
cells.get("A5").setValue("Sweden");
42+
cells.get("A6").setValue("Italy");
43+
cells.get("A7").setValue("Spain");
44+
cells.get("A8").setValue("Portugal");
45+
cells.get("B1").setValue("Sale");
46+
cells.get("B2").setValue(70000);
47+
cells.get("B3").setValue(55000);
48+
cells.get("B4").setValue(30000);
49+
cells.get("B5").setValue(40000);
50+
cells.get("B6").setValue(35000);
51+
cells.get("B7").setValue(32000);
52+
cells.get("B8").setValue(10000);
53+
54+
//Create chart
55+
int chartIndex = sheet.getCharts().add(ChartType.COLUMN, 12, 1, 33, 12);
56+
Chart chart = sheet.getCharts().get(chartIndex);
57+
58+
//Set properties of chart title
59+
chart.getTitle().setText("Sales By Region");
60+
chart.getTitle().getTextFont().setBold(true);
61+
chart.getTitle().getTextFont().setSize(12);
62+
63+
//Set properties of nseries
64+
chart.getNSeries().add("Data!B2:B8", true);
65+
chart.getNSeries().setCategoryData("Data!A2:A8");
66+
67+
//Set the fill colors for the series's data points (France - Portugal(7 points))
68+
ChartPointCollection chartPoints = chart.getNSeries().get(0).getPoints();
69+
70+
ChartPoint point = chartPoints.get(0);
71+
point.getArea().setForegroundColor(Color.getCyan());
72+
73+
point = chartPoints.get(1);
74+
point.getArea().setForegroundColor(Color.getBlue());
75+
76+
point = chartPoints.get(2);
77+
point.getArea().setForegroundColor(Color.getYellow());
78+
79+
point = chartPoints.get(3);
80+
point.getArea().setForegroundColor(Color.getRed());
81+
82+
point = chartPoints.get(4);
83+
point.getArea().setForegroundColor(Color.getBlack());
84+
85+
point = chartPoints.get(5);
86+
point.getArea().setForegroundColor(Color.getGreen());
87+
88+
point = chartPoints.get(6);
89+
point.getArea().setForegroundColor(Color.getMaroon());
90+
91+
//Set the legend invisible
92+
chart.setShowLegend(false);
93+
94+
//Get the Chart image
95+
ImageOrPrintOptions imgOpts = new ImageOrPrintOptions();
96+
imgOpts.setImageFormat(ImageFormat.getPng());
97+
98+
//Save the chart image file.
99+
chart.toImage(new FileOutputStream(dataDir + "AsposeChartImage_Out.png"), imgOpts);
100+
}
101+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.aspose.cells.examples.asposefeatures.charts.createcharts;
2+
3+
import com.aspose.cells.Cell;
4+
import com.aspose.cells.Cells;
5+
import com.aspose.cells.Chart;
6+
import com.aspose.cells.ChartCollection;
7+
import com.aspose.cells.ChartType;
8+
import com.aspose.cells.SeriesCollection;
9+
import com.aspose.cells.Workbook;
10+
import com.aspose.cells.Worksheet;
11+
import com.aspose.cells.WorksheetCollection;
12+
import com.aspose.cells.examples.Utils;
13+
14+
public class AsposeCreateCharts
15+
{
16+
public static void main(String[] args) throws Exception
17+
{
18+
// The path to the documents directory.
19+
String dataDir = Utils.getDataDir(AsposeCreateCharts.class);
20+
21+
// Instantiating a Workbook object
22+
Workbook workbook = new Workbook();
23+
24+
// Obtaining the reference of the first worksheet
25+
WorksheetCollection worksheets = workbook.getWorksheets();
26+
Worksheet sheet = worksheets.get(0);
27+
28+
// Adding some sample value to cells
29+
Cells cells = sheet.getCells();
30+
Cell cell = cells.get("A1");
31+
cell.setValue(50);
32+
cell = cells.get("A2");
33+
cell. setValue (100);
34+
cell = cells.get("A3");
35+
cell.setValue(150);
36+
cell = cells.get("B1");
37+
cell.setValue(4);
38+
cell = cells.get("B2");
39+
cell.setValue(20);
40+
cell = cells.get("B3");
41+
cell.setValue(50);
42+
43+
ChartCollection charts = sheet.getCharts();
44+
45+
// Adding a chart to the worksheet
46+
int chartIndex = charts.add(ChartType.PYRAMID,5,0,15,5);
47+
Chart chart = charts.get(chartIndex);
48+
49+
// Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
50+
SeriesCollection serieses = chart.getNSeries();
51+
serieses.add("A1:B3", true);
52+
53+
// Saving the Excel file
54+
workbook.save(dataDir + "AsposeChart_Out.xls");
55+
56+
// Print message
57+
System.out.println("Workbook with chart is successfully created.");
58+
}
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.aspose.cells.examples.asposefeatures.charts.createpivotcharts;
2+
3+
import com.aspose.cells.Chart;
4+
import com.aspose.cells.ChartType;
5+
import com.aspose.cells.SheetType;
6+
import com.aspose.cells.Workbook;
7+
import com.aspose.cells.Worksheet;
8+
import com.aspose.cells.examples.Utils;
9+
10+
public class AsposePivotChart
11+
{
12+
public static void main(String[] args) throws Exception
13+
{
14+
// The path to the documents directory.
15+
String dataDir = Utils.getDataDir(AsposePivotChart.class);
16+
17+
// Instantiating an Workbook object
18+
Workbook workbook = new Workbook(dataDir + "AsposePivotTable.xls");
19+
20+
// Adding a new sheet
21+
int sheetIndex = workbook.getWorksheets().add(SheetType.CHART);
22+
Worksheet sheet3 = workbook.getWorksheets().get(sheetIndex);
23+
24+
// Naming the sheet
25+
sheet3.setName("PivotChart");
26+
27+
// Adding a column chart
28+
int chartIndex = sheet3.getCharts().add(ChartType.COLUMN, 0, 5, 28, 16);
29+
Chart chart = sheet3.getCharts().get(chartIndex);
30+
31+
// Setting the pivot chart data source
32+
chart.setPivotSource("PivotTable!PivotTable1");
33+
chart.setHidePivotFieldButtons(false);
34+
35+
// Saving the Excel file
36+
workbook.save(dataDir + "Aspose_PivotChart_Out.xls");
37+
38+
// Print Message
39+
System.out.println("Pivot Chart created successfully.");
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.aspose.cells.examples.asposefeatures.converter.converttoformats;
2+
3+
import com.aspose.cells.SaveFormat;
4+
import com.aspose.cells.Workbook;
5+
import com.aspose.cells.examples.Utils;
6+
7+
public class AsposeConverter
8+
{
9+
public static void main(String[] args) throws Exception
10+
{
11+
// The path to the documents directory.
12+
String dataDir = Utils.getDataDir(AsposeConverter.class);
13+
14+
Workbook workbook = new Workbook(dataDir + "workbook.xls");
15+
16+
//Save the document in PDF format
17+
workbook.save(dataDir + "AsposeConvert_Out.pdf", SaveFormat.PDF);
18+
19+
// Print message
20+
System.out.println("Excel to PDF conversion performed successfully.");
21+
}
22+
}

0 commit comments

Comments
 (0)