Skip to content

Commit aed8e9a

Browse files
Merge pull request #12 from fahadadeel/master
Initial Commit for Aspose.Cells Java for PHP Examples
2 parents 1047068 + 04b2f2f commit aed8e9a

File tree

117 files changed

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

117 files changed

+6451
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Aspose.Cells Java for PHP
2+
Aspose Cells Java for PHP is a PHP project that demonstrates / provides the Aspose.Cells for Java API usage examples in PHP by using PHP/JAVA Bridge.
3+
4+
You will need to configure PHP/Java Bridge before using any of the Aspose provided Java APIs in PHP e.g Aspose.Words, Aspose.Cells and Aspose.Slides etc.
5+
6+
For the configuration/setup of PHP/Java Bridge, please see:
7+
8+
http://php-java-bridge.sourceforge.net/pjb/index.php
9+
10+
To download Aspose.Cells for Java API to be used with these examples through PHP/Java Bridge
11+
Please navigate to:
12+
13+
http://www.aspose.com/community/files/72/java-components/aspose.cells-for-java/
14+
15+
For most complete documentation of the project, check Aspose.Words Java for PHP confluence wiki link:
16+
17+
http://www.aspose.com/docs/display/cellsjava/5.+Aspose.Cells+Java+for+PHP
18+
19+
20+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "asposecells/aspose_cells_java_for_php",
3+
"description": "Aspose Cells Java Examples for PHP Developers. Helps you understand how to use Aspose.Cells Java classes in your PHP Projects.",
4+
"type": "library",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Fahad Adeel",
9+
"email": "fahadadeel@gmail.com"
10+
}
11+
],
12+
"minimum-stability": "dev",
13+
"require": {
14+
"php": ">=5.3.0"
15+
},
16+
"autoload": {
17+
"psr-4": {
18+
"Aspose\\Cells\\": "src/aspose/cells"
19+
}
20+
}
21+
}

Plugins/Aspose_Cells_Java_for_PHP/composer.lock

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: fahadadeel
5+
* Date: 21/07/15
6+
* Time: 4:14 PM
7+
*/
8+
9+
namespace Aspose\Cells\WorkingWithFiles\FileHandlingFeatures;
10+
11+
use com\aspose\cells\Workbook as Workbook;
12+
use com\aspose\cells\LoadOptions as LoadOptions;
13+
use com\aspose\cells\FileFormatType as FileFormatType;
14+
use java\io\FileInputStream as FileInputStream;
15+
16+
17+
18+
class OpeningFiles {
19+
20+
public static function run($dataDir=null)
21+
{
22+
23+
$fileFormatType = new FileFormatType();
24+
25+
// 1.
26+
// Opening from path.
27+
//Creating an Workbook object with an Excel file path
28+
$workbook1 = new Workbook($dataDir . "Book1.xls");
29+
30+
// Print message
31+
32+
print("<br />");
33+
print ("Workbook opened using path successfully.");
34+
35+
// 2.
36+
// Opening workbook from stream
37+
//Create a Stream object
38+
$fstream = new FileInputStream($dataDir . "Book2.xls");
39+
40+
//Creating an Workbook object with the stream object
41+
$workbook2 = new Workbook($fstream);
42+
43+
$fstream->close();
44+
45+
// Print message
46+
print("<br />");
47+
print ("Workbook opened using stream successfully.");
48+
49+
50+
// 3.
51+
// Opening Microsoft Excel 97 Files
52+
//Createing and EXCEL_97_TO_2003 LoadOptions object
53+
$loadOptions1 = new LoadOptions($fileFormatType->EXCEL_97_TO_2003);
54+
55+
//Creating an Workbook object with excel 97 file path and the loadOptions object
56+
$workbook3 = new Workbook($dataDir . "Book_Excel97_2003.xls", $loadOptions1);
57+
58+
// Print message
59+
print("<br />");
60+
print("Excel 97 Workbook opened successfully.");
61+
62+
63+
64+
// 4.
65+
// Opening Microsoft Excel 2007 XLSX Files
66+
//Createing and XLSX LoadOptions object
67+
$loadOptions2 = new LoadOptions($fileFormatType->XLSX);
68+
69+
//Creating an Workbook object with 2007 xlsx file path and the loadOptions object
70+
$workbook4 = new Workbook($dataDir . "Book_Excel2007.xlsx", $loadOptions2);
71+
72+
// Print message
73+
print("<br />");
74+
print ("Excel 2007 Workbook opened successfully.");
75+
76+
77+
78+
// 5.
79+
// Opening SpreadsheetML Files
80+
//Creating and EXCEL_2003_XML LoadOptions object
81+
$loadOptions3 = new LoadOptions($fileFormatType->EXCEL_2003_XML);
82+
83+
//Creating an Workbook object with SpreadsheetML file path and the loadOptions object
84+
$workbook5 = new Workbook($dataDir . "Book3.xml", $loadOptions3);
85+
86+
// Print message
87+
print("<br />");
88+
print ("SpreadSheetML format workbook has been opened successfully.");
89+
90+
// 6.
91+
// Opening CSV Files
92+
//Creating and CSV LoadOptions object
93+
$loadOptions4 = new LoadOptions($fileFormatType->CSV);
94+
95+
//Creating an Workbook object with CSV file path and the loadOptions object
96+
$workbook6 = new Workbook($dataDir . "Book_CSV.csv", $loadOptions4);
97+
98+
// Print message
99+
print("<br />");
100+
print ("CSV format workbook has been opened successfully.");
101+
102+
103+
104+
// 7.
105+
// Opening Tab Delimited Files
106+
//Creating and TAB_DELIMITED LoadOptions object
107+
$loadOptions5 = new LoadOptions($fileFormatType->TAB_DELIMITED);
108+
109+
//Creating an Workbook object with Tab Delimited text file path and the loadOptions object
110+
$workbook7 = new Workbook($dataDir . "Book1TabDelimited.txt", $loadOptions5);
111+
112+
// Print message
113+
print("<br />");
114+
print ("Tab Delimited workbook has been opened successfully.");
115+
116+
117+
118+
// 8.
119+
// Opening Encrypted Excel Files
120+
//Creating and EXCEL_97_TO_2003 LoadOptions object
121+
$loadOptions6 = new LoadOptions($fileFormatType->EXCEL_97_TO_2003);
122+
123+
//Setting the password for the encrypted Excel file
124+
$loadOptions6->setPassword("1234");
125+
126+
//Creating an Workbook object with file path and the loadOptions object
127+
$workbook8 = new Workbook($dataDir . "encryptedBook.xls", $loadOptions6);
128+
129+
// Print message
130+
print("<br />");
131+
print ("Encrypted workbook has been opened successfully.");
132+
133+
134+
}
135+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: assadmahmood
5+
* Date: 21/07/15
6+
* Time: 5:00 PM
7+
*/
8+
9+
namespace Aspose\Cells\WorkingWithFiles\FileHandlingFeatures;
10+
11+
use com\aspose\cells\Workbook as Workbook;
12+
use com\aspose\cells\FileFormatType as FileFormatType;
13+
14+
15+
class SavingFiles {
16+
17+
public static function run($dataDir=null)
18+
{
19+
20+
$fileFormatType = new FileFormatType();
21+
22+
//Creating an Workbook object with an Excel file path
23+
$workbook = new Workbook($dataDir . "book.xls");
24+
25+
//Save in default (Excel2003) format
26+
$workbook->save($dataDir . "book.default.out.xls");
27+
28+
//Save in Excel2003 format
29+
$workbook->save($dataDir . "book.out.xls",$fileFormatType->EXCEL_97_TO_2003);
30+
31+
//Save in Excel2007 xlsx format
32+
$workbook->save($dataDir . "book.out.xlsx", $fileFormatType->XLSX);
33+
34+
//Save in SpreadsheetML format
35+
$workbook->save($dataDir . "book.out.xml", $fileFormatType->EXCEL_2003_XML);
36+
37+
//Print Message
38+
print("<BR>");
39+
print("Worksheets are saved successfully.");
40+
}
41+
42+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?php
2+
3+
4+
namespace Aspose\Cells\WorkingWithFiles\UtilityFeatures;
5+
6+
use com\aspose\cells\Workbook as Workbook;
7+
use com\aspose\cells\ChartType as ChartType;
8+
use com\aspose\cells\ImageOrPrintOptions as ImageOrPrintOptions;
9+
use com\aspose\cells\ImageFormat as ImageFormat;
10+
11+
use java\awt\Color as Color;
12+
use java\io\FileOutputStream as FileOutputStream;
13+
14+
15+
16+
class ChartToImage {
17+
18+
public static function run($dataDir=null)
19+
{
20+
21+
$chartType = new ChartType();
22+
$color = new Color();
23+
$imageFormat = new ImageFormat();
24+
25+
//Create a new Workbook.
26+
$workbook = new Workbook();
27+
28+
//Get the first worksheet.
29+
$sheet = $workbook->getWorksheets()->get(0);
30+
31+
//Set the name of worksheet
32+
$sheet->setName("Data");
33+
34+
//Get the cells collection in the sheet.
35+
$cells = $workbook->getWorksheets()->get(0)->getCells();
36+
37+
//Put some values into a cells of the Data sheet.
38+
$cells->get("A1")->setValue("Region");
39+
$cells->get("A2")->setValue("France");
40+
$cells->get("A3")->setValue("Germany");
41+
$cells->get("A4")->setValue("England");
42+
$cells->get("A5")->setValue("Sweden");
43+
$cells->get("A6")->setValue("Italy");
44+
$cells->get("A7")->setValue("Spain");
45+
$cells->get("A8")->setValue("Portugal");
46+
$cells->get("B1")->setValue("Sale");
47+
$cells->get("B2")->setValue(70000);
48+
$cells->get("B3")->setValue(55000);
49+
$cells->get("B4")->setValue(30000);
50+
$cells->get("B5")->setValue(40000);
51+
$cells->get("B6")->setValue(35000);
52+
$cells->get("B7")->setValue(32000);
53+
$cells->get("B8")->setValue(10000);
54+
55+
//Create chart
56+
$chartIndex = $sheet->getCharts()->add($chartType->COLUMN, 12, 1, 33, 12);
57+
$chart = $sheet->getCharts()->get($chartIndex);
58+
59+
//Set properties of chart title
60+
$chart->getTitle()->setText("Sales By Region");
61+
$chart->getTitle()->getFont()->setBold(true);
62+
$chart->getTitle()->getFont()->setSize(12);
63+
64+
//Set properties of nseries
65+
$chart->getNSeries()->add("Data!B2:B8", true);
66+
$chart->getNSeries()->setCategoryData("Data!A2:A8");
67+
68+
//Set the fill colors for the series's data points (France - Portugal(7 points))
69+
$chartPoints = $chart->getNSeries()->get(0)->getPoints();
70+
71+
$point = $chartPoints->get(0);
72+
$point->getArea()->setForegroundColor(java_values($color->getCyan()));
73+
74+
$point = $chartPoints->get(1);
75+
$point->getArea()->setForegroundColor($color->getBlue());
76+
77+
$point = $chartPoints->get(2);
78+
$point->getArea()->setForegroundColor($color->getYellow());
79+
80+
$point = $chartPoints->get(3);
81+
$point->getArea()->setForegroundColor($color->getRed());
82+
83+
$point = $chartPoints->get(4);
84+
$point->getArea()->setForegroundColor($color->getBlack());
85+
86+
$point = $chartPoints->get(5);
87+
$point->getArea()->setForegroundColor($color->getGreen());
88+
89+
$point = $chartPoints->get(6);
90+
$point->getArea()->setForegroundColor($color->getMaroon());
91+
92+
//Set the legend invisible
93+
$chart->setShowLegend(false);
94+
95+
96+
97+
//Get the Chart image
98+
$imgOpts = new ImageOrPrintOptions();
99+
$imgOpts->setImageFormat($imageFormat->getEmf());
100+
101+
$fs = new FileOutputStream($dataDir . "Chart.emf");
102+
103+
//Save the chart image file.
104+
$chart->toImage($fs, $imgOpts);
105+
106+
$fs->close();
107+
108+
// Print message
109+
print("<BR>");
110+
print("Processing performed successfully.");
111+
112+
}
113+
114+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: fahadadeel
5+
* Date: 05/08/15
6+
* Time: 10:35 AM
7+
*/
8+
9+
namespace Aspose\Cells\WorkingWithFiles\UtilityFeatures;
10+
11+
use com\aspose\cells\Workbook as Workbook;
12+
use com\aspose\cells\SaveFormat as SaveFormat;
13+
14+
15+
class ConvertingExcelFilesToHtml {
16+
17+
public static function run($dataDir=null)
18+
{
19+
$saveFormat = new SaveFormat();
20+
21+
$workbook = new Workbook($dataDir . "Book1.xls");
22+
23+
//Save the document in PDF format
24+
$workbook->save($dataDir . "OutBook1.html", $saveFormat->HTML);
25+
26+
// Print message
27+
echo "\n Excel to HTML conversion performed successfully.";
28+
}
29+
30+
}

0 commit comments

Comments
 (0)