Skip to content

Commit 4b4f0ed

Browse files
committed
Restructure Aspose.Cells Java for Apache POI
1 parent 585c4a5 commit 4b4f0ed

File tree

109 files changed

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

109 files changed

+3297
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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>cells-java</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.apache.poi</groupId>
20+
<artifactId>poi</artifactId>
21+
<version>3.13</version>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.apache.poi</groupId>
25+
<artifactId>poi-ooxml</artifactId>
26+
<version>3.13</version>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.apache.poi</groupId>
30+
<artifactId>poi-ooxml-schemas</artifactId>
31+
<version>3.13</version>
32+
</dependency>
33+
</dependencies>
34+
<repositories>
35+
<repository>
36+
<id>aspose-maven-repository</id>
37+
<url>http://maven.aspose.com/repository/repo/</url>
38+
</repository>
39+
</repositories>
40+
</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,41 @@
1+
package com.aspose.cells.examples.asposefeatures.charts;
2+
3+
import com.aspose.cells.MsoPresetTextEffect;
4+
import com.aspose.cells.SaveFormat;
5+
import com.aspose.cells.Workbook;
6+
import com.aspose.cells.examples.Utils;
7+
8+
public class AddWordArtWatermarkToChart
9+
{
10+
public static void main(String[] args) throws Exception
11+
{
12+
// The path to the documents directory.
13+
String dataDir = Utils.getDataDir(AddWordArtWatermarkToChart.class);
14+
15+
//Instantiate a new workbook.
16+
//Open the existing excel file.
17+
Workbook workbook = new Workbook(dataDir + "AsposeChart.xls");
18+
19+
//Get the chart in the first worksheet.
20+
com.aspose.cells.Chart chart = workbook.getWorksheets().get(0).getCharts().get(0);
21+
22+
//Add a WordArt watermark (shape) to the chart's plot area.
23+
com.aspose.cells.Shape wordart = chart.getShapes().addTextEffectInChart(MsoPresetTextEffect.TEXT_EFFECT_2,
24+
"CONFIDENTIAL", "Arial Black", 66, false, false, 1200, 500, 2000, 3000);
25+
26+
//Get the shape's fill format.
27+
com.aspose.cells.MsoFillFormat wordArtFormat = wordart.getFillFormat();
28+
29+
//Set the transparency.
30+
wordArtFormat.setTransparency(0.9);
31+
32+
//Get the line format and make it invisible.
33+
com.aspose.cells.MsoLineFormat lineFormat = wordart.getLineFormat();
34+
lineFormat.setVisible(false);
35+
36+
//Save the excel file.
37+
workbook.save(dataDir + "AsposeChartWatermarked_Out.xls", SaveFormat.EXCEL_97_TO_2003);
38+
39+
System.out.println("Chart is watermarked now.");
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.aspose.cells.examples.asposefeatures.charts;
2+
3+
import com.aspose.cells.Chart;
4+
import com.aspose.cells.Workbook;
5+
import com.aspose.cells.Worksheet;
6+
import com.aspose.cells.examples.Utils;
7+
8+
public class AsposeChangeChartPositionAndSize
9+
{
10+
public static void main(String[] args) throws Exception
11+
{
12+
// The path to the documents directory.
13+
String dataDir = Utils.getDataDir(AsposeChangeChartPositionAndSize.class);
14+
15+
Workbook workbook = new Workbook(dataDir + "AsposeChart.xls");
16+
17+
Worksheet worksheet = workbook.getWorksheets().get(0);
18+
19+
//Load the chart from source worksheet
20+
Chart chart = worksheet.getCharts().get(0);
21+
22+
//Resize the chart
23+
chart.getChartObject().setWidth(400);
24+
chart.getChartObject().setHeight(300);
25+
26+
//Reposition the chart
27+
chart.getChartObject().setX(250);
28+
chart.getChartObject().setY(150);
29+
30+
//Output the file
31+
workbook.save(dataDir + "AsposeChangeChart.xlsx");
32+
33+
System.out.println("Chart Size changed and repositioned.");
34+
}
35+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package com.aspose.cells.examples.asposefeatures.charts;
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.png"), imgOpts);
100+
}
101+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.aspose.cells.examples.asposefeatures.charts;
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 AsposeCharts
15+
{
16+
public static void main(String[] args) throws Exception
17+
{
18+
// The path to the documents directory.
19+
String dataDir = Utils.getDataDir(AsposeCharts.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.xls");
55+
56+
// Print message
57+
System.out.println("Workbook with chart is successfully created.");
58+
}
59+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.aspose.cells.examples.asposefeatures.charts;
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.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;
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.pdf", SaveFormat.PDF);
18+
19+
// Print message
20+
System.out.println("Excel to PDF conversion performed successfully.");
21+
}
22+
}

0 commit comments

Comments
 (0)