Skip to content

Commit 863f4f9

Browse files
committed
New Examples Added
1 parent 622556e commit 863f4f9

File tree

15 files changed

+1070
-3
lines changed

15 files changed

+1070
-3
lines changed

Examples.xml

Lines changed: 318 additions & 3 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2001-2013 Aspose Pty Ltd. All Rights Reserved.
3+
*
4+
* This file is part of Aspose.Cells. The source code in this file
5+
* is only intended as a supplement to the documentation, and is provided
6+
* "as is", without warranty of any kind, either expressed or implied.
7+
*/
8+
9+
package programmersguide.asposecells.workingwithdata.addonfeatures.addinghyperlinkstolinkdata.addinglinktoanothercell.java;
10+
11+
import com.aspose.cells.*;
12+
13+
public class AddingLinkToAnotherCell
14+
{
15+
public static void main(String[] args) throws Exception
16+
{
17+
// The path to the documents directory.
18+
String dataDir = "src/programmersguide/asposecells/workingwithdata/addonfeatures/addinghyperlinkstolinkdata/addinglinktoanothercell/data/";
19+
20+
//Instantiating a Workbook object
21+
Workbook workbook = new Workbook();
22+
23+
//Obtaining the reference of the first worksheet.
24+
WorksheetCollection worksheets = workbook.getWorksheets();
25+
workbook.getWorksheets().add();
26+
Worksheet sheet = worksheets.get(0);
27+
28+
//Setting a value to the "A1" cell
29+
Cells cells = sheet.getCells();
30+
Cell cell = cells.get("A1");
31+
cell.setValue("Visit Aspose");
32+
33+
//Setting the font color of the cell to Blue
34+
Style style = cell.getStyle();
35+
style.getFont().setColor(Color.getBlue());
36+
37+
//Setting the font of the cell to Single Underline
38+
style.getFont().setUnderline(FontUnderlineType.SINGLE);
39+
cell.setStyle(style);
40+
41+
HyperlinkCollection hyperlinks = sheet.getHyperlinks();
42+
43+
//Adding an internal hyperlink to the "B9" cell of the other worksheet "Sheet2" in
44+
//the same Excel file
45+
hyperlinks.add("B3",1 ,1, "Sheet2!B9");
46+
47+
//Saving the Excel file
48+
workbook.save(dataDir + "output.xls");
49+
50+
// Print message
51+
System.out.println("Process completed successfully");
52+
53+
}
54+
}
55+
56+
57+
58+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2001-2013 Aspose Pty Ltd. All Rights Reserved.
3+
*
4+
* This file is part of Aspose.Cells. The source code in this file
5+
* is only intended as a supplement to the documentation, and is provided
6+
* "as is", without warranty of any kind, either expressed or implied.
7+
*/
8+
9+
package programmersguide.asposecells.workingwithdata.addonfeatures.addinghyperlinkstolinkdata.addinglinktoexternalfile.java;
10+
11+
import com.aspose.cells.*;
12+
13+
public class AddingLinkToExternalFile
14+
{
15+
public static void main(String[] args) throws Exception
16+
{
17+
// The path to the documents directory.
18+
String dataDir = "src/programmersguide/asposecells/workingwithdata/addonfeatures/addinghyperlinkstolinkdata/addinglinktoexternalfile/data/";
19+
20+
//Instantiating a Workbook object
21+
Workbook workbook = new Workbook();
22+
23+
//Obtaining the reference of the first worksheet.
24+
WorksheetCollection worksheets = workbook.getWorksheets();
25+
Worksheet sheet = worksheets.get(0);
26+
27+
//Setting a value to the "A1" cell
28+
Cells cells = sheet.getCells();
29+
Cell cell = cells.get("A1");
30+
cell.setValue("Visit Aspose");
31+
32+
//Setting the font color of the cell to Blue
33+
Style style = cell.getStyle();
34+
style.getFont().setColor(Color.getBlue());
35+
36+
//Setting the font of the cell to Single Underline
37+
style.getFont().setUnderline(FontUnderlineType.SINGLE);
38+
cell.setStyle(style);
39+
40+
HyperlinkCollection hyperlinks = sheet.getHyperlinks();
41+
42+
//Adding a link to the external file
43+
hyperlinks.add("A5", 1, 1, dataDir + "book1.xls");
44+
45+
//Saving the Excel file
46+
workbook.save(dataDir + "output.xls");
47+
48+
// Print message
49+
System.out.println("Process completed successfully");
50+
51+
}
52+
}
53+
54+
55+
56+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2001-2013 Aspose Pty Ltd. All Rights Reserved.
3+
*
4+
* This file is part of Aspose.Cells. The source code in this file
5+
* is only intended as a supplement to the documentation, and is provided
6+
* "as is", without warranty of any kind, either expressed or implied.
7+
*/
8+
9+
package programmersguide.asposecells.workingwithdata.addonfeatures.addinghyperlinkstolinkdata.addinglinktourl.java;
10+
11+
import com.aspose.cells.*;
12+
13+
public class AddingLinkToURL
14+
{
15+
public static void main(String[] args) throws Exception
16+
{
17+
// The path to the documents directory.
18+
String dataDir = "src/programmersguide/asposecells/workingwithdata/addonfeatures/addinghyperlinkstolinkdata/addinglinktourl/data/";
19+
20+
//Instantiating a Workbook object
21+
Workbook workbook = new Workbook();
22+
23+
//Obtaining the reference of the first worksheet.
24+
WorksheetCollection worksheets = workbook.getWorksheets();
25+
Worksheet sheet = worksheets.get(0);
26+
HyperlinkCollection hyperlinks = sheet.getHyperlinks();
27+
28+
//Adding a hyperlink to a URL at "A1" cell
29+
hyperlinks.add("A1",1,1,"http://www.aspose.com");
30+
31+
//Saving the Excel file
32+
workbook.save(dataDir + "output.xls");
33+
34+
// Print message
35+
System.out.println("Process completed successfully");
36+
37+
}
38+
}
39+
40+
41+
42+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2001-2013 Aspose Pty Ltd. All Rights Reserved.
3+
*
4+
* This file is part of Aspose.Cells. The source code in this file
5+
* is only intended as a supplement to the documentation, and is provided
6+
* "as is", without warranty of any kind, either expressed or implied.
7+
*/
8+
9+
package programmersguide.asposecells.workingwithdata.dataprocessingfeatures.creatingsubtotals.java;
10+
11+
import com.aspose.cells.*;
12+
13+
public class CreatingSubtotals
14+
{
15+
public static void main(String[] args) throws Exception
16+
{
17+
// The path to the documents directory.
18+
String dataDir = "src/programmersguide/asposecells/workingwithdata/dataprocessingfeatures/creatingsubtotals/data/";
19+
20+
//Instantiate a new workbook
21+
Workbook workbook = new Workbook(dataDir + "book1.xls");
22+
23+
//Get the Cells collection in the first worksheet
24+
Cells cells = workbook.getWorksheets().get(0).getCells();
25+
26+
//Create a cellarea i.e.., B3:C19
27+
CellArea ca = new CellArea();
28+
ca.StartRow = 2;
29+
ca.StartColumn =1;
30+
ca.EndRow = 18;
31+
ca.EndColumn = 2;
32+
33+
//Apply subtotal, the consolidation function is Sum and it will applied to
34+
//Second column (C) in the list
35+
cells.subtotal(ca, 0, ConsolidationFunction.SUM, new int[] { 1 });
36+
37+
//Save the excel file
38+
workbook.save(dataDir + "output.xls");
39+
40+
// Print message
41+
System.out.println("Process completed successfully");
42+
43+
}
44+
}
45+
46+
47+
48+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2001-2013 Aspose Pty Ltd. All Rights Reserved.
3+
*
4+
* This file is part of Aspose.Cells. The source code in this file
5+
* is only intended as a supplement to the documentation, and is provided
6+
* "as is", without warranty of any kind, either expressed or implied.
7+
*/
8+
9+
package programmersguide.asposecells.workingwithdata.dataprocessingfeatures.datafilteringandvalidation.autofilterdata.java;
10+
11+
import com.aspose.cells.*;
12+
13+
public class AutofilterData
14+
{
15+
public static void main(String[] args) throws Exception
16+
{
17+
// The path to the documents directory.
18+
String dataDir = "src/programmersguide/asposecells/workingwithdata/dataprocessingfeatures/datafilteringandvalidation/autofilterdata/data/";
19+
20+
//Instantiating a Workbook object
21+
Workbook workbook = new Workbook(dataDir + "book1.xls");
22+
23+
//Accessing the first worksheet in the Excel file
24+
Worksheet worksheet = workbook.getWorksheets().get(0);
25+
26+
//Creating AutoFilter by giving the cells range
27+
AutoFilter autoFilter = worksheet.getAutoFilter();
28+
CellArea area = new CellArea();
29+
autoFilter.setRange("A1:B1");
30+
31+
//Saving the modified Excel file
32+
workbook.save(dataDir + "output.xls");
33+
34+
// Print message
35+
System.out.println("Process completed successfully");
36+
}
37+
}
38+
39+
40+
41+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Copyright 2001-2013 Aspose Pty Ltd. All Rights Reserved.
3+
*
4+
* This file is part of Aspose.Cells. The source code in this file
5+
* is only intended as a supplement to the documentation, and is provided
6+
* "as is", without warranty of any kind, either expressed or implied.
7+
*/
8+
9+
package programmersguide.asposecells.workingwithdata.dataprocessingfeatures.datafilteringandvalidation.datedatavalidation.java;
10+
11+
import com.aspose.cells.*;
12+
13+
public class DateDataValidation
14+
{
15+
public static void main(String[] args) throws Exception
16+
{
17+
// The path to the documents directory.
18+
String dataDir = "src/programmersguide/asposecells/workingwithdata/dataprocessingfeatures/datafilteringandvalidation/datedatavalidation/data/";
19+
20+
// Create a workbook.
21+
Workbook workbook = new Workbook();
22+
23+
// Obtain the cells of the first worksheet.
24+
Cells cells = workbook.getWorksheets().get(0).getCells();
25+
26+
// Put a string value into the A1 cell.
27+
cells.get("A1").setValue("Please enter Date b/w 1/1/1970 and 12/31/1999");
28+
29+
// Wrap the text.
30+
Style style = cells.get("A1").getStyle();
31+
style.setTextWrapped(true);
32+
cells.get("A1").setStyle(style);
33+
34+
// Set row height and column width for the cells.
35+
cells.setRowHeight(0, 31);
36+
cells.setColumnWidth(0, 35);
37+
38+
// Get the validations collection.
39+
ValidationCollection validations = workbook.getWorksheets().get(0).getValidations();
40+
41+
// Add a new validation.
42+
int i = validations.add();
43+
Validation validation = validations.get(i);
44+
45+
// Set the data validation type.
46+
validation.setType(ValidationType.DATE);
47+
48+
// Set the operator for the data validation
49+
validation.setOperator(OperatorType.BETWEEN);
50+
51+
// Set the value or expression associated with the data validation.
52+
validation.setFormula1("1/1/1970");
53+
54+
// The value or expression associated with the second part of the data validation.
55+
validation.setFormula2("12/31/1999");
56+
57+
// Enable the error.
58+
validation.setShowError(true);
59+
60+
// Set the validation alert style.
61+
validation.setAlertStyle(ValidationAlertType.STOP);
62+
63+
// Set the title of the data-validation error dialog box
64+
validation.setErrorTitle("Date Error");
65+
66+
// Set the data validation error message.
67+
validation.setErrorMessage("Enter a Valid Date");
68+
69+
// Set and enable the data validation input message.
70+
validation.setInputMessage("Date Validation Type");
71+
validation.setIgnoreBlank(true);
72+
validation.setShowInput(true);
73+
74+
// Set a collection of CellArea which contains the data validation settings.
75+
CellArea area = new CellArea();
76+
77+
area.StartRow = 0;
78+
area.StartColumn = 1;
79+
area.EndRow = 0;
80+
area.EndColumn = 1;
81+
82+
// Add the Validation area.
83+
validation.addArea(area);
84+
85+
// Save the excel file.
86+
workbook.save(dataDir + "output.xls", FileFormatType.EXCEL_97_TO_2003);
87+
88+
// Print message
89+
System.out.println("Process completed successfully");
90+
91+
}
92+
}
93+
94+
95+
96+

0 commit comments

Comments
 (0)