Skip to content

Commit 797e4dc

Browse files
Merge pull request #23 from fahadadeel/master
Aspose.Cells Java for Jython - Examples
2 parents a080513 + 8d625c0 commit 797e4dc

File tree

118 files changed

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

118 files changed

+6294
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## Aspose.Cells Java for Jython
2+
3+
Aspose.Cells Java for Jython is a project that demonstrates / provides the Aspose.Cells for Java API usage examples in Jython.
4+
5+
## Download
6+
7+
* To download Aspose.Cells for Java API to be used with these examples, Please navigate to: http://www.aspose.com/community/files/72/java-components/aspose.cells-for-java/
8+
* Place downloaded jar file into "lib" directory.
9+
* Replace "your-lib" with the jar filename.
10+
11+
## Documentation
12+
13+
For most complete documentation of the project, check Aspose.Cells Java For Jython confluence wiki link:
14+
15+
http://www.aspose.com/docs/display/cellsjava/Aspose.Cells+Java+for+Jython
16+
17+
## Download Latest Versions?
18+
19+
* [Latest Releases on Codeplex](https://asposecellsjavajython.codeplex.com/releases/view/619599)
20+
21+
## Clone Plugin SourceCodes?
22+
23+
This project is also hosted and maintained at CodePlex. To clone navigate to:
24+
25+
* [Aspose.Cells Java for Jython on CodePlex - click here](https://asposecellsjavajython.codeplex.com/SourceControl/latest)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from asposecells import Settings
2+
from com.aspose.cells import Workbook
3+
from com.aspose.cells import SaveFormat
4+
5+
6+
class ConvertingExcelFilesToHtml:
7+
8+
def __init__(self):
9+
dataDir = Settings.dataDir + 'WorkingWithFiles/ConvertingExcelFilesToHtml/'
10+
11+
saveFormat = SaveFormat
12+
13+
workbook = Workbook(dataDir + "Book1.xls")
14+
15+
#Save the document in PDF format
16+
workbook.save(dataDir + "OutBook1.html", saveFormat.HTML)
17+
18+
# Print message
19+
print "\n Excel to HTML conversion performed successfully."
20+
21+
if __name__ == '__main__':
22+
ConvertingExcelFilesToHtml()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from asposecells import Settings
2+
from com.aspose.cells import Workbook
3+
from com.aspose.cells import HtmlSaveOptions
4+
from com.aspose.cells import SaveFormat
5+
6+
7+
class ConvertingToMhtmlFiles:
8+
9+
def __init__(self):
10+
dataDir = Settings.dataDir + 'WorkingWithFiles/ConvertingToMhtmlFiles/'
11+
12+
saveFormat = SaveFormat
13+
14+
#Specify the file path
15+
filePath = dataDir + "Book1.xlsx"
16+
17+
#Specify the HTML saving options
18+
sv = HtmlSaveOptions(saveFormat.M_HTML)
19+
20+
#Instantiate a workbook and open the template XLSX file
21+
wb = Workbook(filePath)
22+
23+
#Save the MHT file
24+
wb.save(filePath + ".out.mht", sv)
25+
26+
# Print message
27+
print "Excel to MHTML conversion performed successfully."
28+
29+
if __name__ == '__main__':
30+
ConvertingToMhtmlFiles()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from asposecells import Settings
2+
from com.aspose.cells import Workbook
3+
from com.aspose.cells import ImageFormat;
4+
from com.aspose.cells import ImageOrPrintOptions;
5+
from com.aspose.cells import SheetRender;
6+
from com.aspose.cells import SaveFormat;
7+
8+
9+
10+
class ConvertingToXPS:
11+
12+
def __init__(self):
13+
dataDir = Settings.dataDir + 'WorkingWithFiles/ConvertingToXPS/'
14+
15+
saveFormat = SaveFormat
16+
17+
workbook = Workbook(dataDir + "Book1.xls")
18+
19+
#Get the first worksheet.
20+
sheet = workbook.getWorksheets().get(0)
21+
22+
#Apply different Image and Print options
23+
options = ImageOrPrintOptions()
24+
25+
#Set the Format
26+
options.setSaveFormat(saveFormat.XPS)
27+
28+
# Render the sheet with respect to specified printing options
29+
sr = SheetRender(sheet, options)
30+
sr.toImage(0, dataDir + "out_printingxps.xps")
31+
32+
#Save the complete Workbook in XPS format
33+
workbook.save(dataDir + "out_whole_printingxps", saveFormat.XPS)
34+
35+
# Print message
36+
print "Excel to XPS conversion performed successfully."
37+
38+
if __name__ == '__main__':
39+
ConvertingToXPS()
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from asposecells import Settings
2+
from com.aspose.cells import Workbook
3+
from com.aspose.cells import ImageFormat
4+
from com.aspose.cells import ImageOrPrintOptions
5+
from com.aspose.cells import SheetRender
6+
from com.aspose.cells import SaveFormat
7+
8+
9+
10+
class ConvertingWorksheetToSVG:
11+
12+
def __init__(self):
13+
dataDir = Settings.dataDir + 'WorkingWithFiles/ConvertingWorksheetToSVG/'
14+
15+
saveFormat = SaveFormat
16+
17+
workbook = Workbook(dataDir + "Book1.xls")
18+
19+
#Convert each worksheet into svg format in a single page.
20+
imgOptions = ImageOrPrintOptions()
21+
imgOptions.setSaveFormat(saveFormat.SVG)
22+
imgOptions.setOnePagePerSheet(True)
23+
24+
#Convert each worksheet into svg format
25+
sheetCount = workbook.getWorksheets().getCount()
26+
27+
#for(i=0; i<sheetCount; i++)
28+
for i in range(sheetCount):
29+
30+
sheet = workbook.getWorksheets().get(i)
31+
32+
sr = SheetRender(sheet, imgOptions)
33+
34+
pageCount = sr.getPageCount()
35+
#for (k = 0 k < pageCount k++)
36+
for k in range(pageCount):
37+
38+
#Output the worksheet into Svg image format
39+
sr.toImage(k, dataDir + sheet.getName() + ".out.svg")
40+
41+
42+
43+
# Print message
44+
print "Excel to SVG conversion completed successfully."
45+
46+
if __name__ == '__main__':
47+
ConvertingWorksheetToSVG()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from asposecells import Settings
2+
from com.aspose.cells import Workbook
3+
from com.aspose.cells import SaveFormat
4+
5+
6+
7+
class Excel2PdfConversion:
8+
9+
def __init__(self):
10+
dataDir = Settings.dataDir + 'WorkingWithFiles/Excel2PdfConversion/'
11+
12+
saveFormat = SaveFormat
13+
14+
workbook = Workbook(dataDir + "Book1.xls")
15+
16+
#Save the document in PDF format
17+
workbook.save(dataDir + "OutBook1.pdf", saveFormat.PDF)
18+
19+
# Print message
20+
print "\n Excel to PDF conversion performed successfully."
21+
22+
if __name__ == '__main__':
23+
Excel2PdfConversion()
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from asposecells import Settings
2+
from com.aspose.cells import Workbook
3+
4+
class ManagingDocumentProperties:
5+
6+
def __init__(self):
7+
dataDir = Settings.dataDir + 'WorkingWithFiles/ManagingDocumentProperties/'
8+
9+
workbook = Workbook(dataDir + "Book1.xls")
10+
11+
#Retrieve a list of all custom document properties of the Excel file
12+
customProperties = workbook.getWorksheets().getCustomDocumentProperties()
13+
14+
#Accessing a custom document property by using the property index
15+
#customProperty1 = customProperties.get(3)
16+
17+
#Accessing a custom document property by using the property name
18+
customProperty2 = customProperties.get("Owner")
19+
20+
21+
#Adding a custom document property to the Excel file
22+
publisher = customProperties.add("Publisher", "Aspose")
23+
24+
#Save the file
25+
workbook.save(dataDir + "Test_Workbook.xls")
26+
27+
#Removing a custom document property
28+
customProperties.remove("Publisher")
29+
30+
#Save the file
31+
workbook.save(dataDir + "Test_Workbook_RemovedProperty.xls")
32+
33+
# Print message
34+
print "Excel file's custom properties accessed successfully."
35+
36+
if __name__ == '__main__':
37+
ManagingDocumentProperties()
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
from asposecells import Settings
2+
from com.aspose.cells import Workbook
3+
from com.aspose.cells import FileFormatType
4+
from com.aspose.cells import LoadOptions
5+
from java.io import FileInputStream
6+
7+
8+
class OpeningFiles:
9+
10+
def __init__(self):
11+
dataDir = Settings.dataDir + 'WorkingWithFiles/OpeningFiles/'
12+
13+
fileFormatType = FileFormatType
14+
# 1. Opening from path
15+
# Creatin an Workbook object with an Excel file path
16+
workbook1 = Workbook(dataDir + "Book1.xls")
17+
18+
print "Workbook opened using path successfully.";
19+
20+
# 2 Opening workbook from stream
21+
22+
#Create a Stream object
23+
fstream = FileInputStream(dataDir + "Book2.xls")
24+
#Creating an Workbook object with the stream object
25+
workbook2 = Workbook(fstream)
26+
fstream.close()
27+
28+
print ("Workbook opened using stream successfully.");
29+
30+
# 3.
31+
# Opening Microsoft Excel 97 Files
32+
#Createing and EXCEL_97_TO_2003 LoadOptions object
33+
loadOptions1 = LoadOptions(fileFormatType.EXCEL_97_TO_2003)
34+
#Creating an Workbook object with excel 97 file path and the loadOptions object
35+
workbook3 = Workbook(dataDir + "Book_Excel97_2003.xls", loadOptions1)
36+
# Print message
37+
print("Excel 97 Workbook opened successfully.");
38+
39+
# 4.
40+
# Opening Microsoft Excel 2007 XLSX Files
41+
#Createing and XLSX LoadOptions object
42+
loadOptions2 = LoadOptions(fileFormatType.XLSX)
43+
#Creating an Workbook object with 2007 xlsx file path and the loadOptions object
44+
workbook4 = Workbook(dataDir + "Book_Excel2007.xlsx", loadOptions2)
45+
# Print message
46+
print ("Excel 2007 Workbook opened successfully.")
47+
48+
49+
# 5.
50+
# Opening SpreadsheetML Files
51+
#Creating and EXCEL_2003_XML LoadOptions object
52+
loadOptions3 = LoadOptions(fileFormatType.EXCEL_2003_XML)
53+
#Creating an Workbook object with SpreadsheetML file path and the loadOptions object
54+
workbook5 = Workbook(dataDir + "Book3.xml", loadOptions3)
55+
56+
# Print message
57+
print ("SpreadSheetML format workbook has been opened successfully.");
58+
59+
# 6.
60+
# Opening CSV Files
61+
#Creating and CSV LoadOptions object
62+
loadOptions4 = LoadOptions(fileFormatType.CSV)
63+
#Creating an Workbook object with CSV file path and the loadOptions object
64+
workbook6 = Workbook(dataDir + "Book_CSV.csv", loadOptions4)
65+
# Print message
66+
print ("CSV format workbook has been opened successfully.")
67+
68+
69+
# 7.
70+
# Opening Tab Delimited Files
71+
# Creating and TAB_DELIMITED LoadOptions object
72+
loadOptions5 = LoadOptions(fileFormatType.TAB_DELIMITED);
73+
74+
# Creating an Workbook object with Tab Delimited text file path and the loadOptions object
75+
workbook7 = Workbook(dataDir + "Book1TabDelimited.txt", loadOptions5)
76+
77+
# Print message
78+
print("<br />");
79+
print ("Tab Delimited workbook has been opened successfully.");
80+
81+
82+
83+
# 8.
84+
# Opening Encrypted Excel Files
85+
# Creating and EXCEL_97_TO_2003 LoadOptions object
86+
loadOptions6 = LoadOptions(fileFormatType.EXCEL_97_TO_2003)
87+
88+
# Setting the password for the encrypted Excel file
89+
loadOptions6.setPassword("1234")
90+
91+
# Creating an Workbook object with file path and the loadOptions object
92+
workbook8 = Workbook(dataDir + "encryptedBook.xls", loadOptions6)
93+
94+
# Print message
95+
print("<br />");
96+
print ("Encrypted workbook has been opened successfully.");
97+
98+
99+
100+
if __name__ == '__main__':
101+
OpeningFiles()
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from asposecells import Settings
2+
from com.aspose.cells import Workbook
3+
from com.aspose.cells import FileFormatType
4+
5+
6+
class SavingFiles:
7+
8+
def __init__(self):
9+
dataDir = Settings.dataDir + 'WorkingWithFiles/SavingFiles/'
10+
11+
fileFormatType = FileFormatType
12+
13+
14+
#Creating an Workbook object with an Excel file path
15+
workbook = Workbook(dataDir + "Book1.xls")
16+
#Save in default (Excel2003) format
17+
workbook.save(dataDir + "book.default.out.xls")
18+
19+
#Save in Excel2003 format
20+
workbook.save(dataDir + "book.out.xls", fileFormatType.EXCEL_97_TO_2003)
21+
22+
#Save in Excel2007 xlsx format
23+
workbook.save(dataDir + "book.out.xlsx", fileFormatType.XLSX)
24+
25+
#Save in SpreadsheetML format
26+
workbook.save(dataDir + "book.out.xml", fileFormatType.EXCEL_2003_XML)
27+
28+
#Print Message
29+
print("<BR>")
30+
print("Worksheets are saved successfully.")
31+
32+
33+
34+
if __name__ == '__main__':
35+
SavingFiles()

0 commit comments

Comments
 (0)