Skip to content

Commit 870a8e4

Browse files
committed
New Examples Added
New Examples Added
1 parent a7dc0b0 commit 870a8e4

File tree

26 files changed

+961
-0
lines changed

26 files changed

+961
-0
lines changed

Examples.xml

Lines changed: 245 additions & 0 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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.namedranges.accessallnamedranges.java;
10+
11+
import com.aspose.cells.*;
12+
13+
public class AccessAllNamedRanges
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/namedranges/accessallnamedranges/data/";
19+
20+
//Instantiating a Workbook object
21+
Workbook workbook = new Workbook(dataDir + "book1.xls");
22+
23+
WorksheetCollection worksheets = workbook.getWorksheets();
24+
25+
//Accessing the first worksheet in the Excel file
26+
Worksheet sheet = worksheets.get(0);
27+
Cells cells = sheet.getCells();
28+
29+
//Getting all named ranges
30+
Range[] namedRanges = worksheets.getNamedRanges();
31+
32+
// Print message
33+
System.out.println("Number of Named Ranges : " + namedRanges.length);
34+
}
35+
}
36+
37+
38+
39+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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.namedranges.accessspecificnamedrange.java;
10+
11+
import com.aspose.cells.*;
12+
13+
public class AccessSpecificNamedRange
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/namedranges/accessspecificnamedrange/data/";
19+
20+
//Instantiating a Workbook object
21+
Workbook workbook = new Workbook(dataDir + "book1.xls");
22+
23+
WorksheetCollection worksheets = workbook.getWorksheets();
24+
25+
//Accessing the first worksheet in the Excel file
26+
Worksheet sheet = worksheets.get(0);
27+
Cells cells = sheet.getCells();
28+
29+
//Getting the specified named range
30+
Range namedRange = worksheets.getRangeByName("TestRange");
31+
32+
// Print message
33+
System.out.println("Named Range : " + namedRange.getRefersTo());
34+
}
35+
}
36+
37+
38+
39+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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.namedranges.copynamedranges.java;
10+
11+
import com.aspose.cells.*;
12+
13+
public class CopyNamedRanges
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/namedranges/copynamedranges/data/";
19+
20+
//Instantiating a Workbook object
21+
Workbook workbook = new Workbook();
22+
23+
WorksheetCollection worksheets = workbook.getWorksheets();
24+
25+
//Accessing the first worksheet in the Excel file
26+
Worksheet sheet = worksheets.get(0);
27+
Cells cells = sheet.getCells();
28+
29+
//Creating a named range
30+
Range namedRange = cells.createRange("B4", "G14");
31+
namedRange.setName("TestRange");
32+
33+
//Input some data with some formattings into
34+
//a few cells in the range.
35+
namedRange.get(0, 0).setValue("Test");
36+
namedRange.get(0, 4).setValue("123");
37+
38+
39+
//Creating a named range
40+
Range namedRange2 = cells.createRange("H4", "M14");
41+
namedRange2.setName("TestRange2");
42+
43+
namedRange2.copy(namedRange);
44+
45+
workbook.save(dataDir + "copyranges.xls");
46+
47+
// Print message
48+
System.out.println("Process completed successfully");
49+
}
50+
}
51+
52+
53+
54+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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.namedranges.createnamedrangeofcells.java;
10+
11+
import com.aspose.cells.*;
12+
13+
public class CreateNamedRangeofCells
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/namedranges/createnamedrangeofcells/data/";
19+
20+
//Instantiating a Workbook object
21+
Workbook workbook = new Workbook(dataDir + "book1.xls");
22+
23+
WorksheetCollection worksheets = workbook.getWorksheets();
24+
25+
//Accessing the first worksheet in the Excel file
26+
Worksheet sheet = worksheets.get(0);
27+
Cells cells = sheet.getCells();
28+
29+
//Creating a named range
30+
Range namedRange = cells.createRange("B4", "G14");
31+
namedRange.setName("TestRange");
32+
33+
//Saving the modified Excel file in default (that is Excel 2000) format
34+
workbook.save(dataDir + "output.xls");
35+
36+
// Print message
37+
System.out.println("Process completed successfully");
38+
}
39+
}
40+
41+
42+
43+

0 commit comments

Comments
 (0)