Last active
September 8, 2025 06:52
-
-
Save aspose-cells-gists/7bb30376b4d40cdfd596286870fb9752 to your computer and use it in GitHub Desktop.
Aspose.Cells for Python via .NET
This gist exceeds the recommended number of files (~10).
To access all files, please clone this gist.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /.vs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import aspose.cells | |
| from aspose.cells import Workbook | |
| # Create a new Workbook. | |
| workbook = Workbook() | |
| # Get the first worksheet. | |
| worksheet = workbook.worksheets.get(0) | |
| # Get the background picture. | |
| with open('Background.bmp', 'rb') as f: | |
| data = f.read() | |
| # Set the background image for the sheet. | |
| worksheet.background_image = data | |
| # Save the excel file | |
| workbook.save("background.xlsx") | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| This Gist contains code example snippets for Aspose.Cells for Python via .NET. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Path to source file | |
| filePath = dataDir + "Book1.xlsx" | |
| # Instantiating a Workbook object | |
| workbook = Workbook(filePath) | |
| # Instantiate a workbook from source file | |
| wb = Workbook(filePath) | |
| # Access the first workbook | |
| worksheet = wb.worksheets[0] | |
| # Access the Maximum Display Range | |
| range = worksheet.cells.max_display_range | |
| # Print the Maximum Display Range RefersTo property | |
| print("Maximum Display Range: " + range.refers_to) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Open an existing worksheet | |
| workbook = Workbook(dataDir + "book1.xls") | |
| # Using the Sheet 1 in Workbook | |
| worksheet = workbook.worksheets[0] | |
| # Accessing a cell using its row and column. | |
| cell = worksheet.cells.get_cell(0, 0) | |
| value = str(cell.value) | |
| print(value) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| workbook = Workbook(dataDir + "book1.xls") | |
| # Using the Sheet 1 in Workbook | |
| worksheet = workbook.worksheets[0] | |
| # Accessing a cell using its name | |
| cell = worksheet.cells.get("A1") | |
| value = str(cell.value) | |
| print(value) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Instantiating a Workbook object | |
| workbook = Workbook(dataDir + "book1.xls") | |
| # Using the Sheet 1 in Workbook | |
| worksheet = workbook.worksheets[0] | |
| # Accessing a cell using its row and column | |
| cell = worksheet.cells.get(0, 0) | |
| value = str(cell.value) | |
| print(value) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.drawing import PlacementType | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiate a new workbook | |
| workbook = Workbook() | |
| # Get the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Insert a string value to a cell | |
| worksheet.cells.get("C2").put_value("Image Hyperlink") | |
| # Set the 4th row height | |
| worksheet.cells.set_row_height(3, 100) | |
| # Set the C column width | |
| worksheet.cells.set_column_width(2, 21) | |
| # Add a picture to the C4 cell | |
| index = worksheet.pictures.add(3, 2, 4, 3, dataDir + "aspose-logo.jpg") | |
| # Get the picture object | |
| pic = worksheet.pictures[index] | |
| # Set the placement type | |
| pic.placement = PlacementType.FREE_FLOATING | |
| # Add an image hyperlink | |
| hlink = pic.add_hyperlink("http://www.aspose.com/") | |
| # Specify the screen tip | |
| hlink.screen_tip = "Click to go to Aspose site" | |
| dataDir = dataDir + "ImageHyperlink.out.xls" | |
| # Save the Excel file | |
| workbook.save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from datetime import datetime | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Obtaining the reference of the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Adding a string value to the cell | |
| worksheet.cells.get("A1").put_value("Hello World") | |
| # Adding a double value to the cell | |
| worksheet.cells.get("A2").put_value(20.5) | |
| # Adding an integer value to the cell | |
| worksheet.cells.get("A3").put_value(15) | |
| # Adding a boolean value to the cell | |
| worksheet.cells.get("A4").put_value(True) | |
| # Adding a date/time value to the cell | |
| worksheet.cells.get("A5").put_value(datetime.now()) | |
| # Setting the display format of the date | |
| style = worksheet.cells.get("A5").get_style() | |
| style.number = 15 | |
| worksheet.cells.get("A5").set_style(style) | |
| # Saving the Excel file | |
| workbook.save(dataDir + "output.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import SaveFormat, Workbook | |
| # source directory | |
| SourceDir = "./" | |
| # Output directory | |
| outputDir = "./" | |
| # Load your source workbook | |
| wb = Workbook(SourceDir + "sampleAdvancedFilter.xlsx") | |
| # Access first worksheet | |
| ws = wb.worksheets[0] | |
| # Apply advanced filter on range A5:D19 and criteria range is A1:D2 | |
| # Besides, we want to filter in place | |
| # And, we want all filtered records not just unique records | |
| ws.advanced_filter(True, "A5:D19", "A1:D2", "", False) | |
| # Save the workbook in xlsx format | |
| wb.save(outputDir + "outputAdvancedFilter.xlsx", SaveFormat.XLSX) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import CellArea, ConsolidationFunction, Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create workbook from source Excel file | |
| workbook = Workbook(dataDir + "Book1.xlsx") | |
| # Access the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Get the Cells collection in the first worksheet | |
| cells = worksheet.cells | |
| # Create a cellarea i.e.., A2:B11 | |
| ca = CellArea.create_cell_area("A2", "B11") | |
| # Apply subtotal, the consolidation function is Sum and it will applied to Second column (B) in the list | |
| cells.subtotal(ca, 0, ConsolidationFunction.SUM, [1 ], True, False, True) | |
| # Set the direction of outline summary | |
| worksheet.outline.summary_row_below = True | |
| # Save the excel file | |
| workbook.save(dataDir + "output_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create workbook object | |
| workbook = Workbook() | |
| # Access first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Access cell B2 and add some value inside it | |
| cell = worksheet.cells.get("B2") | |
| cell.put_value("Welcome to Aspose!") | |
| # Enlarge its font to size 16 | |
| style = cell.get_style() | |
| style.font.size = 16 | |
| cell.set_style(style) | |
| # Calculate the width and height of the cell value in unit of pixels | |
| widthOfValue = cell.get_width_of_value() | |
| heightOfValue = cell.get_height_of_value() | |
| # Print both values | |
| print("Width of Cell Value: " + str(widthOfValue)) | |
| print("Height of Cell Value: " + str(heightOfValue)) | |
| # Set the row height and column width to adjust/fit the cell value inside cell | |
| worksheet.cells.set_column_width_pixel(1, widthOfValue) | |
| worksheet.cells.set_row_height_pixel(1, heightOfValue) | |
| # Save the output excel file | |
| workbook.save(dataDir + "output_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import io | |
| import aspose.cells | |
| from aspose.cells import Workbook, Worksheet, Cells | |
| workbook = Workbook("sample.xlsx") | |
| sheet = workbook.worksheets[0] | |
| cells = sheet.cells; | |
| row = cells.check_row(1); | |
| if row: | |
| #get Maximum column index of Row which contains data or style. | |
| print("Max column index in row: " + str(row.last_cell.column)) | |
| #get Maximum column index of Row which contains data. | |
| print("Max data column index in row: " + str(row.last_data_cell.column)) | |
| # create the range of column B | |
| columnRange = cells.create_range(1, 1, True) | |
| max_row_index = cells.max_row + 1 | |
| maxRow = 0 | |
| maxDataRow = 0 | |
| for row_index in range(0,max_row_index): | |
| curr_cell = cells.check_cell(row_index, 1) | |
| if curr_cell and curr_cell.string_value: | |
| maxDataRow = curr_cell.row | |
| if curr_cell and (curr_cell.string_value or curr_cell.has_custom_style): | |
| maxRow = curr_cell.row | |
| # Maximum row index of Column which contains data or style. | |
| print("Max row index in Column: " + str(maxRow)) | |
| # Maximum row index of Column which contains data. | |
| print("Max data row index in Column: " + str(maxDataRow)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import CellsHelper | |
| # Long name will be truncated to 31 characters | |
| name1 = CellsHelper.create_safe_sheet_name("this is first name which is created using CellsHelper.CreateSafeSheetName and truncated to 31 characters") | |
| # Any invalid character will be replaced with _ | |
| name2 = CellsHelper.create_safe_sheet_name(" <> + (adj.Private ? \" Private\" : \")", '_') | |
| # Display first name | |
| print(name1) | |
| # Display second name | |
| print(name2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import io | |
| import aspose.cells | |
| from aspose.cells import Workbook, Worksheet, Cells, CellsHelper | |
| workbook = Workbook("Sample.xlsx"); | |
| a1_cell_value = workbook.worksheets[0].cells.get("A1").string_value | |
| print("Text width: " + str(CellsHelper.get_text_width(a1_cell_value, workbook.default_style.font, 1.0))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import io | |
| import aspose.cells | |
| from aspose.cells import Workbook, Worksheet, Cells, CellsHelper | |
| row = 3 | |
| column = 5 | |
| name = CellsHelper.cell_index_to_name(row, column) | |
| print("Cell name: " + name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import io | |
| import aspose.cells | |
| from aspose.cells import Workbook, Worksheet, Cells, CellsHelper | |
| name = "C4"; | |
| row = [] | |
| column = [] | |
| CellsHelper.cell_name_to_index(name, row, column) | |
| print("Row: " + str(row[0]) + " , Column: " + str(column[0])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Instantiate workbook object with an Excel file | |
| workbook = Workbook(dataDir + "SampleBook.xlsx") | |
| for i in range(len(workbook.worksheets)): | |
| workbook.worksheets[i].cells.convert_string_to_numeric_value() | |
| workbook.save(dataDir + "output_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import CellArea, ConsolidationFunction, Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Instantiate a new workbook | |
| # Open the template file | |
| workbook = Workbook(dataDir + "book1.xls") | |
| # Get the Cells collection in the first worksheet | |
| cells = workbook.worksheets[0].cells | |
| # Create a cellarea i.e.., B3:C19 | |
| ca = CellArea() | |
| ca.start_row = 2 | |
| ca.start_column = 1 | |
| ca.end_row = 18 | |
| ca.end_column = 2 | |
| # Apply subtotal, the consolidation function is Sum and it will applied to | |
| # Second column (C) in the list | |
| cells.subtotal(ca, 0, ConsolidationFunction.SUM, [1 ]) | |
| # Save the excel file | |
| workbook.save(dataDir + "output.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import CellArea, SortOrder, Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Instantiate a new Workbook object. | |
| # Load a template file. | |
| workbook = Workbook(dataDir + "book1.xls") | |
| # Get the workbook datasorter object. | |
| sorter = workbook.data_sorter | |
| # Set the first order for datasorter object. | |
| sorter.order1 = SortOrder.DESCENDING | |
| # Define the first key. | |
| sorter.key1 = 0 | |
| # Set the second order for datasorter object. | |
| sorter.order2 = SortOrder.ASCENDING | |
| # Define the second key. | |
| sorter.key2 = 1 | |
| # Create a cells area (range). | |
| ca = CellArea() | |
| # Specify the start row index. | |
| ca.start_row = 0 | |
| # Specify the start column index. | |
| ca.start_column = 0 | |
| # Specify the last row index. | |
| ca.end_row = 13 | |
| # Specify the last column index. | |
| ca.end_column = 1 | |
| # Sort data in the specified data range (A1:B14) | |
| sorter.sort(workbook.worksheets[0].cells, ca) | |
| # Save the excel file. | |
| workbook.save(dataDir + "output.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import CellValueType, Workbook | |
| from datetime import datetime | |
| # Instantiating an Workbook object | |
| workbook = Workbook() | |
| workbook.settings.date1904 = False | |
| # Obtaining the reference of the newly added worksheet | |
| ws = workbook.worksheets[0] | |
| cells = ws.cells | |
| dateData = datetime(2023, 11, 23) | |
| # Setting the DateTime value to the cells | |
| a1 = cells.get("A1") | |
| a1.put_value(dateData) | |
| # Check if the cell contains a numeric value | |
| if a1.type == CellValueType.IS_NUMERIC: | |
| print("A1 is Numeric Value: " + str(a1.double_value)) | |
| workbook.settings.date1904 = True | |
| print("use The 1904 date system====================") | |
| # Setting the DateTime value to the cells | |
| a2 = cells.get("A2") | |
| a2.value = dateData | |
| # Check if the cell contains a numeric value | |
| if a2.type == CellValueType.IS_NUMERIC: | |
| print("A2 is Numeric Value: " + str(a2.double_value)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import CellValueType, Workbook | |
| from datetime import datetime | |
| # Instantiating an Workbook object | |
| workbook = Workbook() | |
| # Obtaining the reference of the newly added worksheet | |
| ws = workbook.worksheets[0] | |
| cells = ws.cells | |
| # Setting the DateTime value to the cells | |
| a1 = cells.get("A1") | |
| a1.put_value(datetime.now()) | |
| # Check if the cell contains a numeric value | |
| if a1.type == CellValueType.IS_NUMERIC: | |
| print("A1 is Numeric Value: " + str(a1.is_numeric_value)) | |
| a1Style = a1.get_style() | |
| # Set custom Datetime style | |
| a1Style.custom = "mm-dd-yy hh:mm:ss" | |
| a1.set_style(a1Style) | |
| # Check if the cell contains a DateTime value | |
| if a1.type == CellValueType.IS_DATE_TIME: | |
| print("Cell A1 contains a DateTime value.") | |
| # Get the DateTime value | |
| dateTimeValue = a1.date_time_value | |
| # Now, you can use dateTimeValue as needed | |
| print("A1 DateTime Value: " + str(dateTimeValue)) | |
| # Output date formatted string | |
| print("A1 DateTime String Value: " + a1.string_value) | |
| else: | |
| print("Cell A1 does not contain a DateTime value.") | |
| # Setting the DateTime value to the cells | |
| a2 = cells.get("A2") | |
| a2.value = datetime.now() | |
| # Check if the cell contains a numeric value | |
| if a2.type == CellValueType.IS_NUMERIC: | |
| print("A2 is Numeric Value: " + str(a2.is_numeric_value)) | |
| a2Style = a2.get_style() | |
| # Set the display format of numbers and dates. | |
| a2Style.number = 22 | |
| a2.set_style(a2Style) | |
| # Check if the cell contains a DateTime value | |
| if a2.type == CellValueType.IS_DATE_TIME: | |
| print("Cell A2 contains a DateTime value.") | |
| # Get the DateTime value | |
| dateTimeValue = a2.date_time_value | |
| # Now, you can use dateTimeValue as needed | |
| print("A2 DateTime Value: " + str(dateTimeValue)) | |
| # Output date formatted string | |
| print("A2 DateTime String Value: " + a2.string_value) | |
| else: | |
| print("Cell A2 does not contain a DateTime value.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import CellValueType, Workbook | |
| from datetime import datetime | |
| # Instantiating an Workbook object | |
| workbook = Workbook() | |
| # Obtaining the reference of the newly added worksheet | |
| ws = workbook.worksheets[0] | |
| cells = ws.cells | |
| # Setting the DateTime value to the cells | |
| a1 = cells.get("A1") | |
| a1.put_value(datetime.now()) | |
| # Check if the cell contains a numeric value | |
| if a1.type == CellValueType.IS_NUMERIC: | |
| print("A1 is Numeric Value: " + str(a1.is_numeric_value)) | |
| a1Style = a1.get_style() | |
| # Set custom Datetime style | |
| a1Style.custom = "mm-dd-yy hh:mm:ss" | |
| a1.set_style(a1Style) | |
| # Check if the cell contains a DateTime value | |
| if a1.type == CellValueType.IS_DATE_TIME: | |
| print("Cell A1 contains a DateTime value.") | |
| else: | |
| print("Cell A1 does not contain a DateTime value.") | |
| # Setting the DateTime value to the cells | |
| a2 = cells.get("A2") | |
| a2.value = datetime.now() | |
| # Check if the cell contains a numeric value | |
| if a2.type == CellValueType.IS_NUMERIC: | |
| print("A2 is Numeric Value: " + str(a2.is_numeric_value)) | |
| a2Style = a2.get_style() | |
| # Set the display format of numbers and dates. | |
| a2Style.number = 22 | |
| a2.set_style(a2Style) | |
| # Check if the cell contains a DateTime value | |
| if a2.type == CellValueType.IS_DATE_TIME: | |
| print("Cell A2 contains a DateTime value.") | |
| else: | |
| print("Cell A2 does not contain a DateTime value.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # source directory | |
| SourceDir = "./" | |
| workbook = Workbook(SourceDir + "LinkTypes.xlsx") | |
| # Get the first (default) worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Create a range A2:B3 | |
| range = worksheet.cells.create_range("A1", "A7") | |
| # Get Hyperlinks in range | |
| hyperlinks = range.hyperlinks | |
| for link in hyperlinks: | |
| print(link.text_to_display + ": " + str(link.link_type)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| workbook = Workbook(dataDir + "Sample.xlsx") | |
| worksheet = workbook.worksheets[0] | |
| for i in range(len(worksheet.hyperlinks)): | |
| hl = worksheet.hyperlinks[i] | |
| hl.address = "http://www.aspose.com" | |
| workbook.save(dataDir + "output_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Instantiating a Workbook object | |
| # Opening the Excel file through the file stream | |
| workbook = Workbook("sample.xlsx") | |
| # Accessing the first worksheet in the Excel file | |
| worksheet = workbook.worksheets[0] | |
| # Method 1: Call MatchBlanks function to apply the filter | |
| # worksheet.AutoFilter.MatchBlanks(1); | |
| # Method 2: Call AddFilter function and set criteria to "" | |
| # worksheet.AutoFilter.AddFilter(1, ""); | |
| # Method 3: Call AddFilter function and set criteria to null | |
| worksheet.auto_filter.add_filter(1, None) | |
| # Call refresh function to update the worksheet | |
| worksheet.auto_filter.refresh() | |
| # Saving the modified Excel file | |
| workbook.save("FilteredBlanks.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Instantiating a Workbook object | |
| # Opening the Excel file through the file stream | |
| workbook = Workbook("sample.xlsx") | |
| # Accessing the first worksheet in the Excel file | |
| worksheet = workbook.worksheets[0] | |
| # Call MatchBlanks function to apply the filter | |
| worksheet.auto_filter.match_non_blanks(1) | |
| # Call refresh function to update the worksheet | |
| worksheet.auto_filter.refresh() | |
| # Saving the modified Excel file | |
| workbook.save("FilteredNonBlanks.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| # Source directory | |
| sourceDir = "./" | |
| # Output directory | |
| outputDir = "./" | |
| # Instantiating a Workbook object | |
| # Opening the Excel file through the file stream | |
| workbook = Workbook(sourceDir + "Blank.xlsx") | |
| # Accessing the first worksheet in the Excel file | |
| worksheet = workbook.worksheets[0] | |
| # Call MatchBlanks function to apply the filter | |
| worksheet.auto_filter.match_blanks(0) | |
| # Call refresh function to update the worksheet | |
| worksheet.auto_filter.refresh() | |
| # Saving the modified Excel file | |
| workbook.save(outputDir + "FilteredBlank.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import BackgroundType, Workbook | |
| from aspose.pydrawing import Color | |
| # The path to the documents directory. | |
| # Source directory | |
| sourceDir = "./" | |
| # Output directory | |
| outputDir = "./" | |
| # Instantiating a Workbook object | |
| # Opening the Excel file through the file stream | |
| workbook = Workbook(sourceDir + "ColouredCells.xlsx") | |
| # Instantiating a CellsColor object for foreground color | |
| clrForeground = workbook.create_cells_color() | |
| clrForeground.color = Color.red | |
| # Instantiating a CellsColor object for background color | |
| clrBackground = workbook.create_cells_color() | |
| clrBackground.color = Color.white | |
| # Accessing the first worksheet in the Excel file | |
| worksheet = workbook.worksheets[0] | |
| # Call AddFillColorFilter function to apply the filter | |
| worksheet.auto_filter.add_fill_color_filter(0, BackgroundType.SOLID, clrForeground, clrBackground) | |
| # Call refresh function to update the worksheet | |
| worksheet.auto_filter.refresh() | |
| # Saving the modified Excel file | |
| workbook.save(outputDir + "FilteredColouredCells.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import FilterOperatorType, Workbook | |
| # Instantiating a Workbook object containing sample data | |
| workbook = Workbook("sourseSampleCountryNames.xlsx") | |
| # Accessing the first worksheet in the Excel file | |
| worksheet = workbook.worksheets[0] | |
| # Creating AutoFilter by giving the cells range | |
| worksheet.auto_filter.range = "A1:A18" | |
| # Initialize filter for rows containing string "Ba" | |
| worksheet.auto_filter.custom(0, FilterOperatorType.CONTAINS, "Ba") | |
| # Refresh the filter to show/hide filtered rows | |
| worksheet.auto_filter.refresh() | |
| # Saving the modified Excel file | |
| workbook.save("outSourseSampleCountryNames.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import FilterOperatorType, Workbook | |
| # Instantiating a Workbook object containing sample data | |
| workbook = Workbook("sourseSampleCountryNames.xlsx") | |
| # Accessing the first worksheet in the Excel file | |
| worksheet = workbook.worksheets[0] | |
| # Creating AutoFilter by giving the cells range | |
| worksheet.auto_filter.range = "A1:A18" | |
| # Initialize filter for rows containing string "Ba" | |
| worksheet.auto_filter.custom(0, FilterOperatorType.NOT_CONTAINS, "Be") | |
| # Refresh the filter to show/hide filtered rows | |
| worksheet.auto_filter.refresh() | |
| # Saving the modified Excel file | |
| workbook.save("outSourseSampleCountryNames.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import DateTimeGroupingType, Workbook | |
| # The path to the documents directory. | |
| # Source directory | |
| sourceDir = "./" | |
| # Output directory | |
| outputDir = "./" | |
| # Instantiating a Workbook object | |
| # Opening the Excel file through the file stream | |
| workbook = Workbook(sourceDir + "Date.xlsx") | |
| # Accessing the first worksheet in the Excel file | |
| worksheet = workbook.worksheets[0] | |
| # Call AddDateFilter function to apply the filter | |
| worksheet.auto_filter.add_date_filter(0, DateTimeGroupingType.MONTH, 2018, 1, 0, 0, 0, 0) | |
| # Call refresh function to update the worksheet | |
| worksheet.auto_filter.refresh() | |
| # Saving the modified Excel file | |
| workbook.save(outputDir + "FilteredDate.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import DynamicFilterType, Workbook | |
| # The path to the documents directory. | |
| # Source directory | |
| sourceDir = "./" | |
| # Output directory | |
| outputDir = "./" | |
| # Instantiating a Workbook object | |
| # Opening the Excel file through the file stream | |
| workbook = Workbook(sourceDir + "Date.xlsx") | |
| # Accessing the first worksheet in the Excel file | |
| worksheet = workbook.worksheets[0] | |
| # Call DynamicFilter function to apply the filter | |
| worksheet.auto_filter.dynamic_filter(0, DynamicFilterType.JANUARY) | |
| # Call refresh function to update the worksheet | |
| worksheet.auto_filter.refresh() | |
| # Saving the modified Excel file | |
| workbook.save(outputDir + "FilteredDynamicDate.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| # Source directory | |
| sourceDir = "./" | |
| # Output directory | |
| outputDir = "./" | |
| # Instantiating a Workbook object | |
| # Opening the Excel file through the file stream | |
| workbook = Workbook(sourceDir + "Blank.xlsx") | |
| # Accessing the first worksheet in the Excel file | |
| worksheet = workbook.worksheets[0] | |
| # Call MatchNonBlanks function to apply the filter | |
| worksheet.auto_filter.match_non_blanks(0) | |
| # Call refresh function to update the worksheet | |
| worksheet.auto_filter.refresh() | |
| # Saving the modified Excel file | |
| workbook.save(outputDir + "FilteredNonBlank.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import FilterOperatorType, Workbook | |
| # The path to the documents directory. | |
| # Source directory | |
| sourceDir = "./" | |
| # Output directory | |
| outputDir = "./" | |
| # Instantiating a Workbook object | |
| # Opening the Excel file through the file stream | |
| workbook = Workbook(sourceDir + "Number.xlsx") | |
| # Accessing the first worksheet in the Excel file | |
| worksheet = workbook.worksheets[0] | |
| # Call Custom function to apply the filter | |
| worksheet.auto_filter.custom(0, FilterOperatorType.GREATER_OR_EQUAL, 5, True, FilterOperatorType.LESS_OR_EQUAL, 10) | |
| # Call refresh function to update the worksheet | |
| worksheet.auto_filter.refresh() | |
| # Saving the modified Excel file | |
| workbook.save(outputDir + "FilteredNumber.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| # Source directory | |
| sourceDir = "./" | |
| # Output directory | |
| outputDir = "./" | |
| # Instantiating a Workbook object | |
| # Opening the Excel file through the file stream | |
| workbook = Workbook(sourceDir + "Text.xlsx") | |
| # Accessing the first worksheet in the Excel file | |
| worksheet = workbook.worksheets[0] | |
| # Call Filter function to apply the filter | |
| worksheet.auto_filter.filter(0, "Angola") | |
| # Call refresh function to update the worksheet | |
| worksheet.auto_filter.refresh() | |
| # Saving the modified Excel file | |
| workbook.save(outputDir + "FilteredText.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import CellArea, Workbook | |
| workbook = Workbook("ValidationsSample.xlsx") | |
| # Access first worksheet. | |
| worksheet = workbook.worksheets[0] | |
| # Accessing the Validations collection of the worksheet | |
| validation = worksheet.validations[0] | |
| # Create your cell area. | |
| cellArea = CellArea.create_cell_area("D5", "E7") | |
| # Adding the cell area to Validation | |
| validation.add_area(cellArea, False, False) | |
| # Save the output workbook. | |
| workbook.save("ValidationsSample_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import FilterOperatorType, Workbook | |
| # Source directory | |
| sourceDir = "./" | |
| # Output directory | |
| outputDir = "./" | |
| # Instantiating a Workbook object containing sample data | |
| workbook = Workbook(sourceDir + "sourseSampleCountryNames.xlsx") | |
| # Accessing the first worksheet in the Excel file | |
| worksheet = workbook.worksheets[0] | |
| # Creating AutoFilter by giving the cells range | |
| worksheet.auto_filter.range = "A1:A18" | |
| # Initialize filter for rows starting with string "Ba" | |
| worksheet.auto_filter.custom(0, FilterOperatorType.BEGINS_WITH, "Ba") | |
| # Refresh the filter to show/hide filtered rows | |
| worksheet.auto_filter.refresh() | |
| # Saving the modified Excel file | |
| workbook.save(outputDir + "outSourseSampleCountryNames.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Instantiating a Workbook object | |
| # Opening the Excel file through the file stream | |
| workbook = Workbook(dataDir + "book1.xls") | |
| # Accessing the first worksheet in the Excel file | |
| worksheet = workbook.worksheets[0] | |
| # Creating AutoFilter by giving the cells range of the heading row | |
| worksheet.auto_filter.range = "A1:B1" | |
| # Saving the modified Excel file | |
| workbook.save(dataDir + "output.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import FilterOperatorType, Workbook | |
| # Source directory | |
| sourceDir = "./" | |
| # Output directory | |
| outputDir = "./" | |
| # Instantiating a Workbook object containing sample data | |
| workbook = Workbook(sourceDir + "sourseSampleCountryNames.xlsx") | |
| # Accessing the first worksheet in the Excel file | |
| worksheet = workbook.worksheets[0] | |
| # Creating AutoFilter by giving the cells range | |
| worksheet.auto_filter.range = "A1:A18" | |
| # Initialize filter for rows end with string "ia" | |
| worksheet.auto_filter.custom(0, FilterOperatorType.BEGINS_WITH, "ia") | |
| # Refresh the filter to show/hide filtered rows | |
| worksheet.auto_filter.refresh() | |
| # Saving the modified Excel file | |
| workbook.save(outputDir + "outSourseSampleCountryNames.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| book = Workbook("sampleValidation.xlsx") | |
| sheet = book.worksheets.get("Sheet1") | |
| cells = sheet.cells | |
| a2 = cells.get("A2") | |
| va2 = a2.get_validation() | |
| if va2.in_cell_drop_down: | |
| print("A2 is a dropdown") | |
| else: | |
| print("A2 is NOT a dropdown") | |
| b2 = cells.get("B2") | |
| vb2 = b2.get_validation() | |
| if vb2.in_cell_drop_down: | |
| print("B2 is a dropdown") | |
| else: | |
| print("B2 is NOT a dropdown") | |
| c2 = cells.get("C2") | |
| vc2 = c2.get_validation() | |
| if vc2.in_cell_drop_down: | |
| print("C2 is a dropdown") | |
| else: | |
| print("C2 is NOT a dropdown") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Instantiate the workbook from sample Excel file | |
| workbook = Workbook("sample.xlsx") | |
| # Access the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Access Cell C1 | |
| # Cell C1 has the Decimal Validation applied on it. | |
| # It can take only the values Between 10 and 20 | |
| cell = worksheet.cells.get("C1") | |
| # Enter 3 inside this cell | |
| # Since it is not between 10 and 20, it should fail the validation | |
| cell.put_value(3) | |
| # Check if number 3 satisfies the Data Validation rule applied on this cell | |
| print("Is 3 a Valid Value for this Cell: " + str(cell.get_validation_value())) | |
| # Enter 15 inside this cell | |
| # Since it is between 10 and 20, it should succeed the validation | |
| cell.put_value(15) | |
| # Check if number 15 satisfies the Data Validation rule applied on this cell | |
| print("Is 15 a Valid Value for this Cell: " + str(cell.get_validation_value())) | |
| # Enter 30 inside this cell | |
| # Since it is not between 10 and 20, it should fail the validation again | |
| cell.put_value(30) | |
| # Check if number 30 satisfies the Data Validation rule applied on this cell | |
| print("Is 30 a Valid Value for this Cell: " + str(cell.get_validation_value())) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import CellArea, OperatorType, ValidationAlertType, ValidationType, Workbook | |
| # Create a workbook. | |
| workbook = Workbook() | |
| # Obtain the cells of the first worksheet. | |
| cells = workbook.worksheets[0].cells | |
| # Put a string value into the A1 cell. | |
| cells.get("A1").put_value("Please enter Date b/w 1/1/1970 and 12/31/1999") | |
| # Set row height and column width for the cells. | |
| cells.set_row_height(0, float(31)) | |
| cells.set_column_width(0, float(35)) | |
| # Get the validations collection. | |
| validations = workbook.worksheets[0].validations | |
| # Create Cell Area | |
| ca = CellArea() | |
| ca.start_row = 0 | |
| ca.end_row = 0 | |
| ca.start_column = 0 | |
| ca.end_column = 0 | |
| # Add a new validation. | |
| validation = validations[validations.add(ca)] | |
| # Set the data validation type. | |
| validation.type = ValidationType.DATE | |
| # Set the operator for the data validation | |
| validation.operator = OperatorType.BETWEEN | |
| # Set the value or expression associated with the data validation. | |
| validation.formula1 = "1/1/1970" | |
| # The value or expression associated with the second part of the data validation. | |
| validation.formula2 = "12/31/1999" | |
| # Enable the error. | |
| validation.show_error = True | |
| # Set the validation alert style. | |
| validation.alert_style = ValidationAlertType.STOP | |
| # Set the title of the data-validation error dialog box | |
| validation.error_title = "Date Error" | |
| # Set the data validation error message. | |
| validation.error_message = "Enter a Valid Date" | |
| # Set and enable the data validation input message. | |
| validation.input_message = "Date Validation Type" | |
| validation.ignore_blank = True | |
| validation.show_input = True | |
| # Set a collection of CellArea which contains the data validation settings. | |
| cellArea = CellArea() | |
| cellArea.start_row = 0 | |
| cellArea.end_row = 0 | |
| cellArea.start_column = 1 | |
| cellArea.end_column = 1 | |
| # Add the validation area. | |
| validation.add_area(cellArea) | |
| # Save the Excel file. | |
| workbook.save("output.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Load source Excel file | |
| workbook = Workbook("SampleBook1.ods") | |
| # Access first worksheet | |
| worksheet = workbook.worksheets[0] | |
| cell = worksheet.cells.get("A9") | |
| if cell.get_validation() != None: | |
| print(cell.get_validation().type) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Instantiate the workbook from sample Excel file | |
| workbook = Workbook("sample.xlsx") | |
| # Access its first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Cell C1 has the Decimal Validation applied on it. It can take only the values Between 10 and 20 | |
| cell = worksheet.cells.get("C1") | |
| # Access the valditation applied on this cell | |
| validation = cell.get_validation() | |
| # Read various properties of the validation | |
| print("Reading Properties of Validation") | |
| print("--------------------------------") | |
| print("Type: " + str(validation.type)) | |
| print("Operator: " + str(validation.operator)) | |
| print("Formula1: " + validation.formula1) | |
| print("Formula2: " + validation.formula2) | |
| print("Ignore blank: " + str(validation.ignore_blank)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import CellArea, OperatorType, ValidationAlertType, ValidationType, Workbook | |
| # Create a workbook object. | |
| workbook = Workbook() | |
| # Get the first worksheet. | |
| worksheet1 = workbook.worksheets[0] | |
| # Add a new worksheet and access it. | |
| i = workbook.worksheets.add() | |
| worksheet2 = workbook.worksheets[i] | |
| # Create a range in the second worksheet. | |
| range = worksheet2.cells.create_range("E1", "E4") | |
| # Name the range. | |
| range.name = "MyRange" | |
| # Fill different cells with data in the range. | |
| worksheet2.cells.get("E1").value = "Blue" | |
| worksheet2.cells.get("E2").value = "Red" | |
| worksheet2.cells.get("E3").value = "Green" | |
| worksheet2.cells.get("E4").value = "Yellow" | |
| # Get the validations collection. | |
| validations = worksheet1.validations | |
| # Create Cell Area | |
| ca = CellArea() | |
| ca.start_row = 0 | |
| ca.end_row = 0 | |
| ca.start_column = 0 | |
| ca.end_column = 0 | |
| # Create a new validation to the validations list. | |
| validation = validations[validations.add(ca)] | |
| # Set the validation type. | |
| validation.type = ValidationType.LIST | |
| # Set the operator. | |
| validation.operator = OperatorType.NONE | |
| # Set the in cell drop down. | |
| validation.in_cell_drop_down = True | |
| # Set the formula1. | |
| validation.formula1 = "=MyRange" | |
| # Enable it to show error. | |
| validation.show_error = True | |
| # Set the alert type severity level. | |
| validation.alert_style = ValidationAlertType.STOP | |
| # Set the error title. | |
| validation.error_title = "Error" | |
| # Set the error message. | |
| validation.error_message = "Please select a color from the list" | |
| # Specify the validation area. | |
| area = CellArea() | |
| area.start_row = 0 | |
| area.end_row = 4 | |
| area.start_column = 0 | |
| area.end_column = 0 | |
| # Add the validation area. | |
| validation.add_area(area) | |
| # Save the Excel file. | |
| workbook.save("output.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import CellArea, OperatorType, ValidationAlertType, ValidationType, Workbook | |
| # Create a new workbook. | |
| workbook = Workbook() | |
| # Obtain the cells of the first worksheet. | |
| cells = workbook.worksheets[0].cells | |
| # Put a string value into A1 cell. | |
| cells.get("A1").put_value("Please enter a string not more than 5 chars") | |
| # Set row height and column width for the cell. | |
| cells.set_row_height(0, float(31)) | |
| cells.set_column_width(0, float(35)) | |
| # Get the validations collection. | |
| validations = workbook.worksheets[0].validations | |
| # Create Cell Area | |
| ca = CellArea() | |
| ca.start_row = 0 | |
| ca.end_row = 0 | |
| ca.start_column = 0 | |
| ca.end_column = 0 | |
| # Add a new validation. | |
| validation = validations[validations.add(ca)] | |
| # Set the data validation type. | |
| validation.type = ValidationType.TEXT_LENGTH | |
| # Set the operator for the data validation. | |
| validation.operator = OperatorType.LESS_OR_EQUAL | |
| # Set the value or expression associated with the data validation. | |
| validation.formula1 = "5" | |
| # Enable the error. | |
| validation.show_error = True | |
| # Set the validation alert style. | |
| validation.alert_style = ValidationAlertType.WARNING | |
| # Set the title of the data-validation error dialog box. | |
| validation.error_title = "Text Length Error" | |
| # Set the data validation error message. | |
| validation.error_message = " Enter a Valid String" | |
| # Set and enable the data validation input message. | |
| validation.input_message = "TextLength Validation Type" | |
| validation.ignore_blank = True | |
| validation.show_input = True | |
| # Set a collection of CellArea which contains the data validation settings. | |
| cellArea = CellArea() | |
| cellArea.start_row = 0 | |
| cellArea.end_row = 0 | |
| cellArea.start_column = 1 | |
| cellArea.end_column = 1 | |
| # Add the validation area. | |
| validation.add_area(cellArea) | |
| # Save the Excel file. | |
| workbook.save("output.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import CellArea, OperatorType, ValidationAlertType, ValidationType, Workbook | |
| # Create a workbook. | |
| workbook = Workbook() | |
| # Obtain the cells of the first worksheet. | |
| cells = workbook.worksheets[0].cells | |
| # Put a string value into A1 cell. | |
| cells.get("A1").put_value("Please enter Time b/w 09:00 and 11:30 'o Clock") | |
| # Set the row height and column width for the cells. | |
| cells.set_row_height(0, float(31)) | |
| cells.set_column_width(0, float(35)) | |
| # Get the validations collection. | |
| validations = workbook.worksheets[0].validations | |
| # Create Cell Area | |
| ca = CellArea() | |
| ca.start_row = 0 | |
| ca.end_row = 0 | |
| ca.start_column = 0 | |
| ca.end_column = 0 | |
| # Add a new validation. | |
| validation = validations[validations.add(ca)] | |
| # Set the data validation type. | |
| validation.type = ValidationType.TIME | |
| # Set the operator for the data validation. | |
| validation.operator = OperatorType.BETWEEN | |
| # Set the value or expression associated with the data validation. | |
| validation.formula1 = "09:00" | |
| # The value or expression associated with the second part of the data validation. | |
| validation.formula2 = "11:30" | |
| # Enable the error. | |
| validation.show_error = True | |
| # Set the validation alert style. | |
| validation.alert_style = ValidationAlertType.INFORMATION | |
| # Set the title of the data-validation error dialog box. | |
| validation.error_title = "Time Error" | |
| # Set the data validation error message. | |
| validation.error_message = "Enter a Valid Time" | |
| # Set and enable the data validation input message. | |
| validation.input_message = "Time Validation Type" | |
| validation.ignore_blank = True | |
| validation.show_input = True | |
| # Set a collection of CellArea which contains the data validation settings. | |
| cellArea = CellArea() | |
| cellArea.start_row = 0 | |
| cellArea.end_row = 0 | |
| cellArea.start_column = 1 | |
| cellArea.end_column = 1 | |
| # Add the validation area. | |
| validation.add_area(cellArea) | |
| # Save the Excel file. | |
| workbook.save("output.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import CellArea, OperatorType, ValidationType, Workbook | |
| # Create a workbook object. | |
| workbook = Workbook() | |
| # Create a worksheet and get the first worksheet. | |
| ExcelWorkSheet = workbook.worksheets[0] | |
| # Accessing the Validations collection of the worksheet | |
| validations = workbook.worksheets[0].validations | |
| # Create Cell Area | |
| ca = CellArea() | |
| ca.start_row = 0 | |
| ca.end_row = 0 | |
| ca.start_column = 0 | |
| ca.end_column = 0 | |
| # Creating a Validation object | |
| validation = validations[validations.add(ca)] | |
| # Setting the validation type to whole number | |
| validation.type = ValidationType.WHOLE_NUMBER | |
| # Setting the operator for validation to Between | |
| validation.operator = OperatorType.BETWEEN | |
| # Setting the minimum value for the validation | |
| validation.formula1 = "10" | |
| # Setting the maximum value for the validation | |
| validation.formula2 = "1000" | |
| # Applying the validation to a range of cells from A1 to B2 using the | |
| # CellArea structure | |
| area = CellArea() | |
| area.start_row = 0 | |
| area.end_row = 1 | |
| area.start_column = 0 | |
| area.end_column = 1 | |
| # Adding the cell area to Validation | |
| validation.add_area(area) | |
| # Save the workbook. | |
| workbook.save("output.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import FindOptions, Workbook | |
| filePath = "TestBook.xlsx" | |
| workbook = Workbook(filePath) | |
| worksheet = workbook.worksheets[0] | |
| # Access the style of cell A1 | |
| style = worksheet.cells.get("A1").get_style() | |
| # Specify the style for searching | |
| options = FindOptions() | |
| options.style = style | |
| nextCell = None | |
| while True: | |
| # Find the cell that has a style of cell A1 | |
| nextCell = worksheet.cells.find(None, nextCell, options) | |
| if nextCell == None: | |
| break | |
| # Change the text of the cell | |
| nextCell.put_value("Found") | |
| dataDir = "output.out.xlsx" | |
| workbook.save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Create workbook | |
| wb = Workbook() | |
| # Create worksheet | |
| sheet = wb.worksheets[0] | |
| # Access cell A1 and A2 | |
| a1 = sheet.cells.get("A1") | |
| a2 = sheet.cells.get("A2") | |
| # Add sample in A1 and sample with quote prefix in A2 | |
| a1.put_value("sample") | |
| a2.put_value("'sample") | |
| # Print their string values, A1 and A2 both are same | |
| print("String value of A1: " + a1.string_value) | |
| print("String value of A2: " + a2.string_value) | |
| # Access styles of A1 and A2 | |
| s1 = a1.get_style() | |
| s2 = a2.get_style() | |
| print() | |
| # Check if A1 and A2 has a quote prefix | |
| print("A1 has a quote prefix: " + str(s1.quote_prefix)) | |
| print("A2 has a quote prefix: " + str(s2.quote_prefix)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import FindOptions, LookInType, Workbook | |
| # Source directory | |
| sourceDir = "./" | |
| # Opening the Excel file | |
| workbook = Workbook(sourceDir + "sampleFindingCellsContainingFormula.xlsx") | |
| # Accessing the first worksheet in the Excel file | |
| worksheet = workbook.worksheets[0] | |
| # Instantiate FindOptions Object | |
| findOptions = FindOptions() | |
| findOptions.look_in_type = LookInType.FORMULAS | |
| # Finding the cell containing the specified formula | |
| cell = worksheet.cells.find("=SUM(A5:A10)", None, findOptions) | |
| # Printing the name of the cell found after searching worksheet | |
| print("Name of the cell containing formula: " + cell.name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import FindOptions, LookAtType, LookInType, Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Instantiate the workbook object | |
| workbook = Workbook(dataDir + "book1.xls") | |
| # Get Cells collection | |
| cells = workbook.worksheets[0].cells | |
| opts = FindOptions() | |
| opts.look_in_type = LookInType.VALUES | |
| opts.look_at_type = LookAtType.ENTIRE_CONTENT | |
| # Find the cell with the input integer or double | |
| cell1 = cells.find(205, None, opts) | |
| if cell1 != None: | |
| print("Name of the cell containing the value: " + cell1.name) | |
| else: | |
| print("Record not found ") | |
| # Find the cell with the input string | |
| cell2 = cells.find("Items A", None, opts) | |
| if cell2 != None: | |
| print("Name of the cell containing the value: " + cell2.name) | |
| else: | |
| print("Record not found ") | |
| # Find the cell containing with the input string | |
| opts.look_at_type = LookAtType.CONTAINS | |
| cell3 = cells.find("Data", None, opts) | |
| if cell3 != None: | |
| print("Name of the cell containing the value: " + cell3.name) | |
| else: | |
| print("Record not found ") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import CellArea, FindOptions, LookAtType, LookInType, Workbook | |
| # Source directory | |
| sourceDir = "./" | |
| # Instantiate the workbook object | |
| workbook = Workbook(sourceDir + "sampleFindingDataOrFormulasUsingFindOptions.xlsx") | |
| workbook.calculate_formula() | |
| # Get Cells collection | |
| cells = workbook.worksheets[0].cells | |
| # Instantiate FindOptions Object | |
| findOptions = FindOptions() | |
| # Create a Cells Area | |
| ca = CellArea() | |
| ca.start_row = 8 | |
| ca.start_column = 2 | |
| ca.end_row = 17 | |
| ca.end_column = 13 | |
| # Set cells area for find options | |
| findOptions.set_range(ca) | |
| # Set searching properties | |
| findOptions.search_backward = False | |
| findOptions.seach_order_by_rows = True | |
| # Set the lookintype, you may specify, values, formulas, comments etc. | |
| findOptions.look_in_type = LookInType.VALUES | |
| # Set the lookattype, you may specify Match entire content, endswith, starwith etc. | |
| findOptions.look_at_type = LookAtType.ENTIRE_CONTENT | |
| # Find the cell with value | |
| cell = cells.find(341, None, findOptions) | |
| if cell != None: | |
| print("Name of the cell containing the value: " + cell.name) | |
| else: | |
| print("Record not found ") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| sourceDir = "./" | |
| # Output directory | |
| outputDir = "./" | |
| # Instantiate a Workbook object | |
| # Open an Excel file | |
| workbook = Workbook(sourceDir + "HyperlinksSample.xlsx") | |
| # Get the first (default) worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Create a range A2:B3 | |
| range = worksheet.cells.create_range("A2", "B3") | |
| # Get Hyperlinks in range | |
| hyperlinks = range.hyperlinks | |
| for link in hyperlinks: | |
| print(str(str(link.area) + " : " ) + link.address) | |
| # To delete the link, use the Hyperlink.Delete() method. | |
| link.delete() | |
| workbook.save(outputDir + "HyperlinksSample_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| workbook = Workbook() | |
| worksheet = workbook.worksheets[0] | |
| cell = worksheet.cells.get("A1") | |
| cell.html_string = "<Font Style=\"FONT-WEIGHT: bold;FONT-STYLE: italic;TEXT-DECORATION: underline;FONT-FAMILY: Arial;FONT-SIZE: 11pt;COLOR: #ff0000;\">This is simple HTML formatted text.</Font>" | |
| workbook.save(dataDir + "output_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create workbook object | |
| workbook = Workbook() | |
| # Access first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Access cell A1 | |
| cell = worksheet.cells.get("A1") | |
| # Set the HTML string | |
| cell.html_string = "<font style='font-family:Arial;font-size:10pt;color:#666666;vertical-align:top;text-align:left;'>Text 1 </font><font style='font-family:Wingdings;font-size:8.0pt;color:#009DD9;mso-font-charset:2;'>l</font><font style='font-family:Arial;font-size:10pt;color:#666666;vertical-align:top;text-align:left;'> Text 2 </font><font style='font-family:Wingdings;font-size:8.0pt;color:#009DD9;mso-font-charset:2;'>l</font><font style='font-family:Arial;font-size:10pt;color:#666666;vertical-align:top;text-align:left;'> Text 3 </font><font style='font-family:Wingdings;font-size:8.0pt;color:#009DD9;mso-font-charset:2;'>l</font><font style='font-family:Arial;font-size:10pt;color:#666666;vertical-align:top;text-align:left;'> Text 4 </font>" | |
| # Auto fit the Columns | |
| worksheet.auto_fit_columns() | |
| # Save the workbook | |
| workbook.save(dataDir + "BulletsInCells_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Instantiating an Workbook object | |
| workbook = Workbook() | |
| # Obtaining the reference of the newly added worksheet | |
| ws = workbook.worksheets[0] | |
| cells = ws.cells | |
| # Setting the value to the cells | |
| cell = cells.get("A1") | |
| cell.put_value("Fruit") | |
| cell = cells.get("B1") | |
| cell.put_value("Count") | |
| cell = cells.get("C1") | |
| cell.put_value("Price") | |
| cell = cells.get("A2") | |
| cell.put_value("Apple") | |
| cell = cells.get("A3") | |
| cell.put_value("Mango") | |
| cell = cells.get("A4") | |
| cell.put_value("Blackberry") | |
| cell = cells.get("A5") | |
| cell.put_value("Cherry") | |
| c3 = cells.get("C3") | |
| # set html string for C3 cell. | |
| c3.html_string = "<b>test bold</b>" | |
| c4 = cells.get("C4") | |
| # set html string for C4 cell. | |
| c4.html_string = "<i>test italic</i>" | |
| # get the html string of specific cell. | |
| print(c3.html_string) | |
| print(c4.html_string) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Create workbook. | |
| wb = Workbook() | |
| # Access first worksheet. | |
| ws = wb.worksheets[0] | |
| # Access cell A1 and put some text inside it. | |
| cell = ws.cells.get("A1") | |
| cell.put_value("This is some text.") | |
| # Get the Normal and Html5 strings. | |
| strNormal = cell.get_html_string(False) | |
| strHtml5 = cell.get_html_string(True) | |
| # Print the Normal and Html5 strings on console. | |
| print("Normal:\r\n" + strNormal) | |
| print() | |
| print("Html5:\r\n" + strHtml5) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import CellValueFormatStrategy, Workbook | |
| # Create workbook | |
| workbook = Workbook() | |
| # Access first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Access cell A1 | |
| cell = worksheet.cells.get("A1") | |
| # Put value inside the cell | |
| cell.put_value(0.012345) | |
| # Format the cell that it should display 0.01 instead of 0.012345 | |
| style = cell.get_style() | |
| style.number = 2 | |
| cell.set_style(style) | |
| # Get string value as Cell Style | |
| value = cell.get_string_value(CellValueFormatStrategy.CELL_STYLE) | |
| print(value) | |
| # Get string value without any formatting | |
| value = cell.get_string_value(CellValueFormatStrategy.NONE) | |
| print(value) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Workbook object | |
| workbook.worksheets.add() | |
| # Obtaining the reference of the first (default) worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Adding an internal hyperlink to the "B9" cell of the other worksheet "Sheet2" in | |
| # The same Excel file | |
| worksheet.hyperlinks.add("B3", 1, 1, "Sheet2!B9") | |
| # Saving the Excel file | |
| workbook.save(dataDir + "output.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Excel object | |
| i = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[i] | |
| # Adding an internal hyperlink to the "B9" cell of the other worksheet "Sheet2" in | |
| # The same Excel file | |
| worksheet.hyperlinks.add("A5", 1, 1, dataDir + "book1.xls") | |
| # Saving the Excel file | |
| workbook.save(dataDir + "output.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Obtaining the reference of the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Adding a hyperlink to a URL at "A1" cell | |
| worksheet.hyperlinks.add("A1", 1, 1, "http:// Www.aspose.com") | |
| # Saving the Excel file | |
| workbook.save(dataDir + "output.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Instantiating an Workbook object | |
| workbook = Workbook() | |
| # Obtaining the reference of the newly added worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Getting D8 cell | |
| d8 = worksheet.cells.get("D8") | |
| d8.embedded_image = open("aspose.png", "rb").read() | |
| workbook.save("out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create a workbook | |
| workbook = Workbook() | |
| # Populate Data into Cells | |
| cells = workbook.worksheets[0].cells | |
| cells.get("A1").put_value("data1") | |
| cells.get("B1").put_value("data2") | |
| cells.get("A2").put_value("data3") | |
| cells.get("B2").put_value("data4") | |
| # Save workbook | |
| workbook.save(dataDir + "output_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import StyleFlag, Workbook | |
| # Create workbook | |
| wb = Workbook() | |
| # Access first worksheet | |
| ws = wb.worksheets[0] | |
| # Access cell A1 | |
| cell = ws.cells.get("A1") | |
| # Put some text in cell, it does not have Single Quote at the beginning | |
| cell.put_value("Text") | |
| # Access style of cell A1 | |
| st = cell.get_style() | |
| # Print the value of Style.quote_prefix of cell A1 | |
| print("Quote Prefix of Cell A1: " + str(st.quote_prefix)) | |
| # Put some text in cell, it has Single Quote at the beginning | |
| cell.put_value("'Text") | |
| # Access style of cell A1 | |
| st = cell.get_style() | |
| # Print the value of Style.quote_prefix of cell A1 | |
| print("Quote Prefix of Cell A1: " + str(st.quote_prefix)) | |
| # Print information about StyleFlag.quote_prefix property | |
| print() | |
| print("When StyleFlag.quote_prefix is False, it means, do not update the value of Cell.Style.quote_prefix.") | |
| print("Similarly, when StyleFlag.quote_prefix is True, it means, update the value of Cell.Style.quote_prefix.") | |
| print() | |
| # Create an empty style | |
| st = wb.create_style() | |
| # Create style flag - set StyleFlag.quote_prefix as false | |
| # It means, we do not want to update the Style.quote_prefix property of cell A1's style. | |
| flag = StyleFlag() | |
| flag.quote_prefix = False | |
| # Create a range consisting of single cell A1 | |
| rng = ws.cells.create_range("A1") | |
| # Apply the style to the range | |
| rng.apply_style(st, flag) | |
| # Access the style of cell A1 | |
| st = cell.get_style() | |
| # Print the value of Style.quote_prefix of cell A1 | |
| # It will print True, because we have not updated the Style.quote_prefix property of cell A1's style. | |
| print("Quote Prefix of Cell A1: " + str(st.quote_prefix)) | |
| # Create an empty style | |
| st = wb.create_style() | |
| # Create style flag - set StyleFlag.quote_prefix as true | |
| # It means, we want to update the Style.quote_prefix property of cell A1's style. | |
| flag = StyleFlag() | |
| flag.quote_prefix = True | |
| # Apply the style to the range | |
| rng.apply_style(st, flag) | |
| # Access the style of cell A1 | |
| st = cell.get_style() | |
| # Print the value of Style.quote_prefix of cell A1 | |
| # It will print False, because we have updated the Style.quote_prefix property of cell A1's style. | |
| print("Quote Prefix of Cell A1: " + str(st.quote_prefix)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import CellValueType, Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Opening an existing workbook | |
| workbook = Workbook(dataDir + "book1.xls") | |
| # Accessing first worksheet | |
| worksheet = workbook.worksheets[0] | |
| for cell1 in worksheet.cells: | |
| # Passing the type of the data contained in the cell for evaluation | |
| if cell1.type == CellValueType.IS_STRING: | |
| stringValue = cell1.string_value | |
| print("String Value: " + stringValue) | |
| elif cell1.type == CellValueType.IS_NUMERIC: | |
| doubleValue = cell1.double_value | |
| print("Double Value: " + str(doubleValue)) | |
| elif cell1.type == CellValueType.IS_BOOL: | |
| boolValue = cell1.bool_value | |
| print("Bool Value: " + str(boolValue)) | |
| elif cell1.type == CellValueType.IS_DATE_TIME: | |
| dateTimeValue = cell1.date_time_value | |
| print("DateTime Value: " + str(dateTimeValue)) | |
| elif cell1.type == CellValueType.IS_UNKNOWN: | |
| stringValue = cell1.string_value | |
| print("Unknown Value: " + stringValue) | |
| elif cell1.type == CellValueType.IS_NULL: | |
| pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import FindOptions, LookAtType, LookInType, Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create workbook object | |
| workbook = Workbook() | |
| # Access first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Add 10 in cell A1 and A2 | |
| worksheet.cells.get("A1").put_value(10) | |
| worksheet.cells.get("A2").put_value(10) | |
| # Add Sum formula in cell D4 but customize it as --- | |
| cell = worksheet.cells.get("D4") | |
| style = cell.get_style() | |
| style.custom = "---" | |
| cell.set_style(style) | |
| # The result of formula will be 20 but 20 will not be visible because the cell is formated as --- | |
| cell.formula = "=Sum(A1:A2)" | |
| # Calculate the workbook | |
| workbook.calculate_formula() | |
| # Create find options, we will search 20 using original values otherwise 20 will never be found because it is formatted as --- | |
| options = FindOptions() | |
| options.look_in_type = LookInType.ORIGINAL_VALUES | |
| options.look_at_type = LookAtType.ENTIRE_CONTENT | |
| foundCell = None | |
| obj = 20 | |
| # Find 20 which is Sum(A1:A2) and formatted as --- | |
| foundCell = worksheet.cells.find(obj, foundCell, options) | |
| # Print the found cell | |
| print(foundCell) | |
| # Save the workbook | |
| workbook.save(dataDir + "output_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import CellArea, SortOnType, SortOrder, Workbook | |
| from aspose.pydrawing import Color | |
| # Source directory | |
| sourceDir = "./" | |
| # Output directory | |
| outputDir = "./" | |
| # Create a workbook object and load template file | |
| workbook = Workbook(sourceDir + "CellsNet46500.xlsx") | |
| # Instantiate data sorter object | |
| sorter = workbook.data_sorter | |
| # Add key for second column for red color | |
| sorter.add_key(1, SortOnType.CELL_COLOR, SortOrder.DESCENDING, Color.red) | |
| # Sort the data based on the key | |
| sorter.sort(workbook.worksheets[0].cells, CellArea.create_cell_area("A2", "C6")) | |
| # Save the output file | |
| workbook.save(outputDir + "outputSortData_CustomSortList.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import CellArea, SortOrder, Workbook | |
| # Source directory | |
| sourceDir = "./" | |
| # Output directory | |
| outputDir = "./" | |
| # Load the source Excel file | |
| wb = Workbook(sourceDir + "sampleSortData_CustomSortList.xlsx") | |
| # Access first worksheet | |
| ws = wb.worksheets[0] | |
| # Specify cell area - sort from A1 to A40 | |
| ca = CellArea.create_cell_area("A1", "A40") | |
| # Create Custom Sort list | |
| customSortList = ["USA,US", "Brazil,BR", "China,CN", "Russia,RU", "Canada,CA" ] | |
| # Add Key for Column A, Sort it in Ascending Order with Custom Sort List | |
| wb.data_sorter.add_key(0, SortOrder.ASCENDING, customSortList) | |
| wb.data_sorter.sort(ws.cells, ca) | |
| # Save the output Excel file | |
| wb.save(outputDir + "outputSortData_CustomSortList.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import CellArea, CellsHelper, SortOrder, Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create workbook. | |
| workbook = Workbook(dataDir + "sampleSortAsNumber.xlsx") | |
| # Access first worksheet. | |
| worksheet = workbook.worksheets[0] | |
| # Create your cell area. | |
| ca = CellArea.create_cell_area("A1", "A20") | |
| # Create your sorter. | |
| sorter = workbook.data_sorter | |
| # Find the index, since we want to sort by column A, so we should know the index for sorter. | |
| idx = CellsHelper.column_name_to_index("A") | |
| # Add key in sorter, it will sort in Ascending order. | |
| sorter.add_key(idx, SortOrder.ASCENDING) | |
| sorter.sort_as_number = True | |
| # Perform sort. | |
| sorter.sort(worksheet.cells, ca) | |
| # Save the output workbook. | |
| workbook.save(dataDir + "outputSortAsNumber.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| inputPath = dataDir + "Sample.xlsx" | |
| outputPath = dataDir + "Output.out.xlsx" | |
| workbook = Workbook(inputPath) | |
| worksheet = workbook.worksheets[0] | |
| cell = worksheet.cells.get("A1") | |
| print("Before updating the font settings....") | |
| fnts = cell.get_characters() | |
| for i in range(len(fnts)): | |
| print(fnts[i].font.name) | |
| # Modify the first FontSetting Font Name | |
| fnts[0].font.name = "Arial" | |
| # And update it using SetCharacters() method | |
| cell.set_characters(fnts) | |
| print() | |
| print("After updating the font settings....") | |
| fnts = cell.get_characters() | |
| for i in range(len(fnts)): | |
| print(fnts[i].font.name) | |
| # Save workbook | |
| workbook.save(outputPath) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import CellArea, FormatConditionType, Workbook | |
| from aspose.pydrawing import Color | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create workbook | |
| workbook = Workbook() | |
| # Access first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Add some data in cells | |
| worksheet.cells.get("A1").put_value("2-Color Scale") | |
| worksheet.cells.get("D1").put_value("3-Color Scale") | |
| for i in range(2, 15 + 1): | |
| worksheet.cells.get("A" + str(i)).put_value(i) | |
| worksheet.cells.get("D" + str(i)).put_value(i) | |
| # Adding 2-Color Scale Conditional Formatting | |
| ca = CellArea.create_cell_area("A2", "A15") | |
| idx = worksheet.conditional_formattings.add() | |
| fcc = worksheet.conditional_formattings[idx] | |
| fcc.add_condition(FormatConditionType.COLOR_SCALE) | |
| fcc.add_area(ca) | |
| fc = worksheet.conditional_formattings[idx][0] | |
| fc.color_scale.is_3_color_scale = False | |
| fc.color_scale.max_color = Color.light_blue | |
| fc.color_scale.min_color = Color.light_green | |
| # Adding 3-Color Scale Conditional Formatting | |
| ca = CellArea.create_cell_area("D2", "D15") | |
| idx = worksheet.conditional_formattings.add() | |
| fcc = worksheet.conditional_formattings[idx] | |
| fcc.add_condition(FormatConditionType.COLOR_SCALE) | |
| fcc.add_area(ca) | |
| fc = worksheet.conditional_formattings[idx][0] | |
| fc.color_scale.is_3_color_scale = True | |
| fc.color_scale.max_color = Color.light_blue | |
| fc.color_scale.mid_color = Color.yellow | |
| fc.color_scale.min_color = Color.light_green | |
| # Save the workbook | |
| workbook.save(dataDir + "output_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import CellArea, FormatConditionType, OperatorType, SaveFormat, Workbook | |
| from aspose.pydrawing import Color | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| sheet = workbook.worksheets[0] | |
| # Adds an empty conditional formatting | |
| index = sheet.conditional_formattings.add() | |
| fcs = sheet.conditional_formattings[index] | |
| # Sets the conditional format range. | |
| ca = CellArea() | |
| ca.start_row = 0 | |
| ca.end_row = 0 | |
| ca.start_column = 0 | |
| ca.end_column = 0 | |
| fcs.add_area(ca) | |
| # Adds condition. | |
| conditionIndex = fcs.add_condition(FormatConditionType.CELL_VALUE, OperatorType.BETWEEN, "50", "100") | |
| # Sets the background color. | |
| fc = fcs[conditionIndex] | |
| fc.style.background_color = Color.red | |
| # Saving the Excel file | |
| workbook.save(dataDir + "output.out.xls", SaveFormat.AUTO) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import CellArea, FormatConditionType, SaveFormat, Workbook | |
| from aspose.pydrawing import Color | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| sheet = workbook.worksheets[0] | |
| # Adds an empty conditional formatting | |
| index = sheet.conditional_formattings.add() | |
| fcs = sheet.conditional_formattings[index] | |
| # Sets the conditional format range. | |
| ca = CellArea() | |
| ca = CellArea() | |
| ca.start_row = 2 | |
| ca.end_row = 2 | |
| ca.start_column = 1 | |
| ca.end_column = 1 | |
| fcs.add_area(ca) | |
| # Adds condition. | |
| conditionIndex = fcs.add_condition(FormatConditionType.EXPRESSION) | |
| # Sets the background color. | |
| fc = fcs[conditionIndex] | |
| fc.formula1 = "=IF(SUM(B1:B2)>100,TRUE,FALSE)" | |
| fc.style.background_color = Color.red | |
| sheet.cells.get("B3").formula = "=SUM(B1:B2)" | |
| sheet.cells.get("C4").put_value("If Sum of B1:B2 is greater than 100, B3 will have RED background") | |
| # Saving the Excel file | |
| workbook.save(dataDir + "output.out.xls", SaveFormat.AUTO) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import TextAlignmentType, Workbook | |
| from aspose.cells.drawing import GradientStyleType | |
| from aspose.pydrawing import Color | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Instantiate a new Workbook | |
| workbook = Workbook() | |
| # Get the first worksheet (default) in the workbook | |
| worksheet = workbook.worksheets[0] | |
| # Input a value into B3 cell | |
| worksheet.cells.get(2, 1).put_value("test") | |
| # Get the Style of the cell | |
| style = worksheet.cells.get("B3").get_style() | |
| # Set Gradient pattern on | |
| style.is_gradient = True | |
| # Specify two color gradient fill effects | |
| style.set_two_color_gradient(Color.from_argb(255, 255, 255), Color.from_argb(79, 129, 189), GradientStyleType.HORIZONTAL, 1) | |
| # Set the color of the text in the cell | |
| style.font.color = Color.red | |
| # Specify horizontal and vertical alignment settings | |
| style.horizontal_alignment = TextAlignmentType.CENTER | |
| style.vertical_alignment = TextAlignmentType.CENTER | |
| # Apply the style to the cell | |
| worksheet.cells.get("B3").set_style(style) | |
| # Set the third row height in pixels | |
| worksheet.cells.set_row_height_pixel(2, 53) | |
| # Merge the range of cells (B3:C3) | |
| worksheet.cells.merge(2, 1, 1, 2) | |
| # Save the Excel file | |
| workbook.save(dataDir + "output.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import BackgroundType, CellArea, FormatConditionType, Workbook | |
| from aspose.pydrawing import Color | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create an instance of Workbook or load existing | |
| book = Workbook() | |
| # Access the Worksheet on which desired rule has to be applied | |
| sheet = book.worksheets[0] | |
| # Add FormatConditions to the instance of Worksheet | |
| idx = sheet.conditional_formattings.add() | |
| # Access the newly added FormatConditions via its index | |
| conditionCollection = sheet.conditional_formattings[idx] | |
| # Define a CellsArea on which conditional formatting will be applicable | |
| # The code creates a CellArea ranging from A1 to I20 | |
| area = CellArea.create_cell_area("A1", "I20") | |
| # Add area to the instance of FormatConditions | |
| conditionCollection.add_area(area) | |
| # Add a condition to the instance of FormatConditions | |
| # For this case, the condition type is expression, which is based on some formula | |
| idx = conditionCollection.add_condition(FormatConditionType.EXPRESSION) | |
| # Access the newly added FormatCondition via its index | |
| formatCondirion = conditionCollection[idx] | |
| # Set the formula for the FormatCondition | |
| # Formula uses the Excel's built-in functions as discussed earlier in this article | |
| formatCondirion.formula1 = r"=MOD(ROW(),2)=0" | |
| # Set the background color and patter for the FormatCondition's Style | |
| formatCondirion.style.background_color = Color.blue | |
| formatCondirion.style.pattern = BackgroundType.SOLID | |
| # Save the result on disk | |
| book.save(dataDir + "output_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiate a new Workbook. | |
| workbook = Workbook() | |
| # Create a style object . | |
| style = workbook.create_style() | |
| # Input a value to A1 cell. | |
| workbook.worksheets[0].cells.get("A1").put_value("Test") | |
| # Apply the style to the cell. | |
| workbook.worksheets[0].cells.get("A1").set_style(style) | |
| # Save the Excel 2007 file. | |
| workbook.save(dataDir + "book1.out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import BorderType, CellBorderType, TextAlignmentType, Workbook | |
| from aspose.pydrawing import Color | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Obtaining the reference of the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Accessing the "A1" cell from the worksheet | |
| cell = worksheet.cells.get("A1") | |
| # Adding some value to the "A1" cell | |
| cell.put_value("Hello Aspose!") | |
| # Get the style from A1 cell | |
| style = cell.get_style() | |
| # Setting the vertical alignment | |
| style.vertical_alignment = TextAlignmentType.CENTER | |
| # Setting the horizontal alignment | |
| style.horizontal_alignment = TextAlignmentType.CENTER | |
| # Setting the font color of the text | |
| style.font.color = Color.green | |
| # Setting to shrink according to the text contained in it | |
| style.shrink_to_fit = True | |
| # Setting the bottom border color to red | |
| style.borders.get(BorderType.BOTTOM_BORDER).color = Color.red | |
| # Setting the bottom border type to medium | |
| style.borders.get(BorderType.BOTTOM_BORDER).line_style = CellBorderType.MEDIUM | |
| # Applying the style to A1 cell | |
| cell.set_style(style) | |
| # Saving the Excel file | |
| workbook.save(dataDir + "book1.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import BorderType, CellBorderType, TextAlignmentType, Workbook | |
| from aspose.pydrawing import Color | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Excel object | |
| i = workbook.worksheets.add() | |
| # Obtaining the reference of the first worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[i] | |
| # Accessing the "A1" cell from the worksheet | |
| cell = worksheet.cells.get("A1") | |
| # Adding some value to the "A1" cell | |
| cell.put_value("Hello Aspose!") | |
| # Adding a new Style | |
| style = workbook.create_style() | |
| # Setting the vertical alignment of the text in the "A1" cell | |
| style.vertical_alignment = TextAlignmentType.CENTER | |
| # Setting the horizontal alignment of the text in the "A1" cell | |
| style.horizontal_alignment = TextAlignmentType.CENTER | |
| # Setting the font color of the text in the "A1" cell | |
| style.font.color = Color.green | |
| # Shrinking the text to fit in the cell | |
| style.shrink_to_fit = True | |
| # Setting the bottom border color of the cell to red | |
| style.borders.get(BorderType.BOTTOM_BORDER).color = Color.red | |
| # Setting the bottom border type of the cell to medium | |
| style.borders.get(BorderType.BOTTOM_BORDER).line_style = CellBorderType.MEDIUM | |
| # Assigning the Style object to the "A1" cell | |
| cell.set_style(style) | |
| # Apply the same style to some other cells | |
| worksheet.cells.get("B1").set_style(style) | |
| worksheet.cells.get("C1").set_style(style) | |
| worksheet.cells.get("D1").set_style(style) | |
| # Saving the Excel file | |
| workbook.save(dataDir + "book1.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import BorderType, CellBorderType, Workbook | |
| from aspose.pydrawing import Color | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Obtaining the reference of the first (default) worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[0] | |
| # Accessing the "A1" cell from the worksheet | |
| cell = worksheet.cells.get("A1") | |
| # Adding some value to the "A1" cell | |
| cell.put_value("Visit Aspose!") | |
| # Create a style object | |
| style = cell.get_style() | |
| # Setting the line style of the top border | |
| style.borders.get(BorderType.TOP_BORDER).line_style = CellBorderType.THICK | |
| # Setting the color of the top border | |
| style.borders.get(BorderType.TOP_BORDER).color = Color.black | |
| # Setting the line style of the bottom border | |
| style.borders.get(BorderType.BOTTOM_BORDER).line_style = CellBorderType.THICK | |
| # Setting the color of the bottom border | |
| style.borders.get(BorderType.BOTTOM_BORDER).color = Color.black | |
| # Setting the line style of the left border | |
| style.borders.get(BorderType.LEFT_BORDER).line_style = CellBorderType.THICK | |
| # Setting the color of the left border | |
| style.borders.get(BorderType.LEFT_BORDER).color = Color.black | |
| # Setting the line style of the right border | |
| style.borders.get(BorderType.RIGHT_BORDER).line_style = CellBorderType.THICK | |
| # Setting the color of the right border | |
| style.borders.get(BorderType.RIGHT_BORDER).color = Color.black | |
| # Apply the border styles to the cell | |
| cell.set_style(style) | |
| # Saving the Excel file | |
| workbook.save(dataDir + "book1.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import BorderType, CellBorderType, Workbook | |
| from aspose.pydrawing import Color | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Obtaining the reference of the first (default) worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[0] | |
| # Accessing the "A1" cell from the worksheet | |
| cell = worksheet.cells.get("A1") | |
| # Adding some value to the "A1" cell | |
| cell.put_value("Hello World From Aspose") | |
| # Creating a range of cells starting from "A1" cell to 3rd column in a row | |
| range = worksheet.cells.create_range(0, 0, 1, 3) | |
| # Adding a thick top border with blue line | |
| range.set_outline_border(BorderType.TOP_BORDER, CellBorderType.THICK, Color.blue) | |
| # Adding a thick bottom border with blue line | |
| range.set_outline_border(BorderType.BOTTOM_BORDER, CellBorderType.THICK, Color.blue) | |
| # Adding a thick left border with blue line | |
| range.set_outline_border(BorderType.LEFT_BORDER, CellBorderType.THICK, Color.blue) | |
| # Adding a thick right border with blue line | |
| range.set_outline_border(BorderType.RIGHT_BORDER, CellBorderType.THICK, Color.blue) | |
| # Saving the Excel file | |
| workbook.save(dataDir + "book1.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import StyleFlag, Workbook | |
| from aspose.pydrawing import Color | |
| # Create the workbook | |
| workbook = Workbook() | |
| # Get the first worksheet | |
| ws = workbook.worksheets[0] | |
| cells = ws.cells | |
| # Setting the value to the cells | |
| cell = cells.get("A1") | |
| cell.put_value("Fruit") | |
| cell = cells.get("B1") | |
| cell.put_value("Count") | |
| cell = cells.get("C1") | |
| cell.put_value("Price") | |
| cell = cells.get("A2") | |
| cell.put_value("Apple") | |
| cell = cells.get("A3") | |
| cell.put_value("Mango") | |
| cell = cells.get("A4") | |
| cell.put_value("Blackberry") | |
| cell = cells.get("A5") | |
| cell.put_value("Cherry") | |
| cell = cells.get("B2") | |
| cell.put_value(5) | |
| cell = cells.get("B3") | |
| cell.put_value(3) | |
| cell = cells.get("B4") | |
| cell.put_value(6) | |
| cell = cells.get("B5") | |
| cell.put_value(4) | |
| cell = cells.get("C2") | |
| cell.put_value(5) | |
| cell = cells.get("C3") | |
| cell.put_value(20) | |
| cell = cells.get("C4") | |
| cell.put_value(30) | |
| cell = cells.get("C5") | |
| cell.put_value(60) | |
| # Access the worksheet | |
| worksheet = workbook.worksheets[0] | |
| a2 = worksheet.cells.get("A2") | |
| # Get style of A2 | |
| style = a2.get_style() | |
| # Change the format | |
| style.font.color = Color.red | |
| style.font.is_bold = True | |
| flag = StyleFlag() | |
| flag.font_color = True | |
| a2.set_style(style, flag) | |
| b3 = worksheet.cells.get("B3") | |
| # Get style of B3 | |
| style2 = b3.get_style() | |
| # Change the format | |
| style2.font.color = Color.blue | |
| style2.font.is_italic = True | |
| b3.set_style(style2) | |
| # Save the modified workbook | |
| workbook.save("output.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Instantiating an Workbook object | |
| workbook = Workbook() | |
| # Obtaining the reference of the newly added worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Row index of the cell | |
| row = 0 | |
| # Column index of the cell | |
| column = 0 | |
| a1 = worksheet.cells.get(row, column) | |
| a1.put_value("a1 rotate text") | |
| a1Style = a1.get_style() | |
| # Set the rotation angle in degrees | |
| a1Style.rotation_angle = 45 | |
| a1.set_style(a1Style) | |
| # set Column index of the cell | |
| column = 1 | |
| b1 = worksheet.cells.get(row, column) | |
| b1.put_value("b1 rotate text") | |
| b1Style = b1.get_style() | |
| # Set the rotation angle in degrees | |
| b1Style.rotation_angle = 255 | |
| b1.set_style(b1Style) | |
| # set Column index of the cell | |
| column = 2 | |
| c1 = worksheet.cells.get(row, column) | |
| c1.put_value("c1 rotate text") | |
| c1Style = c1.get_style() | |
| # Set the rotation angle in degrees | |
| c1Style.rotation_angle = -90 | |
| c1.set_style(c1Style) | |
| # set Column index of the cell | |
| column = 3 | |
| d1 = worksheet.cells.get(row, column) | |
| d1.put_value("d1 rotate text") | |
| d1Style = d1.get_style() | |
| # Set the rotation angle in degrees | |
| d1Style.rotation_angle = -90 | |
| d1.set_style(d1Style) | |
| workbook.save("out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import SaveFormat, StyleFlag, TextAlignmentType, Workbook | |
| # Source directory | |
| sourceDir = "./" | |
| # Output directory | |
| outputDir = "./" | |
| # Load sample Excel file containing cells with formatting. | |
| wb = Workbook(sourceDir + "sampleChangeCellsAlignmentAndKeepExistingFormatting.xlsx") | |
| # Access first worksheet. | |
| ws = wb.worksheets[0] | |
| # Create cells range. | |
| rng = ws.cells.create_range("B2:D7") | |
| # Create style object. | |
| st = wb.create_style() | |
| # Set the horizontal and vertical alignment to center. | |
| st.horizontal_alignment = TextAlignmentType.CENTER | |
| st.vertical_alignment = TextAlignmentType.CENTER | |
| # Create style flag object. | |
| flag = StyleFlag() | |
| # Set style flag alignments true. It is most crucial statement. | |
| # Because if it will be false, no changes will take place. | |
| flag.alignments = True | |
| # Apply style to range of cells. | |
| rng.apply_style(st, flag) | |
| # Save the workbook in XLSX format. | |
| wb.save(outputDir + "outputChangeCellsAlignmentAndKeepExistingFormatting.xlsx", SaveFormat.XLSX) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import TextDirectionType, Workbook | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Obtaining the reference of first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Accessing the "A1" cell from the worksheet | |
| cell = worksheet.cells.get("A1") | |
| # Adding some value to the "A1" cell | |
| cell.put_value("I am using the latest version of Aspose.Cells to test this functionality.") | |
| # Gets style in the "A1" cell | |
| style = cell.get_style() | |
| # Shrinking the text to fit according to the dimensions of the cell | |
| style.text_direction = TextDirectionType.LEFT_TO_RIGHT | |
| cell.set_style(style) | |
| # Saving the Excel file | |
| workbook.save("book1.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Create an instance of Workbook class | |
| book = Workbook() | |
| # Setting this property to true will make Aspose.Cells to throw exception | |
| # when invalid custom number format is assigned to Style.Custom property | |
| book.settings.check_custom_number_format = True | |
| # Access first worksheet | |
| sheet = book.worksheets[0] | |
| # Access cell A1 and put some number to it | |
| cell = sheet.cells.get("A1") | |
| cell.put_value(2347) | |
| # Access cell's style and set its Style.Custom property | |
| style = cell.get_style() | |
| # This line will throw exception if Workbook.Settings.CheckCustomNumberFormat is set to true | |
| style.custom = "ggg @ fff" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import BackgroundType, SaveFormat, Workbook | |
| from aspose.pydrawing import Color | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Workbook object | |
| i = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[i] | |
| # Define a Style and get the A1 cell style | |
| style = worksheet.cells.get("A1").get_style() | |
| # Setting the foreground color to yellow | |
| style.foreground_color = Color.yellow | |
| # Setting the background pattern to vertical stripe | |
| style.pattern = BackgroundType.VERTICAL_STRIPE | |
| # Apply the style to A1 cell | |
| worksheet.cells.get("A1").set_style(style) | |
| # Get the A2 cell style | |
| style = worksheet.cells.get("A2").get_style() | |
| # Setting the foreground color to blue | |
| style.foreground_color = Color.blue | |
| # Setting the background color to yellow | |
| style.background_color = Color.yellow | |
| # Setting the background pattern to vertical stripe | |
| style.pattern = BackgroundType.VERTICAL_STRIPE | |
| # Apply the style to A2 cell | |
| worksheet.cells.get("A2").set_style(style) | |
| # Saving the Excel file | |
| workbook.save(dataDir + "book1.out.xls", SaveFormat.EXCEL_97_TO_2003) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import SaveFormat, Workbook | |
| from aspose.pydrawing import Color | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating an Workbook object | |
| workbook = Workbook() | |
| # Adding Orchid color to the palette at 55th index | |
| workbook.change_palette(Color.orchid, 55) | |
| # Adding a new worksheet to the Excel object | |
| i = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[i] | |
| # Accessing the "A1" cell from the worksheet | |
| cell = worksheet.cells.get("A1") | |
| # Adding some value to the "A1" cell | |
| cell.put_value("Hello Aspose!") | |
| # Defining new Style object | |
| styleObject = workbook.create_style() | |
| # Setting the Orchid (custom) color to the font | |
| styleObject.font.color = Color.orchid | |
| # Applying the style to the cell | |
| cell.set_style(styleObject) | |
| # Saving the Excel file | |
| workbook.save(dataDir + "book1.out.xls", SaveFormat.AUTO) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Instantiate a workbook object | |
| # Open the template file | |
| workbook = Workbook(dataDir + "Book1.xlsx") | |
| # Get the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Get the A1 cell | |
| a1 = worksheet.cells.get("A1") | |
| # Get the conditional formatting resultant object | |
| cfr1 = a1.get_conditional_formatting_result() | |
| # Get the ColorScale resultant color object | |
| c = cfr1.color_scale_result | |
| # Read the color | |
| print(str(c.to_argb())) | |
| print(c.name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import CellArea, FormatConditionType, OperatorType, Workbook | |
| from aspose.pydrawing import Color | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| filePath = dataDir + "Book1.xlsx" | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| sheet = workbook.worksheets[0] | |
| # Adds an empty conditional formatting | |
| index = sheet.conditional_formattings.add() | |
| fcs = sheet.conditional_formattings[index] | |
| # Sets the conditional format range. | |
| ca = CellArea() | |
| ca.start_row = 0 | |
| ca.end_row = 0 | |
| ca.start_column = 0 | |
| ca.end_column = 0 | |
| fcs.add_area(ca) | |
| ca = CellArea() | |
| ca.start_row = 1 | |
| ca.end_row = 1 | |
| ca.start_column = 1 | |
| ca.end_column = 1 | |
| fcs.add_area(ca) | |
| # Adds condition. | |
| conditionIndex = fcs.add_condition(FormatConditionType.CELL_VALUE, OperatorType.BETWEEN, "=A2", "100") | |
| # Adds condition. | |
| conditionIndex2 = fcs.add_condition(FormatConditionType.CELL_VALUE, OperatorType.BETWEEN, "50", "100") | |
| # Sets the background color. | |
| fc = fcs[conditionIndex] | |
| fc.style.background_color = Color.red | |
| # Saving the Excel file | |
| workbook.save(dataDir + "output.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import SaveFormat, Workbook | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Obtaining the reference of the worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Accessing the "A1" cell from the worksheet | |
| cell = worksheet.cells.get("A1") | |
| # Adding some value to the "A1" cell | |
| cell.put_value("Visit Aspose!") | |
| # Setting the horizontal alignment of the text in the "A1" cell | |
| style = cell.get_style() | |
| # Setting the indentation level of the text (inside the cell) to 2 | |
| style.indent_level = 2 | |
| cell.set_style(style) | |
| # Saving the Excel file | |
| workbook.save(dataDir + "book1.out.xls", SaveFormat.EXCEL_97_TO_2003) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import SaveFormat, Workbook | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Obtaining the reference of the worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Accessing the "A1" cell from the worksheet | |
| cell = worksheet.cells.get("A1") | |
| # Adding some value to the "A1" cell | |
| cell.put_value("Visit Aspose!") | |
| # Setting the horizontal alignment of the text in the "A1" cell | |
| style = cell.get_style() | |
| # Setting the rotation of the text (inside the cell) to 25 | |
| style.rotation_angle = 25 | |
| cell.set_style(style) | |
| # Saving the Excel file | |
| workbook.save(dataDir + "book1.out.xls", SaveFormat.EXCEL_97_TO_2003) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import SaveFormat, Workbook | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Obtaining the reference of the worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Accessing the "A1" cell from the worksheet | |
| cell = worksheet.cells.get("A1") | |
| # Adding some value to the "A1" cell | |
| cell.put_value("Visit Aspose!") | |
| # Setting the horizontal alignment of the text in the "A1" cell | |
| style = cell.get_style() | |
| # Shrinking the text to fit according to the dimensions of the cell | |
| style.shrink_to_fit = True | |
| cell.set_style(style) | |
| # Saving the Excel file | |
| workbook.save(dataDir + "book1.out.xls", SaveFormat.EXCEL_97_TO_2003) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import SaveFormat, TextAlignmentType, Workbook | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Obtaining the reference of the worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Accessing the "A1" cell from the worksheet | |
| cell = worksheet.cells.get("A1") | |
| # Adding some value to the "A1" cell | |
| cell.put_value("Visit Aspose!") | |
| # Setting the horizontal alignment of the text in the "A1" cell | |
| style = cell.get_style() | |
| style.horizontal_alignment = TextAlignmentType.CENTER | |
| cell.set_style(style) | |
| # Saving the Excel file | |
| workbook.save(dataDir + "book1.out.xls", SaveFormat.EXCEL_97_TO_2003) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import SaveFormat, TextAlignmentType, Workbook | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Clearing all the worksheets | |
| workbook.worksheets.clear() | |
| # Adding a new worksheet to the Excel object | |
| i = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[i] | |
| # Accessing the "A1" cell from the worksheet | |
| cell = worksheet.cells.get("A1") | |
| # Adding some value to the "A1" cell | |
| cell.put_value("Visit Aspose!") | |
| # Setting the horizontal alignment of the text in the "A1" cell | |
| style = cell.get_style() | |
| # Setting the vertical alignment of the text in a cell | |
| style.vertical_alignment = TextAlignmentType.CENTER | |
| cell.set_style(style) | |
| # Saving the Excel file | |
| workbook.save(dataDir + "book1.out.xls", SaveFormat.EXCEL_97_TO_2003) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| workbook = Workbook() | |
| # Specify custom separators | |
| workbook.settings.number_decimal_separator = '.' | |
| workbook.settings.number_group_separator = ' ' | |
| worksheet = workbook.worksheets[0] | |
| # Set cell value | |
| cell = worksheet.cells.get("A1") | |
| cell.put_value(123456.789) | |
| # Set custom cell style | |
| style = cell.get_style() | |
| style.custom = "#,##0.000;[Red]#,##0.000" | |
| cell.set_style(style) | |
| worksheet.auto_fit_columns() | |
| # Save workbook as pdf | |
| workbook.save(dataDir + "CustomSeparator_out.pdf") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook,License,PdfSaveOptions, LoadOptions, LoadFormat, LoadFilter, LoadDataFilterOptions, PasteOptions,PasteType | |
| from aspose.pydrawing import Color | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Instantiate Workbook object. | |
| # Open an exiting excel file. | |
| workbook = Workbook(dataDir + "book1.xlsx") | |
| # Define Color array (of 12 colors) for Theme. | |
| colors = [] | |
| colors.append(Color.from_argb(255, 250, 235, 215)) # Background1 | |
| colors.append(Color.from_argb(255, 165, 42, 42)) # Text1 | |
| colors.append(Color.from_argb(255, 240, 248, 255)) # Background2 | |
| colors.append(Color.from_argb(255, 255, 255, 0)) # Text2 | |
| colors.append(Color.from_argb(255, 154, 205, 50)) # Accent1 | |
| colors.append(Color.from_argb(255, 255, 0, 0)) # Accent2 | |
| colors.append(Color.from_argb(255, 255, 192, 203)) # Accent3 | |
| colors.append(Color.from_argb(255, 128, 0, 128)) # Accent4 | |
| colors.append(Color.from_argb(255, 152, 251, 152)) # Accent5 | |
| colors.append(Color.from_argb(255, 255, 165, 0)) # Accent6 | |
| colors.append(Color.from_argb(255, 0, 128, 0)) # Hyperlink | |
| colors.append(Color.from_argb(255, 128, 128, 128)) # Followed Hyperlink | |
| # Set the custom theme with specified colors. | |
| workbook.custom_theme("CustomeTheme1", colors) | |
| # Save as the excel file. | |
| workbook.save(dataDir + "output.out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose import pycore | |
| from aspose.cells import CellArea, Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Instantiate a new Workbook | |
| # Open an existing excel file | |
| wkBook = Workbook(dataDir + "SampleInput.xlsx") | |
| # Get a worksheet in the workbook | |
| wkSheet = wkBook.worksheets.get("Sheet2") | |
| # Clear its contents | |
| wkSheet.cells.clear() | |
| # Create an arraylist object | |
| al = [] | |
| # Get the merged cells list to put it into the arraylist object | |
| al = wkSheet.cells.merged_cells | |
| # Loop through the arraylist and get each cellarea | |
| # To unmerge it | |
| for i in range(len(al)): | |
| ca = CellArea() | |
| ca = pycore.cast(CellArea, al[i]) | |
| frow = ca.start_row | |
| fcol = ca.start_column | |
| erow = ca.end_row | |
| ecol = ca.end_column | |
| trows = erow - frow + 1 | |
| tcols = ecol - fcol + 1 | |
| wkSheet.cells.un_merge(frow, fcol, trows, tcols) | |
| dataDir = dataDir + "MergeTrial.out.xlsx" | |
| # Save the excel file | |
| wkBook.save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import BorderType, Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create workbook object | |
| workbook = Workbook(dataDir + "source.xlsx") | |
| # Extract theme name applied to this workbook | |
| print(workbook.theme) | |
| # Access first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Access cell A1 | |
| cell = worksheet.cells.get("A1") | |
| # Get the style object | |
| style = cell.get_style() | |
| if style.foreground_theme_color != None: | |
| # Extract theme color applied to this cell if theme has foregroundtheme color defined | |
| print(style.foreground_theme_color.color_type) | |
| else: | |
| print("Theme has not foreground color defined.") | |
| # Extract theme color applied to the bottom border of the cell if theme has border color defined | |
| bot = style.borders.get(BorderType.BOTTOM_BORDER) | |
| if bot.theme_color != None: | |
| print(bot.theme_color.color_type) | |
| else: | |
| print("Theme has not Border color defined.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Create a new Workbook or load an existing one | |
| workbook = Workbook() | |
| # Access the first worksheet in the workbook | |
| worksheet = workbook.worksheets[0] | |
| # Access a specific cell, for example, cell A1 | |
| cell = worksheet.cells.get("A1") | |
| # Put some numeric value in the cell | |
| cell.put_value(1234.56) | |
| # Get the style of the cell | |
| style = cell.get_style() | |
| # Set the number format to accounting. | |
| # The format code "_(\$* #,##0.00_);_(\$* (#,##0.00);_(\$* \"-\"??_);_(@_)" is an example for US currency. | |
| # You might need to adjust the format code according to your specific requirements and locale. | |
| style.custom = "_(\\$* #,##0.00_);_(\\$* (#,##0.00);_(\\$* \"-\"??_);_(@_)" | |
| # Apply the style to the cell | |
| cell.set_style(style) | |
| # Save the workbook | |
| workbook.save("FormattedWorkbook.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Create a new workbook | |
| workbook = Workbook() | |
| # Get the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Access the cell you want to format | |
| cell = worksheet.cells.get("A1") | |
| # Set the cell value | |
| cell.put_value(0.5) | |
| # Get the style of the cell | |
| style = cell.get_style() | |
| # Set the number format to fraction (e.g., "# ?/?") | |
| style.custom = "# ?/?" | |
| # Apply the style to the cell | |
| cell.set_style(style) | |
| # Save the workbook | |
| workbook.save("output.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Create a new workbook | |
| workbook = Workbook() | |
| # Access the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Access a specific cell, for example, cell "A1" | |
| cell = worksheet.cells.get("A1") | |
| # Set the cell value | |
| cell.put_value(0.25) | |
| # Get the cell's style | |
| style = cell.get_style() | |
| # Set the number format to percentage | |
| style.number = 9 | |
| # Apply the style to the cell | |
| cell.set_style(style) | |
| # Save the workbook to a file | |
| workbook.save("output.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Create a new workbook | |
| workbook = Workbook() | |
| # Access the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Access the cell you want to format, for example, cell "A1" | |
| cell = worksheet.cells.get("A1") | |
| # Set the value of the cell | |
| cell.put_value(12345.6789) | |
| # Get the cell's style | |
| style = cell.get_style() | |
| # Set the custom format of the cell to scientific notation | |
| style.custom = "0.00E+00" | |
| # Apply the style to the cell | |
| cell.set_style(style) | |
| # Save the workbook to a file | |
| workbook.save("output.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Create a new workbook | |
| workbook = Workbook() | |
| # Access the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Access the cell at the first row and first column (A1) | |
| cell = worksheet.cells.get("A1") | |
| # Set the value of the cell | |
| cell.put_value(1234567890) | |
| # Get the style of the cell | |
| style = cell.get_style() | |
| # Set the custom number format | |
| # For example, format as a phone number | |
| style.custom = "(###) ###-####" | |
| # Apply the style to the cell | |
| cell.set_style(style) | |
| # Save the workbook | |
| workbook.save("output.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Create a new workbook | |
| workbook = Workbook() | |
| # Access the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Access the cell you want to format (e.g., "A1") | |
| cell = worksheet.cells.get("A1") | |
| # Put a numeric value representing time in the cell | |
| # For example, 0.5 represents 12 hours (half a day) | |
| cell.put_value(0.5) | |
| # Get the style of the cell | |
| style = cell.get_style() | |
| # Set the custom number format for time (HH:MM) | |
| style.custom = "HH:MM" | |
| # Apply the style to the cell | |
| cell.set_style(style) | |
| workbook.save("output.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import BorderType, CellBorderType, StyleFlag, TextAlignmentType, Workbook | |
| from aspose.pydrawing import Color | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Obtaining the reference of the first (default) worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[0] | |
| # Adding a new Style to the styles | |
| style = workbook.create_style() | |
| # Setting the vertical alignment of the text in the "A1" cell | |
| style.vertical_alignment = TextAlignmentType.CENTER | |
| # Setting the horizontal alignment of the text in the "A1" cell | |
| style.horizontal_alignment = TextAlignmentType.CENTER | |
| # Setting the font color of the text in the "A1" cell | |
| style.font.color = Color.green | |
| # Shrinking the text to fit in the cell | |
| style.shrink_to_fit = True | |
| # Setting the bottom border color of the cell to red | |
| style.borders.get(BorderType.BOTTOM_BORDER).color = Color.red | |
| # Setting the bottom border type of the cell to medium | |
| style.borders.get(BorderType.BOTTOM_BORDER).line_style = CellBorderType.MEDIUM | |
| # Creating StyleFlag | |
| styleFlag = StyleFlag() | |
| styleFlag.horizontal_alignment = True | |
| styleFlag.vertical_alignment = True | |
| styleFlag.shrink_to_fit = True | |
| styleFlag.borders = True | |
| styleFlag.font_color = True | |
| # Accessing a column from the Columns collection | |
| column = worksheet.cells.columns[0] | |
| # Applying the style to the column | |
| column.apply_style(style, styleFlag) | |
| # Saving the Excel file | |
| workbook.save(dataDir + "book1.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import BorderType, CellBorderType, StyleFlag, TextAlignmentType, Workbook | |
| from aspose.pydrawing import Color | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Obtaining the reference of the first (default) worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[0] | |
| # Adding a new Style to the styles | |
| style = workbook.create_style() | |
| # Setting the vertical alignment of the text in the "A1" cell | |
| style.vertical_alignment = TextAlignmentType.CENTER | |
| # Setting the horizontal alignment of the text in the "A1" cell | |
| style.horizontal_alignment = TextAlignmentType.CENTER | |
| # Setting the font color of the text in the "A1" cell | |
| style.font.color = Color.green | |
| # Shrinking the text to fit in the cell | |
| style.shrink_to_fit = True | |
| # Setting the bottom border color of the cell to red | |
| style.borders.get(BorderType.BOTTOM_BORDER).color = Color.red | |
| # Setting the bottom border type of the cell to medium | |
| style.borders.get(BorderType.BOTTOM_BORDER).line_style = CellBorderType.MEDIUM | |
| # Creating StyleFlag | |
| styleFlag = StyleFlag() | |
| styleFlag.horizontal_alignment = True | |
| styleFlag.vertical_alignment = True | |
| styleFlag.shrink_to_fit = True | |
| styleFlag.borders = True | |
| styleFlag.font_color = True | |
| # Accessing a row from the Rows collection | |
| row = worksheet.cells.rows[0] | |
| # Assigning the Style object to the Style property of the row | |
| row.apply_style(style, styleFlag) | |
| # Saving the Excel file | |
| workbook.save(dataDir + "book1.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.pydrawing import Color | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Obtaining the reference of the first(default) worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[0] | |
| # Accessing the "A1" cell from the worksheet | |
| cell = worksheet.cells.get("A1") | |
| # Adding some value to the "A1" cell | |
| cell.put_value("Visit Aspose!") | |
| # Setting the font of selected characters to bold | |
| cell.characters(6, 7).font.is_bold = True | |
| # Setting the font color of selected characters to blue | |
| cell.characters(6, 7).font.color = Color.blue | |
| # Saving the Excel file | |
| workbook.save(dataDir + "book1.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import BackgroundType, BorderType, CellBorderType, StyleFlag, TextAlignmentType, Workbook | |
| from aspose.pydrawing import Color | |
| # Create a new Workbook. | |
| workbook = Workbook() | |
| /* | |
| * Note: Since Excel color palette has 56 colors on it. | |
| * The colors are indexed 0-55. | |
| * Please check: http:# Www.aspose.com/Products/Aspose.Cells/Api/Aspose.Cells.Workbook.ChangePalette.html | |
| * If a color is not present on the palette, we have to add it | |
| * To the palette, so that we may use. | |
| * Add a few custom colors to the palette. | |
| */ | |
| workbook.change_palette(Color.from_argb(155, 204, 255), 55) | |
| workbook.change_palette(Color.from_argb(0, 51, 105), 54) | |
| workbook.change_palette(Color.from_argb(250, 250, 200), 53) | |
| workbook.change_palette(Color.from_argb(124, 199, 72), 52) | |
| # Obtain the cells of the first worksheet. | |
| cells = workbook.worksheets[0].cells | |
| # Input the title on B1 cell. | |
| cells.get("B1").put_value("Western Product Sales 2006") | |
| # Insert some column headings in the second row. | |
| cell = cells.get("B2") | |
| cell.put_value("January") | |
| cell = cells.get("C2") | |
| cell.put_value("February") | |
| cell = cells.get("D2") | |
| cell.put_value("March") | |
| cell = cells.get("E2") | |
| cell.put_value("April") | |
| cell = cells.get("F2") | |
| cell.put_value("May") | |
| cell = cells.get("G2") | |
| cell.put_value("June") | |
| cell = cells.get("H2") | |
| cell.put_value("July") | |
| cell = cells.get("I2") | |
| cell.put_value("August") | |
| cell = cells.get("J2") | |
| cell.put_value("September") | |
| cell = cells.get("K2") | |
| cell.put_value("October") | |
| cell = cells.get("L2") | |
| cell.put_value("November") | |
| cell = cells.get("M2") | |
| cell.put_value("December") | |
| cell = cells.get("N2") | |
| cell.put_value("Total") | |
| # Insert product names. | |
| cells.get("A3").put_value("Biscuits") | |
| cells.get("A4").put_value("Coffee") | |
| cells.get("A5").put_value("Tofu") | |
| cells.get("A6").put_value("Ikura") | |
| cells.get("A7").put_value("Choclade") | |
| cells.get("A8").put_value("Maxilaku") | |
| cells.get("A9").put_value("Scones") | |
| cells.get("A10").put_value("Sauce") | |
| cells.get("A11").put_value("Syrup") | |
| cells.get("A12").put_value("Spegesild") | |
| cells.get("A13").put_value("Filo Mix") | |
| cells.get("A14").put_value("Pears") | |
| cells.get("A15").put_value("Konbu") | |
| cells.get("A16").put_value("Kaviar") | |
| cells.get("A17").put_value("Zaanse") | |
| cells.get("A18").put_value("Cabrales") | |
| cells.get("A19").put_value("Gnocchi") | |
| cells.get("A20").put_value("Wimmers") | |
| cells.get("A21").put_value("Breads") | |
| cells.get("A22").put_value("Lager") | |
| cells.get("A23").put_value("Gravad") | |
| cells.get("A24").put_value("Telino") | |
| cells.get("A25").put_value("Pavlova") | |
| cells.get("A26").put_value("Total") | |
| # Input porduct sales data (B3:M25). | |
| cells.get("B3").put_value(5000) | |
| cells.get("C3").put_value(4500) | |
| cells.get("D3").put_value(6010) | |
| cells.get("E3").put_value(7230) | |
| cells.get("F3").put_value(5400) | |
| cells.get("G3").put_value(5030) | |
| cells.get("H3").put_value(3000) | |
| cells.get("I3").put_value(6000) | |
| cells.get("J3").put_value(9000) | |
| cells.get("K3").put_value(3300) | |
| cells.get("L3").put_value(2500) | |
| cells.get("M3").put_value(5510) | |
| cells.get("B4").put_value(4000) | |
| cells.get("C4").put_value(2500) | |
| cells.get("D4").put_value(6000) | |
| cells.get("E4").put_value(5300) | |
| cells.get("F4").put_value(7400) | |
| cells.get("G4").put_value(7030) | |
| cells.get("H4").put_value(4000) | |
| cells.get("I4").put_value(4000) | |
| cells.get("J4").put_value(5500) | |
| cells.get("K4").put_value(4500) | |
| cells.get("L4").put_value(2500) | |
| cells.get("M4").put_value(2510) | |
| cells.get("B5").put_value(2000) | |
| cells.get("C5").put_value(1500) | |
| cells.get("D5").put_value(3000) | |
| cells.get("E5").put_value(2500) | |
| cells.get("F5").put_value(3400) | |
| cells.get("G5").put_value(4030) | |
| cells.get("H5").put_value(2000) | |
| cells.get("I5").put_value(2000) | |
| cells.get("J5").put_value(1500) | |
| cells.get("K5").put_value(2200) | |
| cells.get("L5").put_value(2100) | |
| cells.get("M5").put_value(2310) | |
| cells.get("B6").put_value(1000) | |
| cells.get("C6").put_value(1300) | |
| cells.get("D6").put_value(2000) | |
| cells.get("E6").put_value(2600) | |
| cells.get("F6").put_value(5400) | |
| cells.get("G6").put_value(2030) | |
| cells.get("H6").put_value(2100) | |
| cells.get("I6").put_value(4000) | |
| cells.get("J6").put_value(6500) | |
| cells.get("K6").put_value(5600) | |
| cells.get("L6").put_value(3300) | |
| cells.get("M6").put_value(5110) | |
| cells.get("B7").put_value(3000) | |
| cells.get("C7").put_value(3500) | |
| cells.get("D7").put_value(1000) | |
| cells.get("E7").put_value(4500) | |
| cells.get("F7").put_value(5400) | |
| cells.get("G7").put_value(2030) | |
| cells.get("H7").put_value(3000) | |
| cells.get("I7").put_value(3000) | |
| cells.get("J7").put_value(4500) | |
| cells.get("K7").put_value(6000) | |
| cells.get("L7").put_value(3000) | |
| cells.get("M7").put_value(3000) | |
| cells.get("B8").put_value(5000) | |
| cells.get("C8").put_value(5500) | |
| cells.get("D8").put_value(5000) | |
| cells.get("E8").put_value(5500) | |
| cells.get("F8").put_value(5400) | |
| cells.get("G8").put_value(5030) | |
| cells.get("H8").put_value(5000) | |
| cells.get("I8").put_value(2500) | |
| cells.get("J8").put_value(5500) | |
| cells.get("K8").put_value(5200) | |
| cells.get("L8").put_value(5500) | |
| cells.get("M8").put_value(2510) | |
| cells.get("B9").put_value(4100) | |
| cells.get("C9").put_value(1500) | |
| cells.get("D9").put_value(1000) | |
| cells.get("E9").put_value(2300) | |
| cells.get("F9").put_value(3300) | |
| cells.get("G9").put_value(4030) | |
| cells.get("H9").put_value(5000) | |
| cells.get("I9").put_value(6000) | |
| cells.get("J9").put_value(3500) | |
| cells.get("K9").put_value(4300) | |
| cells.get("L9").put_value(2300) | |
| cells.get("M9").put_value(2110) | |
| cells.get("B10").put_value(2000) | |
| cells.get("C10").put_value(2300) | |
| cells.get("D10").put_value(3000) | |
| cells.get("E10").put_value(3300) | |
| cells.get("F10").put_value(3400) | |
| cells.get("G10").put_value(3030) | |
| cells.get("H10").put_value(3000) | |
| cells.get("I10").put_value(3000) | |
| cells.get("J10").put_value(3500) | |
| cells.get("K10").put_value(3500) | |
| cells.get("L10").put_value(3500) | |
| cells.get("M10").put_value(3510) | |
| cells.get("B11").put_value(4400) | |
| cells.get("C11").put_value(4500) | |
| cells.get("D11").put_value(4000) | |
| cells.get("E11").put_value(4300) | |
| cells.get("F11").put_value(4400) | |
| cells.get("G11").put_value(4030) | |
| cells.get("H11").put_value(5000) | |
| cells.get("I11").put_value(5000) | |
| cells.get("J11").put_value(4500) | |
| cells.get("K11").put_value(4400) | |
| cells.get("L11").put_value(4400) | |
| cells.get("M11").put_value(4510) | |
| cells.get("B12").put_value(2000) | |
| cells.get("C12").put_value(1500) | |
| cells.get("D12").put_value(3000) | |
| cells.get("E12").put_value(2300) | |
| cells.get("F12").put_value(3400) | |
| cells.get("G12").put_value(3030) | |
| cells.get("H12").put_value(3000) | |
| cells.get("I12").put_value(3000) | |
| cells.get("J12").put_value(2500) | |
| cells.get("K12").put_value(2500) | |
| cells.get("L12").put_value(1500) | |
| cells.get("M12").put_value(5110) | |
| cells.get("B13").put_value(4000) | |
| cells.get("C13").put_value(1400) | |
| cells.get("D13").put_value(1400) | |
| cells.get("E13").put_value(3300) | |
| cells.get("F13").put_value(3300) | |
| cells.get("G13").put_value(3730) | |
| cells.get("H13").put_value(3800) | |
| cells.get("I13").put_value(3600) | |
| cells.get("J13").put_value(2600) | |
| cells.get("K13").put_value(4600) | |
| cells.get("L13").put_value(1400) | |
| cells.get("M13").put_value(2660) | |
| cells.get("B14").put_value(3000) | |
| cells.get("C14").put_value(3500) | |
| cells.get("D14").put_value(3333) | |
| cells.get("E14").put_value(2330) | |
| cells.get("F14").put_value(3430) | |
| cells.get("G14").put_value(3040) | |
| cells.get("H14").put_value(3040) | |
| cells.get("I14").put_value(3030) | |
| cells.get("J14").put_value(1509) | |
| cells.get("K14").put_value(4503) | |
| cells.get("L14").put_value(1503) | |
| cells.get("M14").put_value(3113) | |
| cells.get("B15").put_value(2010) | |
| cells.get("C15").put_value(1520) | |
| cells.get("D15").put_value(3030) | |
| cells.get("E15").put_value(2320) | |
| cells.get("F15").put_value(3410) | |
| cells.get("G15").put_value(3000) | |
| cells.get("H15").put_value(3000) | |
| cells.get("I15").put_value(3020) | |
| cells.get("J15").put_value(2520) | |
| cells.get("K15").put_value(2520) | |
| cells.get("L15").put_value(1520) | |
| cells.get("M15").put_value(5120) | |
| cells.get("B16").put_value(2220) | |
| cells.get("C16").put_value(1200) | |
| cells.get("D16").put_value(3220) | |
| cells.get("E16").put_value(1320) | |
| cells.get("F16").put_value(1400) | |
| cells.get("G16").put_value(1030) | |
| cells.get("H16").put_value(3200) | |
| cells.get("I16").put_value(3020) | |
| cells.get("J16").put_value(2100) | |
| cells.get("K16").put_value(2100) | |
| cells.get("L16").put_value(1100) | |
| cells.get("M16").put_value(5210) | |
| cells.get("B17").put_value(1444) | |
| cells.get("C17").put_value(1540) | |
| cells.get("D17").put_value(3040) | |
| cells.get("E17").put_value(2340) | |
| cells.get("F17").put_value(1440) | |
| cells.get("G17").put_value(1030) | |
| cells.get("H17").put_value(3000) | |
| cells.get("I17").put_value(4000) | |
| cells.get("J17").put_value(4500) | |
| cells.get("K17").put_value(2500) | |
| cells.get("L17").put_value(4500) | |
| cells.get("M17").put_value(5550) | |
| cells.get("B18").put_value(4000) | |
| cells.get("C18").put_value(5500) | |
| cells.get("D18").put_value(3000) | |
| cells.get("E18").put_value(3300) | |
| cells.get("F18").put_value(3330) | |
| cells.get("G18").put_value(5330) | |
| cells.get("H18").put_value(3400) | |
| cells.get("I18").put_value(3040) | |
| cells.get("J18").put_value(2540) | |
| cells.get("K18").put_value(4500) | |
| cells.get("L18").put_value(4500) | |
| cells.get("M18").put_value(2110) | |
| cells.get("B19").put_value(2000) | |
| cells.get("C19").put_value(2500) | |
| cells.get("D19").put_value(3200) | |
| cells.get("E19").put_value(3200) | |
| cells.get("F19").put_value(2330) | |
| cells.get("G19").put_value(5230) | |
| cells.get("H19").put_value(2400) | |
| cells.get("I19").put_value(3240) | |
| cells.get("J19").put_value(2240) | |
| cells.get("K19").put_value(4300) | |
| cells.get("L19").put_value(4100) | |
| cells.get("M19").put_value(2310) | |
| cells.get("B20").put_value(7000) | |
| cells.get("C20").put_value(8500) | |
| cells.get("D20").put_value(8000) | |
| cells.get("E20").put_value(5300) | |
| cells.get("F20").put_value(6330) | |
| cells.get("G20").put_value(7330) | |
| cells.get("H20").put_value(3600) | |
| cells.get("I20").put_value(3940) | |
| cells.get("J20").put_value(2940) | |
| cells.get("K20").put_value(4600) | |
| cells.get("L20").put_value(6500) | |
| cells.get("M20").put_value(8710) | |
| cells.get("B21").put_value(4000) | |
| cells.get("C21").put_value(4500) | |
| cells.get("D21").put_value(2000) | |
| cells.get("E21").put_value(2200) | |
| cells.get("F21").put_value(2000) | |
| cells.get("G21").put_value(3000) | |
| cells.get("H21").put_value(3000) | |
| cells.get("I21").put_value(3000) | |
| cells.get("J21").put_value(4330) | |
| cells.get("K21").put_value(4420) | |
| cells.get("L21").put_value(4500) | |
| cells.get("M21").put_value(1330) | |
| cells.get("B22").put_value(2050) | |
| cells.get("C22").put_value(3520) | |
| cells.get("D22").put_value(1030) | |
| cells.get("E22").put_value(2000) | |
| cells.get("F22").put_value(3000) | |
| cells.get("G22").put_value(2000) | |
| cells.get("H22").put_value(2010) | |
| cells.get("I22").put_value(2210) | |
| cells.get("J22").put_value(2230) | |
| cells.get("K22").put_value(4240) | |
| cells.get("L22").put_value(3330) | |
| cells.get("M22").put_value(2000) | |
| cells.get("B23").put_value(1222) | |
| cells.get("C23").put_value(3000) | |
| cells.get("D23").put_value(3020) | |
| cells.get("E23").put_value(2770) | |
| cells.get("F23").put_value(3011) | |
| cells.get("G23").put_value(2000) | |
| cells.get("H23").put_value(6000) | |
| cells.get("I23").put_value(9000) | |
| cells.get("J23").put_value(4000) | |
| cells.get("K23").put_value(2000) | |
| cells.get("L23").put_value(5000) | |
| cells.get("M23").put_value(6333) | |
| cells.get("B24").put_value(1000) | |
| cells.get("C24").put_value(2000) | |
| cells.get("D24").put_value(1000) | |
| cells.get("E24").put_value(1300) | |
| cells.get("F24").put_value(1330) | |
| cells.get("G24").put_value(1390) | |
| cells.get("H24").put_value(1600) | |
| cells.get("I24").put_value(1900) | |
| cells.get("J24").put_value(1400) | |
| cells.get("K24").put_value(1650) | |
| cells.get("L24").put_value(1520) | |
| cells.get("M24").put_value(1910) | |
| cells.get("B25").put_value(2000) | |
| cells.get("C25").put_value(6600) | |
| cells.get("D25").put_value(3300) | |
| cells.get("E25").put_value(8300) | |
| cells.get("F25").put_value(2000) | |
| cells.get("G25").put_value(3000) | |
| cells.get("H25").put_value(6000) | |
| cells.get("I25").put_value(4000) | |
| cells.get("J25").put_value(7000) | |
| cells.get("K25").put_value(2000) | |
| cells.get("L25").put_value(5000) | |
| cells.get("M25").put_value(5500) | |
| # Add Monthwise Summary formulas. | |
| cells.get("B26").formula = "=SUM(B3:B25)" | |
| cells.get("C26").formula = "=SUM(C3:C25)" | |
| cells.get("D26").formula = "=SUM(D3:D25)" | |
| cells.get("E26").formula = "=SUM(E3:E25)" | |
| cells.get("F26").formula = "=SUM(F3:F25)" | |
| cells.get("G26").formula = "=SUM(G3:G25)" | |
| cells.get("H26").formula = "=SUM(H3:H25)" | |
| cells.get("I26").formula = "=SUM(I3:I25)" | |
| cells.get("J26").formula = "=SUM(J3:J25)" | |
| cells.get("K26").formula = "=SUM(K3:K25)" | |
| cells.get("L26").formula = "=SUM(L3:L25)" | |
| cells.get("M26").formula = "=SUM(M3:M25)" | |
| # Add Productwise Summary formulas. | |
| cells.get("N3").formula = "=SUM(B3:M3)" | |
| cells.get("N4").formula = "=SUM(B4:M4)" | |
| cells.get("N5").formula = "=SUM(B5:M5)" | |
| cells.get("N6").formula = "=SUM(B6:M6)" | |
| cells.get("N7").formula = "=SUM(B7:M7)" | |
| cells.get("N8").formula = "=SUM(B8:M8)" | |
| cells.get("N9").formula = "=SUM(B9:M9)" | |
| cells.get("N10").formula = "=SUM(B10:M10)" | |
| cells.get("N11").formula = "=SUM(B11:M11)" | |
| cells.get("N12").formula = "=SUM(B12:M12)" | |
| cells.get("N13").formula = "=SUM(B13:M13)" | |
| cells.get("N14").formula = "=SUM(B14:M14)" | |
| cells.get("N15").formula = "=SUM(B15:M15)" | |
| cells.get("N16").formula = "=SUM(B16:M16)" | |
| cells.get("N17").formula = "=SUM(B17:M17)" | |
| cells.get("N18").formula = "=SUM(B18:M18)" | |
| cells.get("N19").formula = "=SUM(B19:M19)" | |
| cells.get("N20").formula = "=SUM(B20:M20)" | |
| cells.get("N21").formula = "=SUM(B21:M21)" | |
| cells.get("N22").formula = "=SUM(B22:M22)" | |
| cells.get("N23").formula = "=SUM(B23:M23)" | |
| cells.get("N24").formula = "=SUM(B24:M24)" | |
| cells.get("N25").formula = "=SUM(B25:M25)" | |
| # Add Grand Total. | |
| cells.get("N26").formula = "=SUM(N3:N25)" | |
| # Define a style object adding a new style to the collection list. | |
| stl0 = workbook.create_style() | |
| # Set a custom shading color of the cells. | |
| stl0.foreground_color = Color.from_argb(155, 204, 255) | |
| stl0.pattern = BackgroundType.SOLID | |
| stl0.font.name = "Trebuchet MS" | |
| stl0.font.size = 18 | |
| stl0.font.color = Color.maroon | |
| stl0.font.is_bold = True | |
| stl0.font.is_italic = True | |
| # Define a style flag struct. | |
| flag = StyleFlag() | |
| flag.cell_shading = True | |
| flag.font_name = True | |
| flag.font_size = True | |
| flag.font_color = True | |
| flag.font_bold = True | |
| flag.font_italic = True | |
| # Get the first row in the first worksheet. | |
| row = workbook.worksheets[0].cells.rows[0] | |
| # Apply the style to it. | |
| row.apply_style(stl0, flag) | |
| # Obtain the cells of the first worksheet. | |
| cells = workbook.worksheets[0].cells | |
| # Set the height of the first row. | |
| cells.set_row_height(0, 30) | |
| # Define a style object adding a new style to the collection list. | |
| stl1 = workbook.create_style() | |
| # Set the rotation angle of the text. | |
| stl1.rotation_angle = 45 | |
| # Set the custom fill color of the cells. | |
| stl1.foreground_color = Color.from_argb(0, 51, 105) | |
| stl1.pattern = BackgroundType.SOLID | |
| stl1.borders.get(BorderType.LEFT_BORDER).line_style = CellBorderType.THIN | |
| stl1.borders.get(BorderType.LEFT_BORDER).color = Color.white | |
| stl1.horizontal_alignment = TextAlignmentType.CENTER | |
| stl1.vertical_alignment = TextAlignmentType.CENTER | |
| stl1.font.name = "Times New Roman" | |
| stl1.font.size = 10 | |
| stl1.font.color = Color.white | |
| stl1.font.is_bold = True | |
| # Set a style flag struct. | |
| flag = StyleFlag() | |
| flag.left_border = True | |
| flag.rotation = True | |
| flag.cell_shading = True | |
| flag.horizontal_alignment = True | |
| flag.vertical_alignment = True | |
| flag.font_name = True | |
| flag.font_size = True | |
| flag.font_color = True | |
| flag.font_bold = True | |
| row = workbook.worksheets[0].cells.rows[1] | |
| # Apply the style to it. | |
| row.apply_style(stl1, flag) | |
| # Set the height of the second row. | |
| cells.set_row_height(1, 48) | |
| # Define a style object adding a new style to the collection list. | |
| stl2 = workbook.create_style() | |
| # Set the custom cell shading color. | |
| stl2.foreground_color = Color.from_argb(155, 204, 255) | |
| stl2.pattern = BackgroundType.SOLID | |
| stl2.font.name = "Trebuchet MS" | |
| stl2.font.color = Color.maroon | |
| stl2.font.size = 10 | |
| flag = StyleFlag() | |
| flag.cell_shading = True | |
| flag.font_name = True | |
| flag.font_color = True | |
| flag.font_size = True | |
| # Get the first column in the first worksheet. | |
| col = workbook.worksheets[0].cells.columns[0] | |
| # Apply the style to it. | |
| col.apply_style(stl2, flag) | |
| # Define a style object adding a new style to the collection list. | |
| stl3 = workbook.create_style() | |
| # Set the custom cell filling color. | |
| stl3.foreground_color = Color.from_argb(124, 199, 72) | |
| stl3.pattern = BackgroundType.SOLID | |
| cells.get("A2").set_style(stl3) | |
| # Define a style object adding a new style to the collection list. | |
| stl4 = workbook.create_style() | |
| # Set the custom font text color. | |
| stl4.font.color = Color.from_argb(0, 51, 105) | |
| stl4.borders.get(BorderType.BOTTOM_BORDER).line_style = CellBorderType.THIN | |
| stl4.borders.get(BorderType.BOTTOM_BORDER).color = Color.from_argb(124, 199, 72) | |
| stl4.foreground_color = Color.white | |
| stl4.pattern = BackgroundType.SOLID | |
| # Set custom number format. | |
| stl4.custom = "$#,##0.0" | |
| # Set a style flag struct. | |
| flag = StyleFlag() | |
| flag.font_color = True | |
| flag.cell_shading = True | |
| flag.number_format = True | |
| flag.bottom_border = True | |
| # Define a style object adding a new style to the collection list. | |
| stl5 = workbook.create_style() | |
| stl5.borders.get(BorderType.BOTTOM_BORDER).line_style = CellBorderType.THIN | |
| stl5.borders.get(BorderType.BOTTOM_BORDER).color = Color.from_argb(124, 199, 72) | |
| stl5.foreground_color = Color.from_argb(250, 250, 200) | |
| stl5.pattern = BackgroundType.SOLID | |
| # Set custom number format. | |
| stl5.custom = "$#,##0.0" | |
| stl5.font.color = Color.maroon | |
| # Create a named range of cells (B3:M25)in the first worksheet. | |
| range = workbook.worksheets[0].cells.create_range("B3", "M25") | |
| # Name the range. | |
| range.name = "MyRange" | |
| # Apply the style to cells in the named range. | |
| range.apply_style(stl4, flag) | |
| # Apply different style to alternative rows in the range. | |
| for i in range(22 + 1): | |
| for j in range(12): | |
| if i % 2 == 0: | |
| range.get(i, j).set_style(stl5) | |
| # Define a style object adding a new style to the collection list. | |
| stl6 = workbook.create_style() | |
| # Set the custom fill color of the cells. | |
| stl6.foreground_color = Color.from_argb(0, 51, 105) | |
| stl6.pattern = BackgroundType.SOLID | |
| stl6.font.name = "Arial" | |
| stl6.font.size = 10 | |
| stl6.font.color = Color.white | |
| stl6.font.is_bold = True | |
| # Set the custom number format. | |
| stl6.custom = "$#,##0.0" | |
| # Set the style flag struct. | |
| flag = StyleFlag() | |
| flag.cell_shading = True | |
| flag.font_name = True | |
| flag.font_size = True | |
| flag.font_color = True | |
| flag.font_bold = True | |
| flag.number_format = True | |
| # Get the 26th row in the first worksheet which produces totals. | |
| row = workbook.worksheets[0].cells.rows[25] | |
| # Apply the style to it. | |
| row.apply_style(stl6, flag) | |
| # Now apply this style to those cells (N3:N25) which has productwise sales totals. | |
| for i in range(2, 25): | |
| cells.get(i, 13).set_style(stl6) | |
| # Set N column's width to fit the contents. | |
| workbook.worksheets[0].cells.set_column_width(13, 9.33) | |
| # Get the first worksheet in the book. | |
| worksheet = workbook.worksheets[0] | |
| # Name the worksheet. | |
| worksheet.name = "Sales Report" | |
| dataDir = "./" | |
| filename = dataDir + "FormatWorksheet.xls" | |
| # Save the excel file. | |
| workbook.save(filename) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import CellArea, FormatConditionType, Workbook | |
| from aspose.cells.drawing import ImageType | |
| from aspose.cells.rendering import ImageOrPrintOptions | |
| # Source directory | |
| sourceDir = "./" | |
| # Output directory | |
| outputDir = "./" | |
| # Create workbook object from source excel file | |
| workbook = Workbook(sourceDir + "sampleGenerateDatabarImage.xlsx") | |
| # Access first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Access the cell which contains conditional formatting databar | |
| cell = worksheet.cells.get("C1") | |
| # Create and get the conditional formatting of the worksheet | |
| idx = worksheet.conditional_formattings.add() | |
| fcc = worksheet.conditional_formattings[idx] | |
| fcc.add_condition(FormatConditionType.DATA_BAR) | |
| fcc.add_area(CellArea.create_cell_area("C1", "C4")) | |
| # Access the conditional formatting databar | |
| dbar = fcc[0].data_bar | |
| # Create image or print options | |
| opts = ImageOrPrintOptions() | |
| opts.image_type = ImageType.PNG | |
| # Get the image bytes of the databar | |
| imgBytes = dbar.to_image(cell, opts) | |
| # Write image bytes on the disk | |
| with open(outputDir + "outputGenerateDatabarImage.png", "wb") as f: | |
| f.write(imgBytes) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Open a template Excel file | |
| workbook = Workbook(dataDir + "book1.xlsx") | |
| # Get the first worksheet in the workbook | |
| sheet = workbook.worksheets[0] | |
| # Get the A1 cell | |
| cell = sheet.cells.get("A1") | |
| # Get the conditional formatting result object | |
| cfr = cell.get_conditional_formatting_result() | |
| # Get the icon set | |
| icon = cfr.conditional_formatting_icon | |
| # Create the image file based on the icon's image data | |
| with open(dataDir + "imgIcon.out.jpg", "wb") as f: | |
| f.write(icon.image_data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Load source workbook | |
| wb = Workbook(dataDir + "sampleGetFonts.xlsx") | |
| # Get all the fonts inside the workbook | |
| fnts = wb.get_fonts() | |
| # Print all the fonts | |
| for i in range(len(fnts)): | |
| print(fnts[i]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import ThemeColorType, Workbook | |
| from aspose.pydrawing import Color | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Instantiate Workbook object. | |
| # Open an exiting excel file. | |
| workbook = Workbook(dataDir + "book1.xlsx") | |
| # Get the Background1 theme color. | |
| c = workbook.get_theme_color(ThemeColorType.BACKGROUND1) | |
| # Print the color. | |
| print("theme color Background1: " + str(c)) | |
| # Get the Accent2 theme color. | |
| c = workbook.get_theme_color(ThemeColorType.ACCENT2) | |
| # Print the color. | |
| print("theme color Accent2: " + str(c)) | |
| # Change the Background1 theme color. | |
| workbook.set_theme_color(ThemeColorType.BACKGROUND1, Color.red) | |
| # Get the updated Background1 theme color. | |
| c = workbook.get_theme_color(ThemeColorType.BACKGROUND1) | |
| # Print the updated color for confirmation. | |
| print("theme color Background1 changed to: " + str(c)) | |
| # Change the Accent2 theme color. | |
| workbook.set_theme_color(ThemeColorType.ACCENT2, Color.blue) | |
| # Get the updated Accent2 theme color. | |
| c = workbook.get_theme_color(ThemeColorType.ACCENT2) | |
| # Print the updated color for confirmation. | |
| print("theme color Accent2 changed to: " + str(c)) | |
| # Save the updated file. | |
| workbook.save(dataDir + "output.out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import FontSchemeType, Workbook | |
| workbook = Workbook("Book1.xlsx") | |
| defaultStyle = workbook.default_style | |
| schemeType = defaultStyle.font.scheme_type | |
| if schemeType == FontSchemeType.MAJOR or schemeType == FontSchemeType.MINOR: | |
| print("It's theme font") | |
| # Change theme font to mormal font | |
| defaultStyle.font.scheme_type = FontSchemeType.NONE | |
| workbook.default_style = defaultStyle |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Initialize a new Workbook | |
| # Open an excel file | |
| workbook = Workbook(dataDir + "book1.xlsx") | |
| # Implement 1904 date system | |
| workbook.settings.date1904 = True | |
| # Save the excel file | |
| workbook.save(dataDir + "Mybook.out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create Workbook Object | |
| wb = Workbook() | |
| # Open first Worksheet in the workbook | |
| ws = wb.worksheets[0] | |
| # Get Worksheet Cells Collection | |
| cell = ws.cells | |
| # Increase the width of First Column Width | |
| cell.set_column_width(0, 35) | |
| # Increase the height of first row | |
| cell.set_row_height(0, 65) | |
| # Add Text to the Firts Cell with Explicit Line Breaks | |
| cell.get(0, 0).put_value("I am using\nthe latest version of \nAspose.Cells to \ntest this functionality") | |
| # Make Cell's Text wrap | |
| style = cell.get(0, 0).get_style() | |
| style.is_text_wrapped = True | |
| cell.get(0, 0).set_style(style) | |
| # Save Excel File | |
| wb.save(dataDir + "WrappingText.out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create Workbook Object | |
| wb = Workbook() | |
| # Open first Worksheet in the workbook | |
| ws = wb.worksheets[0] | |
| # Get Worksheet Cells Collection | |
| cell = ws.cells | |
| # Increase the width of First Column Width | |
| cell.set_column_width(0, 35) | |
| # Increase the height of first row | |
| cell.set_row_height(0, 36) | |
| # Add Text to the Firts Cell | |
| cell.get(0, 0).put_value("I am using the latest version of Aspose.Cells to test this functionality") | |
| # Make Cell's Text wrap | |
| style = cell.get(0, 0).get_style() | |
| style.is_text_wrapped = True | |
| cell.get(0, 0).set_style(style) | |
| # Save Excel File | |
| wb.save(dataDir + "WrappingText.out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import CountryCode, LoadOptions, Workbook | |
| # Instantiate a new LoadOptions. | |
| options = LoadOptions() | |
| # Sets the customer's region | |
| options.region = CountryCode.JAPAN | |
| # Instantiate a new Workbook. | |
| workbook = Workbook("Book1.xlsx", options) | |
| defaultStyle = workbook.default_style | |
| # Gets customer's local font. | |
| localFontName = defaultStyle.font.name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import BackgroundType, Workbook | |
| from aspose.pydrawing import Color | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Create a Workbook. | |
| wbk = Workbook() | |
| # Create a Worksheet and get the first sheet. | |
| worksheet = wbk.worksheets[0] | |
| # Create a Cells object ot fetch all the cells. | |
| cells = worksheet.cells | |
| # Merge some Cells (C6:E7) into a single C6 Cell. | |
| cells.merge(5, 2, 2, 3) | |
| # Input data into C6 Cell. | |
| worksheet.cells.get(5, 2).put_value("This is my value") | |
| # Create a Style object to fetch the Style of C6 Cell. | |
| style = worksheet.cells.get(5, 2).get_style() | |
| # Create a Font object | |
| font = style.font | |
| # Set the name. | |
| font.name = "Times New Roman" | |
| # Set the font size. | |
| font.size = 18 | |
| # Set the font color | |
| font.color = Color.blue | |
| # Bold the text | |
| font.is_bold = True | |
| # Make it italic | |
| font.is_italic = True | |
| # Set the backgrond color of C6 Cell to Red | |
| style.foreground_color = Color.red | |
| style.pattern = BackgroundType.SOLID | |
| # Apply the Style to C6 Cell. | |
| cells.get(5, 2).set_style(style) | |
| # Save the Workbook. | |
| wbk.save(dataDir + "mergingcells.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import BackgroundType, Workbook | |
| from aspose.pydrawing import Color | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Create a Workbook. | |
| wbk = Workbook() | |
| # Create a Worksheet and get the first sheet. | |
| worksheet = wbk.worksheets[0] | |
| # Create a Cells object ot fetch all the cells. | |
| cells = worksheet.cells | |
| # Merge some Cells (C6:E7) into a single C6 Cell. | |
| cells.merge(5, 2, 2, 3) | |
| # Input data into C6 Cell. | |
| worksheet.cells.get(5, 2).put_value("This is my value") | |
| # Create a Style object to fetch the Style of C6 Cell. | |
| style = worksheet.cells.get(5, 2).get_style() | |
| # Create a Font object | |
| font = style.font | |
| # Set the name. | |
| font.name = "Times New Roman" | |
| # Set the font size. | |
| font.size = 18 | |
| # Set the font color | |
| font.color = Color.blue | |
| # Bold the text | |
| font.is_bold = True | |
| # Make it italic | |
| font.is_italic = True | |
| # Set the backgrond color of C6 Cell to Red | |
| style.foreground_color = Color.red | |
| style.pattern = BackgroundType.SOLID | |
| # Apply the Style to C6 Cell. | |
| cells.get(5, 2).set_style(style) | |
| # Save the Workbook. | |
| wbk.save(dataDir + "mergingcells.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.pydrawing import Color | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| /* | |
| * Create a workbook. | |
| * Open a template file. | |
| * In the book1.xls file, we have applied Ms Excel's | |
| * Named style i.e., "Percent" to the range "A1:C8". | |
| */ | |
| workbook = Workbook(dataDir + "book1.xlsx") | |
| # We get the Percent style and create a style object. | |
| style = workbook.get_named_style("Percent") | |
| # Change the number format to "0.00%". | |
| style.number = 11 | |
| # Set the font color. | |
| style.font.color = Color.red | |
| # Update the style. so, the style of range "A1:C8" will be changed too. | |
| style.update() | |
| # Save the excel file. | |
| workbook.save(dataDir + "book2.out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import StyleFlag, Workbook | |
| from aspose.pydrawing import Color | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create a workbook. | |
| workbook = Workbook() | |
| # Create a new style object. | |
| style = workbook.create_style() | |
| # Set the number format. | |
| style.number = 14 | |
| # Set the font color to red color. | |
| style.font.color = Color.red | |
| # Name the style. | |
| style.name = "Date1" | |
| # Get the first worksheet cells. | |
| cells = workbook.worksheets[0].cells | |
| # Specify the style (described above) to A1 cell. | |
| cells.get("A1").set_style(style) | |
| # Create a range (B1:D1). | |
| range = cells.create_range("B1", "D1") | |
| # Initialize styleflag object. | |
| flag = StyleFlag() | |
| # Set all formatting attributes on. | |
| flag.all = True | |
| # Apply the style (described above)to the range. | |
| range.apply_style(style, flag) | |
| # Modify the style (described above) and change the font color from red to black. | |
| style.font.color = Color.black | |
| # Done! Since the named style (described above) has been set to a cell and range, | |
| # The change would be Reflected(new modification is implemented) to cell(A1) and # Range (B1:D1). | |
| style.update() | |
| # Save the excel file. | |
| workbook.save(dataDir + "book_styles.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Create a new workbook | |
| workbook = Workbook() | |
| # Access the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Access the cell where you want to apply the currency format | |
| a1 = worksheet.cells.get("A1") | |
| # Set a numeric value to the cell | |
| a1.put_value(1234.56) | |
| # Create a style object to apply the currency format | |
| a1Style = a1.get_style() | |
| # "7" is the currency format in Excel | |
| a1Style.number = 7 | |
| # Apply the style to the cell | |
| a1.set_style(a1Style) | |
| # Access the cell where you want to apply the currency format | |
| a2 = worksheet.cells.get("A2") | |
| # Set a numeric value to the cell | |
| a2.put_value(3456.78) | |
| # Create a style object to apply the currency format | |
| a2Style = a2.get_style() | |
| # Custom format for dollar currency | |
| a2Style.custom = "$#,##0.00" | |
| # Apply the style to the cell | |
| a2.set_style(a2Style) | |
| # Save the workbook | |
| workbook.save("CurrencyFormatted.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Create a new workbook | |
| workbook = Workbook() | |
| # Access the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Access the cell where you want to apply the date format | |
| a1 = worksheet.cells.get("A1") | |
| # Set a numeric value that represents a date (e.g., 44210 represents 09/06/2021 in Excel) | |
| a1.put_value(44210) | |
| # Create a style object to apply the date format | |
| a1Style = a1.get_style() | |
| # "14" represents a standard date format in Excel (MM/DD/YYYY) | |
| a1Style.number = 14 | |
| # Apply the style to the cell | |
| a1.set_style(a1Style) | |
| # Access the cell where you want to apply the currency format | |
| a2 = worksheet.cells.get("A2") | |
| # Set a numeric value to the cell | |
| a2.put_value(44210) | |
| # Create a style object to apply the date format | |
| a2Style = a2.get_style() | |
| # Custom format for YYYY-MM-DD | |
| a2Style.custom = "YYYY-MM-DD" | |
| # Apply the style to the cell | |
| a2.set_style(a2Style) | |
| # Save the workbook | |
| workbook.save("DateFormatted.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| workbook = Workbook(dataDir + "SourceFile.xlsx") | |
| workbook.save(dataDir + "CustomDateFormat_out.pdf") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.pydrawing import Color | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create workbook object | |
| workbook = Workbook() | |
| # Access the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Access cells | |
| cell1 = worksheet.cells.get("A1") | |
| cell2 = worksheet.cells.get("B1") | |
| # Set the styles of both cells to Times New Roman | |
| styleObject = workbook.create_style() | |
| styleObject.font.color = Color.red | |
| styleObject.font.name = "Times New Roman" | |
| cell1.set_style(styleObject) | |
| cell2.set_style(styleObject) | |
| # Put the values inside the cell | |
| cell1.put_value("Hello World!") | |
| cell2.put_value("Hello World!!") | |
| # Save to Pdf without setting PdfSaveOptions.IsFontSubstitutionCharGranularity | |
| workbook.save(dataDir + "SampleOutput_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import BorderType, CellArea, CellBorderType, FormatConditionType, OperatorType, Workbook | |
| from aspose.pydrawing import Color | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| sheet = workbook.worksheets[0] | |
| # Adds an empty conditional formatting | |
| index = sheet.conditional_formattings.add() | |
| fcs = sheet.conditional_formattings[index] | |
| # Sets the conditional format range. | |
| ca = CellArea() | |
| ca.start_row = 0 | |
| ca.end_row = 5 | |
| ca.start_column = 0 | |
| ca.end_column = 3 | |
| fcs.add_area(ca) | |
| # Adds condition. | |
| conditionIndex = fcs.add_condition(FormatConditionType.CELL_VALUE, OperatorType.BETWEEN, "50", "100") | |
| # Sets the background color. | |
| fc = fcs[conditionIndex] | |
| fc.style.borders.get(BorderType.LEFT_BORDER).line_style = CellBorderType.DASHED | |
| fc.style.borders.get(BorderType.RIGHT_BORDER).line_style = CellBorderType.DASHED | |
| fc.style.borders.get(BorderType.TOP_BORDER).line_style = CellBorderType.DASHED | |
| fc.style.borders.get(BorderType.BOTTOM_BORDER).line_style = CellBorderType.DASHED | |
| fc.style.borders.get(BorderType.LEFT_BORDER).color = Color.from_argb(0, 255, 255) | |
| fc.style.borders.get(BorderType.RIGHT_BORDER).color = Color.from_argb(0, 255, 255) | |
| fc.style.borders.get(BorderType.TOP_BORDER).color = Color.from_argb(0, 255, 255) | |
| fc.style.borders.get(BorderType.BOTTOM_BORDER).color = Color.from_argb(255, 255, 0) | |
| workbook.save(dataDir + "output.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.pydrawing import Color | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Excel object | |
| i = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[i] | |
| # Accessing the "A1" cell from the worksheet | |
| cell = worksheet.cells.get("A1") | |
| # Adding some value to the "A1" cell | |
| cell.put_value("Hello Aspose!") | |
| # Obtaining the style of the cell | |
| style = cell.get_style() | |
| # Setting the font color to blue | |
| style.font.color = Color.blue | |
| # Applying the style to the cell | |
| cell.set_style(style) | |
| # Saving the Excel file | |
| workbook.save("out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Excel object | |
| i = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[i] | |
| # Accessing the "A1" cell from the worksheet | |
| cell = worksheet.cells.get("A1") | |
| # Adding some value to the "A1" cell | |
| cell.put_value("Hello Aspose!") | |
| # Obtaining the style of the cell | |
| style = cell.get_style() | |
| # Setting the font size to 14 | |
| style.font.size = 14 | |
| # Applying the style to the cell | |
| cell.set_style(style) | |
| # Saving the Excel file | |
| workbook.save("out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Excel object | |
| i = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[i] | |
| # Accessing the "A1" cell from the worksheet | |
| cell = worksheet.cells.get("A1") | |
| # Adding some value to the "A1" cell | |
| cell.put_value("Hello Aspose!") | |
| # Obtaining the style of the cell | |
| style = cell.get_style() | |
| # Setting the font weight to bold | |
| style.font.is_bold = True | |
| # Applying the style to the cell | |
| cell.set_style(style) | |
| # Saving the Excel file | |
| workbook.save("out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import BackgroundType, CellArea, FormatConditionType, OperatorType, Workbook | |
| from aspose.pydrawing import Color | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| sheet = workbook.worksheets[0] | |
| # Adds an empty conditional formatting | |
| index = sheet.conditional_formattings.add() | |
| fcs = sheet.conditional_formattings[index] | |
| # Sets the conditional format range. | |
| ca = CellArea() | |
| ca.start_row = 0 | |
| ca.end_row = 5 | |
| ca.start_column = 0 | |
| ca.end_column = 3 | |
| fcs.add_area(ca) | |
| # Adds condition. | |
| conditionIndex = fcs.add_condition(FormatConditionType.CELL_VALUE, OperatorType.BETWEEN, "50", "100") | |
| fc = fcs[conditionIndex] | |
| fc.style.pattern = BackgroundType.REVERSE_DIAGONAL_STRIPE | |
| fc.style.foreground_color = Color.from_argb(255, 255, 0) | |
| fc.style.background_color = Color.from_argb(0, 255, 255) | |
| workbook.save(dataDir + "output.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Excel object | |
| i = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[i] | |
| # Accessing the "A1" cell from the worksheet | |
| cell = worksheet.cells.get("A1") | |
| # Adding some value to the "A1" cell | |
| cell.put_value("Hello Aspose!") | |
| # Obtaining the style of the cell | |
| style = cell.get_style() | |
| # Setting the strike out effect on the font | |
| style.font.is_strikeout = True | |
| # Applying the style to the cell | |
| cell.set_style(style) | |
| # Saving the Excel file | |
| workbook.save(dataDir + "out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Excel object | |
| i = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[i] | |
| # Accessing the "A1" cell from the worksheet | |
| cell = worksheet.cells.get("A1") | |
| # Adding some value to the "A1" cell | |
| cell.put_value("Hello Aspose!") | |
| # Obtaining the style of the cell | |
| style = cell.get_style() | |
| # Setting subscript effect | |
| style.font.is_subscript = True | |
| # Applying the style to the cell | |
| cell.set_style(style) | |
| # Saving the Excel file | |
| workbook.save(dataDir + "out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Excel object | |
| i = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[i] | |
| # Accessing the "A1" cell from the worksheet | |
| cell = worksheet.cells.get("A1") | |
| # Adding some value to the "A1" cell | |
| cell.put_value("Hello Aspose!") | |
| # Obtaining the style of the cell | |
| style = cell.get_style() | |
| # Setting superscript effect | |
| style.font.is_superscript = True | |
| # Applying the style to the cell | |
| cell.set_style(style) | |
| # Saving the Excel file | |
| workbook.save(dataDir + "out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import SaveFormat, Workbook | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Excel object | |
| i = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[i] | |
| # Accessing the "A1" cell from the worksheet | |
| cell = worksheet.cells.get("A1") | |
| # Adding some value to the "A1" cell | |
| cell.put_value("Hello Aspose!") | |
| # Obtaining the style of the cell | |
| style = cell.get_style() | |
| # Setting the font name to "Times New Roman" | |
| style.font.name = "Times New Roman" | |
| # Applying the style to the cell | |
| cell.set_style(style) | |
| # Saving the Excel file | |
| workbook.save(dataDir + "book1.out.xls", SaveFormat.EXCEL_97_TO_2003) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import SaveFormat, Workbook | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Excel object | |
| i = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[i] | |
| # Accessing the "A1" cell from the worksheet | |
| cell = worksheet.cells.get("A1") | |
| # Adding some value to the "A1" cell | |
| cell.put_value("Hello Aspose!") | |
| # Obtaining the style of the cell | |
| style = cell.get_style() | |
| # Setting the font weight to bold | |
| style.font.is_bold = True | |
| # Applying the style to the cell | |
| cell.set_style(style) | |
| # Saving the Excel file | |
| workbook.save(dataDir + "book1.out.xls", SaveFormat.EXCEL_97_TO_2003) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import FontUnderlineType, Workbook | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Excel object | |
| i = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[i] | |
| # Accessing the "A1" cell from the worksheet | |
| cell = worksheet.cells.get("A1") | |
| # Adding some value to the "A1" cell | |
| cell.put_value("Hello Aspose!") | |
| # Obtaining the style of the cell | |
| style = cell.get_style() | |
| # Setting the font to be underlined | |
| style.font.underline = FontUnderlineType.SINGLE | |
| # Applying the style to the cell | |
| cell.set_style(style) | |
| # Saving the Excel file | |
| workbook.save(dataDir + "out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import SaveFormat, Workbook | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Excel object | |
| workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[0] | |
| # Accessing the "A1" cell from the worksheet | |
| cell = worksheet.cells.get("A1") | |
| # Adding some value to the "A1" cell | |
| cell.put_value("Hello") | |
| # Setting the font Subscript | |
| style = cell.get_style() | |
| style.font.is_subscript = True | |
| cell.set_style(style) | |
| # Saving the Excel file | |
| workbook.save(dataDir + "Subscript.out.xls", SaveFormat.AUTO) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import SaveFormat, Workbook | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Excel object | |
| workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[0] | |
| # Accessing the "A1" cell from the worksheet | |
| cell = worksheet.cells.get("A1") | |
| # Adding some value to the "A1" cell | |
| cell.put_value("Hello") | |
| # Setting the font Superscript | |
| style = cell.get_style() | |
| style.font.is_superscript = True | |
| cell.set_style(style) | |
| # Saving the Excel file | |
| workbook.save(dataDir + "Superscript.out.xls", SaveFormat.AUTO) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import SaveFormat, Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create a workbook. | |
| wb = Workbook() | |
| # Access first worksheet. | |
| ws = wb.worksheets[0] | |
| # Access cell A1 and put value 123. | |
| cell = ws.cells.get("A1") | |
| cell.put_value(123) | |
| # Access cell style. | |
| st = cell.get_style() | |
| # Specifying DBNum custom pattern formatting. | |
| st.custom = "[DBNum2][$-804]General" | |
| # Set the cell style. | |
| cell.set_style(st) | |
| # Set the first column width. | |
| ws.cells.set_column_width(0, 30) | |
| # Save the workbook in output pdf format. | |
| wb.save(dataDir + "outputDBNumCustomFormatting.pdf", SaveFormat.PDF) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create a Workbook. | |
| # Open the excel file. | |
| wbk = Workbook(dataDir + "mergingcells.xls") | |
| # Create a Worksheet and get the first sheet. | |
| worksheet = wbk.worksheets[0] | |
| # Create a Cells object ot fetch all the cells. | |
| cells = worksheet.cells | |
| # Unmerge the cells. | |
| cells.un_merge(5, 2, 2, 3) | |
| # Save the file. | |
| wbk.save(dataDir + "unmergingcells.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import SaveFormat, Workbook | |
| from datetime import datetime | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Obtaining the reference of first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Adding the current system date to "A1" cell | |
| worksheet.cells.get("A1").put_value(datetime.now()) | |
| # Getting the Style of the A1 Cell | |
| style = worksheet.cells.get("A1").get_style() | |
| # Setting the display format to number 15 to show date as "d-mmm-yy" | |
| style.number = 15 | |
| # Applying the style to the A1 cell | |
| worksheet.cells.get("A1").set_style(style) | |
| # Adding a numeric value to "A2" cell | |
| worksheet.cells.get("A2").put_value(20) | |
| # Getting the Style of the A2 Cell | |
| style = worksheet.cells.get("A2").get_style() | |
| # Setting the display format to number 9 to show value as percentage | |
| style.number = 9 | |
| # Applying the style to the A2 cell | |
| worksheet.cells.get("A2").set_style(style) | |
| # Adding a numeric value to "A3" cell | |
| worksheet.cells.get("A3").put_value(2546) | |
| # Getting the Style of the A3 Cell | |
| style = worksheet.cells.get("A3").get_style() | |
| # Setting the display format to number 6 to show value as currency | |
| style.number = 6 | |
| # Applying the style to the A3 cell | |
| worksheet.cells.get("A3").set_style(style) | |
| # Saving the Excel file | |
| workbook.save(dataDir + "book1.out.xls", SaveFormat.EXCEL_97_TO_2003) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import BuiltinStyleType, Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| output1Path = dataDir + "Output.xlsx" | |
| output2Path = dataDir + "Output.out.ods" | |
| workbook = Workbook() | |
| style = workbook.create_builtin_style(BuiltinStyleType.TITLE) | |
| cell = workbook.worksheets[0].cells.get("A1") | |
| cell.put_value("Aspose") | |
| cell.set_style(style) | |
| worksheet = workbook.worksheets[0] | |
| worksheet.auto_fit_column(0) | |
| worksheet.auto_fit_row(0) | |
| workbook.save(output1Path) | |
| print("File saved {0}", output1Path) | |
| workbook.save(output2Path) | |
| print("File saved {0}", output1Path) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import BackgroundType, CellsFactory, Workbook | |
| from aspose.pydrawing import Color | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create a Style object using CellsFactory class | |
| cf = CellsFactory() | |
| st = cf.create_style() | |
| # Set the Style fill color to Yellow | |
| st.pattern = BackgroundType.SOLID | |
| st.foreground_color = Color.yellow | |
| # Create a workbook and set its default style using the created Style object | |
| wb = Workbook() | |
| wb.default_style = st | |
| # Save the workbook | |
| wb.save(dataDir + "output_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Creating a file stream containing the Excel file to be opened | |
| fstream = open(dataDir + "Book1.xlsx", "rb") | |
| # Opening the Excel file through the file stream | |
| workbook = Workbook(fstream) | |
| # Accessing the first worksheet in the Excel file | |
| worksheet = workbook.worksheets[0] | |
| # Copying conditional format settings from cell "A1" to cell "B1" | |
| # worksheet.CopyConditionalFormatting(0, 0, 0, 1); | |
| TotalRowCount = 0 | |
| for i in range(len(workbook.worksheets)): | |
| sourceSheet = workbook.worksheets[i] | |
| sourceRange = sourceSheet.cells.max_display_range | |
| destRange = worksheet.cells.create_range(sourceRange.first_row + TotalRowCount, sourceRange.first_column, sourceRange.row_count, sourceRange.column_count) | |
| destRange.copy(sourceRange) | |
| TotalRowCount = sourceRange.row_count + TotalRowCount | |
| # Saving the modified Excel file | |
| workbook.save(dataDir + "output.xls") | |
| # Closing the file stream to free all resources | |
| fstream.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import SaveFormat, Workbook | |
| from datetime import datetime | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Excel object | |
| i = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[i] | |
| # Adding the current system date to "A1" cell | |
| worksheet.cells.get("A1").put_value(datetime.now()) | |
| # Getting the style of A1 cell | |
| style = worksheet.cells.get("A1").get_style() | |
| # Setting the custom display format to show date as "d-mmm-yy" | |
| style.custom = "d-mmm-yy" | |
| # Applying the style to A1 cell | |
| worksheet.cells.get("A1").set_style(style) | |
| # Adding a numeric value to "A2" cell | |
| worksheet.cells.get("A2").put_value(20) | |
| # Getting the style of A2 cell | |
| style = worksheet.cells.get("A2").get_style() | |
| # Setting the custom display format to show value as percentage | |
| style.custom = "0.0%" | |
| # Applying the style to A2 cell | |
| worksheet.cells.get("A2").set_style(style) | |
| # Adding a numeric value to "A3" cell | |
| worksheet.cells.get("A3").put_value(2546) | |
| # Getting the style of A3 cell | |
| style = worksheet.cells.get("A3").get_style() | |
| # Setting the custom display format to show value as currency | |
| style.custom = "£#,##0;[Red]$-#,##0" | |
| # Applying the style to A3 cell | |
| worksheet.cells.get("A3").set_style(style) | |
| # Saving the Excel file | |
| workbook.save(dataDir + "book1.out.xls", SaveFormat.EXCEL_97_TO_2003) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import BackgroundType, ThemeColor, ThemeColorType, Workbook | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiate a Workbook. | |
| workbook = Workbook() | |
| # Get cells collection in the first (default) worksheet. | |
| cells = workbook.worksheets[0].cells | |
| # Get the D3 cell. | |
| c = cells.get("D3") | |
| # Get the style of the cell. | |
| s = c.get_style() | |
| # Set foreground color for the cell from the default theme Accent2 color. | |
| s.foreground_theme_color = ThemeColor(ThemeColorType.ACCENT2, 0.5) | |
| # Set the pattern type. | |
| s.pattern = BackgroundType.SOLID | |
| # Get the font for the style. | |
| f = s.font | |
| # Set the theme color. | |
| f.theme_color = ThemeColor(ThemeColorType.ACCENT4, 0.1) | |
| # Apply style. | |
| c.set_style(s) | |
| # Put a value. | |
| c.put_value("Testing1") | |
| # Save the excel file. | |
| workbook.save(dataDir + "output.out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook, CellsHelper | |
| # Instantiating an Workbook object | |
| workbook = Workbook() | |
| # Obtaining the reference of the newly added worksheet | |
| ws = workbook.worksheets[0] | |
| cells = ws.cells | |
| # Setting the value to the cells | |
| cell = cells.get("A1") | |
| cell.put_value("Fruit") | |
| cell = cells.get("B1") | |
| cell.put_value("Count") | |
| cell = cells.get("C1") | |
| cell.put_value("Price") | |
| cell = cells.get("A2") | |
| cell.put_value("Apple") | |
| cell = cells.get("A3") | |
| cell.put_value("Mango") | |
| cell = cells.get("A4") | |
| cell.put_value("Blackberry") | |
| cell = cells.get("A5") | |
| cell.put_value("Cherry") | |
| cell = cells.get("B2") | |
| cell.put_value(5) | |
| cell = cells.get("B3") | |
| cell.put_value(3) | |
| cell = cells.get("B4") | |
| cell.put_value(6) | |
| cell = cells.get("B5") | |
| cell.put_value(4) | |
| cell = cells.get("C2") | |
| cell.put_value(5) | |
| cell = cells.get("C3") | |
| cell.put_value(20) | |
| cell = cells.get("C4") | |
| cell.put_value(30) | |
| cell = cells.get("C5") | |
| cell.put_value(60) | |
| curr = cells.find("Blackberry", None) | |
| # get row and column index of current cell | |
| currRow = [] | |
| currCol = [] | |
| CellsHelper.cell_name_to_index(curr.name, currRow, currCol) | |
| print("Row Index: " + str(currRow[0]) + " Column Index: " + str(currCol[0])) | |
| # get column name by column index | |
| columnName = CellsHelper.column_index_to_name(currCol[0]) | |
| # get row name by row index | |
| rowName = CellsHelper.row_index_to_name(currRow[0]) | |
| print("Column Name: " + columnName + " Row Name: " + rowName); | |
| # get column index by column name | |
| columnIndex = CellsHelper.column_name_to_index(columnName); | |
| # get row index by row name | |
| rowIndex = CellsHelper.row_name_to_index(rowName) | |
| print("Column Index: " + str(columnIndex) + " Row Index: " + str(rowIndex)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.pydrawing import Color | |
| # Instantiating an Workbook object | |
| workbook = Workbook() | |
| # Obtaining the reference of the newly added worksheet | |
| ws = workbook.worksheets[0] | |
| cells = ws.cells | |
| # Setting the value to the cells | |
| cell = cells.get("A1") | |
| cell.put_value("Fruit") | |
| cell = cells.get("B1") | |
| cell.put_value("Count") | |
| cell = cells.get("C1") | |
| cell.put_value("Price") | |
| cell = cells.get("A2") | |
| cell.put_value("Apple") | |
| cell = cells.get("A3") | |
| cell.put_value("Mango") | |
| cell = cells.get("A4") | |
| cell.put_value("Blackberry") | |
| cell = cells.get("A5") | |
| cell.put_value("Cherry") | |
| cell = cells.get("B2") | |
| cell.put_value(5) | |
| cell = cells.get("B3") | |
| cell.put_value(3) | |
| cell = cells.get("B4") | |
| cell.put_value(6) | |
| cell = cells.get("B5") | |
| cell.put_value(4) | |
| cell = cells.get("C2") | |
| cell.put_value(5) | |
| cell = cells.get("C3") | |
| cell.put_value(20) | |
| cell = cells.get("C4") | |
| cell.put_value(30) | |
| cell = cells.get("C5") | |
| cell.put_value(60) | |
| cell = cells.get("E10") | |
| temp = workbook.create_style() | |
| temp.font.color = Color.red | |
| cell.set_style(temp) | |
| # Get max display range of worksheet | |
| range = cells.max_display_range | |
| # get maximum row index of cell which contains data or style. | |
| print(cells.max_row) | |
| # get maximum row index of cell which contains data. | |
| print(cells.max_data_row) | |
| # get maximum column index of cell which contains data or style. | |
| print(cells.max_column) | |
| # get maximum column index of cell which contains data. | |
| print(cells.max_data_column) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import FileFormatType, SaveFormat, Workbook | |
| from aspose.cells.charts import ChartType | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| workbook = Workbook(FileFormatType.XLSX) | |
| sheet = workbook.worksheets[0] | |
| # Put data | |
| sheet.cells.get(0, 0).put_value(1) | |
| sheet.cells.get(0, 1).put_value(2) | |
| sheet.cells.get(0, 2).put_value(3) | |
| sheet.cells.get(1, 0).put_value(4) | |
| sheet.cells.get(1, 1).put_value(5) | |
| sheet.cells.get(1, 2).put_value(6) | |
| sheet.cells.get(2, 0).put_value(7) | |
| sheet.cells.get(2, 1).put_value(8) | |
| sheet.cells.get(2, 2).put_value(9) | |
| # Generate the chart | |
| chartIndex = sheet.charts.add(ChartType.SCATTER_CONNECTED_BY_LINES_WITH_DATA_MARKER, 5, 1, 24, 10) | |
| chart = sheet.charts[chartIndex] | |
| chart.title.text = "Test" | |
| chart.category_axis.title.text = "X-Axis" | |
| chart.value_axis.title.text = "Y-Axis" | |
| chart.n_series.category_data = "A1:C1" | |
| # Insert series | |
| chart.n_series.add("A2:C2", False) | |
| series = chart.n_series[0] | |
| pointCount = series.points.count | |
| for i in range(pointCount): | |
| pointIndex = series.points[i] | |
| pointIndex.data_labels.text = "Series 1" + "\n" + "Point " + str(i) | |
| # Insert series | |
| chart.n_series.add("A3:C3", False) | |
| series = chart.n_series[1] | |
| pointCount = series.points.count | |
| for i in range(pointCount): | |
| pointIndex = series.points[i] | |
| pointIndex.data_labels.text = "Series 2" + "\n" + "Point " + str(i) | |
| workbook.save(dataDir + "output_out.xlsx", SaveFormat.XLSX) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.drawing import MsoPresetTextEffect | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Open the existing excel file. | |
| workbook = Workbook(dataDir + "sample.xlsx") | |
| # Get the chart in the first worksheet. | |
| chart = workbook.worksheets[0].charts[0] | |
| # Add a WordArt watermark (shape) to the chart's plot area. | |
| wordart = chart.shapes.add_text_effect_in_chart(MsoPresetTextEffect.TEXT_EFFECT2, "CONFIDENTIAL", "Arial Black", 66, False, False, 1200, 500, 2000, 3000) | |
| # Get the shape's fill format. | |
| wordArtFormat = wordart.fill | |
| # Set the transparency. | |
| wordArtFormat.transparency = 0.9 | |
| # Get the line format. | |
| lineFormat = wordart.line | |
| # Set Line format to invisible. | |
| lineFormat.weight = 0.0 | |
| # Save the excel file. | |
| workbook.save(dataDir + "output_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType, LegendPositionType | |
| # How to Set Category Axis | |
| # Your local test path | |
| path = r"" | |
| # Create a new workbook | |
| workbook = Workbook() | |
| worksheet = workbook.worksheets[0] | |
| worksheet.name = "CHART" | |
| # Add a chart to the worksheet | |
| chartIndex = worksheet.charts.add(ChartType.COLUMN, 8, 0, 20, 10) | |
| chart = worksheet.charts[chartIndex] | |
| # Add some values to cells | |
| worksheet.cells.get("A1").put_value("Sales") | |
| worksheet.cells.get("A2").put_value(100) | |
| worksheet.cells.get("A3").put_value(150) | |
| worksheet.cells.get("A4").put_value(130) | |
| worksheet.cells.get("A5").put_value(160) | |
| worksheet.cells.get("A6").put_value(150) | |
| worksheet.cells.get("B1").put_value("Days") | |
| worksheet.cells.get("B2").put_value(1) | |
| worksheet.cells.get("B3").put_value(2) | |
| worksheet.cells.get("B4").put_value(3) | |
| worksheet.cells.get("B5").put_value(4) | |
| worksheet.cells.get("B6").put_value(5) | |
| # Some values in string | |
| Sales = "100,150,130,160,150" | |
| Days = "1,2,3,4,5" | |
| # Set Category Axis Data with string | |
| chart.n_series.category_data = "{" + Days + "}" | |
| # Or you can set Category Axis Data with data in cells, try it! | |
| # chart.NSeries.CategoryData = "B2:B6"; | |
| # Add Series to the chart | |
| chart.n_series.add("Demand1", True) | |
| # Set value axis with string | |
| chart.n_series[0].values = "{" + Sales + "}" | |
| chart.n_series.add("Demand2", True) | |
| # Set value axis with data in cells | |
| chart.n_series[1].values = "A2:A6" | |
| # Set some Category Axis properties | |
| chart.category_axis.tick_labels.rotation_angle = 45 | |
| chart.category_axis.tick_labels.font.size = 8 | |
| chart.legend.position = LegendPositionType.BOTTOM | |
| # Save the workbook to view the result file | |
| workbook.save(path + "Output.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import CopyOptions, SaveFormat, Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Load sample excel file | |
| wb = Workbook(dataDir + "sample.xlsx") | |
| # Access the first sheet which contains chart | |
| source = wb.worksheets[0] | |
| # Add another sheet named DestSheet | |
| destination = wb.worksheets.add("DestSheet") | |
| # Set CopyOptions.ReferToDestinationSheet to true | |
| options = CopyOptions() | |
| options.refer_to_destination_sheet = True | |
| # Copy all the rows of source worksheet to destination worksheet which includes chart as well | |
| # The chart data source will now refer to DestSheet | |
| destination.cells.copy_rows(source.cells, 0, 0, source.cells.max_display_range.row_count, options) | |
| # Save workbook in xlsx format | |
| wb.save(dataDir + "output_out.xlsx", SaveFormat.XLSX) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| workbook = Workbook(dataDir + "chart.xls") | |
| worksheet = workbook.worksheets[1] | |
| # Load the chart from source worksheet | |
| chart = worksheet.charts[0] | |
| # Resize the chart | |
| chart.chart_object.width = 400 | |
| chart.chart_object.height = 300 | |
| # Reposition the chart | |
| chart.chart_object.x = 250 | |
| chart.chart_object.y = 150 | |
| # Output the file | |
| workbook.save(dataDir + "chart.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartTextDirectionType | |
| # Source directory | |
| sourceDir = "./" | |
| # Output directory | |
| outputDir = "./" | |
| workbook = Workbook(sourceDir + "SampleChangeTickLabelDirection.xlsx") | |
| worksheet = workbook.worksheets[0] | |
| # Load the chart from source worksheet | |
| chart = worksheet.charts[0] | |
| chart.category_axis.tick_labels.direction_type = ChartTextDirectionType.HORIZONTAL | |
| # Output the file | |
| workbook.save(outputDir + "outputChangeChartDataLableDirection.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType, LegendPositionType | |
| from aspose.pydrawing import Color | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Workbook object | |
| sheetIndex = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[sheetIndex] | |
| # Adding sample values to cells | |
| worksheet.cells.get("A1").put_value(50) | |
| worksheet.cells.get("A2").put_value(100) | |
| worksheet.cells.get("A3").put_value(150) | |
| worksheet.cells.get("B1").put_value(60) | |
| worksheet.cells.get("B2").put_value(32) | |
| worksheet.cells.get("B3").put_value(50) | |
| # Adding a chart to the worksheet | |
| chartIndex = worksheet.charts.add(ChartType.COLUMN, 5, 0, 15, 5) | |
| # Accessing the instance of the newly added chart | |
| chart = worksheet.charts[chartIndex] | |
| # Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3" | |
| chart.n_series.add("A1:B3", True) | |
| # Setting the title of a chart | |
| chart.title.text = "Title" | |
| # Setting the font color of the chart title to blue | |
| chart.title.font.color = Color.blue | |
| # Move the legend to left | |
| chart.legend.position = LegendPositionType.LEFT | |
| # Set font color of the legend | |
| chart.legend.font.color = Color.blue | |
| # Save the file | |
| workbook.save("chart_legend.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import SaveFormat, Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Open the template file. | |
| workbook = Workbook(dataDir + "Sample.xlsx") | |
| # Access the first worksheet | |
| sheet = workbook.worksheets[0] | |
| # Access the first chart inside the sheet | |
| chart = sheet.charts[0] | |
| # Set text of second legend entry fill to none | |
| chart.legend.legend_entries[1].is_text_no_fill = True | |
| # Save the workbook in xlsx format | |
| workbook.save(dataDir + "ChartLegendEntry_out.xlsx", SaveFormat.XLSX) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells.rendering import ImageOrPrintOptions | |
| from aspose.pydrawing.drawing2d import SmoothingMode | |
| options = ImageOrPrintOptions() | |
| options.vertical_resolution = 300 | |
| options.horizontal_resolution = 300 | |
| options.smoothing_mode = SmoothingMode.ANTI_ALIAS | |
| # Create an instance of ImageOrPrintOptions and set a few properties | |
| options = options | |
| # Convert chart to image with additional settings | |
| chart.to_image(dataDir + "chartPNG_out.png", options) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Converting chart to PDF | |
| chart.to_pdf(dataDir + "chartPDF_out.pdf") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Converting chart to PDF | |
| chart.to_pdf(dataDir + "chartPDF_out.pdf") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.drawing import ImageType | |
| from aspose.cells.rendering import ImageOrPrintOptions | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create workbook object from source file | |
| workbook = Workbook(dataDir + "SampleChartBook.xlsx") | |
| # Access first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Access first chart inside the worksheet | |
| chart = worksheet.charts[0] | |
| # Set image or print options | |
| opts = ImageOrPrintOptions() | |
| opts.image_type = ImageType.SVG | |
| # Save the chart to svg format | |
| chart.to_image(dataDir + "Image_out.svg", opts) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.drawing import ImageType | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Open the existing excel file which contains the column chart. | |
| workbook = Workbook(dataDir + "ColumnChart.xlsx") | |
| # Get the designer chart (first chart) in the first worksheet of the workbook. | |
| chart = workbook.worksheets[0].charts[0] | |
| # Convert the chart to an image file. | |
| chart.to_image(dataDir + "ColumnChart.out.jpeg", ImageType.JPEG) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.drawing import ImageType | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Open the existing excel file which contains the pie chart. | |
| workbook = Workbook(dataDir + "PieChart.xlsx") | |
| # Get the designer chart (first chart) in the first worksheet of the workbook. | |
| chart = workbook.worksheets[0].charts[0] | |
| # Convert the chart to an image file. | |
| chart.to_image(dataDir + "PieChart.out.emf", ImageType.EMF) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartMarkerType, ChartType, FormattingType, LegendPositionType | |
| from aspose.cells.drawing import LineType | |
| from aspose.pydrawing import Color | |
| # Create the workbook | |
| workbook = Workbook("combo.xlsx") | |
| # Access the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Add a stock vloume(VHLC) | |
| pieIdx = worksheet.charts.add(ChartType.STOCK_VOLUME_HIGH_LOW_CLOSE, 15, 0, 34, 12) | |
| # Retrieve the Chart object | |
| chart = worksheet.charts[pieIdx] | |
| # Set the legend can be showed | |
| chart.show_legend = True | |
| # Set the chart title name | |
| chart.title.text = "Combo Chart" | |
| # Set the Legend at the bottom of the chart area | |
| chart.legend.position = LegendPositionType.BOTTOM | |
| # Set data range | |
| chart.set_chart_data_range("A1:E12", True) | |
| # Set category data | |
| chart.n_series.category_data = "A2:A12" | |
| # Set the Series[1] Series[2] and Series[3] to different Marker Style | |
| for j in range(len(chart.n_series)): | |
| if j == 1: | |
| chart.n_series[j].marker.marker_style = ChartMarkerType.CIRCLE | |
| chart.n_series[j].marker.marker_size = 15 | |
| chart.n_series[j].marker.area.formatting = FormattingType.CUSTOM | |
| chart.n_series[j].marker.area.foreground_color = Color.pink | |
| chart.n_series[j].border.is_visible = False | |
| elif j == 2: | |
| chart.n_series[j].marker.marker_style = ChartMarkerType.DASH | |
| chart.n_series[j].marker.marker_size = 15 | |
| chart.n_series[j].marker.area.formatting = FormattingType.CUSTOM | |
| chart.n_series[j].marker.area.foreground_color = Color.orange | |
| chart.n_series[j].border.is_visible = False | |
| elif j == 3: | |
| chart.n_series[j].marker.marker_style = ChartMarkerType.SQUARE | |
| chart.n_series[j].marker.marker_size = 15 | |
| chart.n_series[j].marker.area.formatting = FormattingType.CUSTOM | |
| chart.n_series[j].marker.area.foreground_color = Color.light_blue | |
| chart.n_series[j].border.is_visible = False | |
| # Set the chart type for Series[0] | |
| chart.n_series[0].type = ChartType.LINE | |
| # Set style for the border of first series | |
| chart.n_series[0].border.style = LineType.SOLID | |
| # Set Color for the first series | |
| chart.n_series[0].border.color = Color.dark_blue | |
| # Fill the PlotArea area with nothing | |
| chart.plot_area.area.formatting = FormattingType.NONE | |
| # Save the Excel file | |
| workbook.save("out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import BackgroundType, CellArea, ValidationType, Workbook | |
| from aspose.cells.charts import ChartType | |
| from aspose.pydrawing import Color | |
| # How to Create a Dynamic Chart with Dropdownlist | |
| # Your local test path | |
| LocalPath = r"" | |
| # Create a new workbook and access the first worksheet. | |
| workbook = Workbook() | |
| sheets = workbook.worksheets | |
| sheet = sheets[0] | |
| # Populate the data for the chart. Add values to cells and set series names. | |
| sheet.cells.get("A3").put_value("Tea") | |
| sheet.cells.get("A4").put_value("Coffee") | |
| sheet.cells.get("A5").put_value("Sugar") | |
| # In this example, we will add 12 months of data | |
| sheet.cells.get("B2").put_value("Jan") | |
| sheet.cells.get("C2").put_value("Feb") | |
| sheet.cells.get("D2").put_value("Mar") | |
| sheet.cells.get("E2").put_value("Apr") | |
| sheet.cells.get("F2").put_value("May") | |
| sheet.cells.get("G2").put_value("Jun") | |
| sheet.cells.get("H2").put_value("Jul") | |
| sheet.cells.get("I2").put_value("Aug") | |
| sheet.cells.get("J2").put_value("Sep") | |
| sheet.cells.get("K2").put_value("Oct") | |
| sheet.cells.get("L2").put_value("Nov") | |
| sheet.cells.get("M2").put_value("Dec") | |
| allMonths = 12 | |
| iCount = 3 | |
| for i in range(iCount): | |
| for j in range(allMonths): | |
| _row = i + 2 | |
| _column = j + 1 | |
| value = 50 * (i % 2) + 20 * (j % 3) + 10 * (i / 3) + 10 | |
| sheet.cells.get(_row, _column).put_value(value) | |
| # This is the Dropdownlist for Dynamic Data | |
| ca = CellArea() | |
| ca.start_row = 9 | |
| ca.end_row = 9 | |
| ca.start_column = 0 | |
| ca.end_column = 0 | |
| _index = sheet.validations.add(ca) | |
| _va = sheet.validations[_index] | |
| _va.type = ValidationType.LIST | |
| _va.in_cell_drop_down = True | |
| _va.formula1 = "=$B$2:$M$2" | |
| sheet.cells.get("A9").put_value("Current Month") | |
| sheet.cells.get("A10").put_value("Jan") | |
| _style = sheet.cells.get("A10").get_style() | |
| _style.font.is_bold = True | |
| _style.pattern = BackgroundType.SOLID | |
| _style.foreground_color = Color.yellow | |
| sheet.cells.get("A10").set_style(_style) | |
| # Set the dynamic range for the chart's data source. | |
| index = sheets.names.add("Sheet1!ChtMonthData") | |
| sheets.names[index].refers_to = "=OFFSET(Sheet1!$A$3,0,MATCH($A$10, $B$2:$M$2, 0),3,1)" | |
| # Set the dynamic range for the chart's data labels. | |
| index = sheets.names.add("Sheet1!ChtXLabels") | |
| sheets.names[index].refers_to = "=Sheet1!$A$3:$A$5" | |
| # Create a chart object and set its data source. | |
| chartIndex = sheet.charts.add(ChartType.COLUMN, 8, 2, 20, 8) | |
| chart = sheet.charts[chartIndex] | |
| chart.n_series.add("month", True) | |
| chart.n_series[0].name = "=Sheet1!$A$10" | |
| chart.n_series[0].values = "Sheet1!ChtMonthData" | |
| chart.n_series[0].x_values = "Sheet1!ChtXLabels" | |
| # Save the workbook as an Excel file. | |
| workbook.save(LocalPath + "DynamicChartWithDropdownlist.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType | |
| # How to Create a Dynamic Rolling Chart | |
| # Your local test path | |
| LocalPath = r"" | |
| # Create a new workbook and access the first worksheet. | |
| workbook = Workbook() | |
| sheets = workbook.worksheets | |
| sheet = sheets[0] | |
| # Populate the data for the chart. Add values to cells and set series names. | |
| sheet.cells.get("A1").put_value("Month") | |
| sheet.cells.get("A2").put_value(1) | |
| sheet.cells.get("A3").put_value(2) | |
| sheet.cells.get("A4").put_value(3) | |
| sheet.cells.get("A5").put_value(4) | |
| sheet.cells.get("A6").put_value(5) | |
| sheet.cells.get("A7").put_value(6) | |
| sheet.cells.get("A8").put_value(7) | |
| sheet.cells.get("B1").put_value("Sales") | |
| sheet.cells.get("B2").put_value(50) | |
| sheet.cells.get("B3").put_value(45) | |
| sheet.cells.get("B4").put_value(55) | |
| sheet.cells.get("B5").put_value(60) | |
| sheet.cells.get("B6").put_value(55) | |
| sheet.cells.get("B7").put_value(65) | |
| sheet.cells.get("B8").put_value(70) | |
| # Set the dynamic range for the chart's data source. | |
| index = sheets.names.add("Sheet1!ChtData") | |
| sheets.names[index].refers_to = "=OFFSET(Sheet1!$B$1,COUNT(Sheet1!$B:$B),0,-5,1)" | |
| # Set the dynamic range for the chart's data labels. | |
| index = sheets.names.add("Sheet1!ChtLabels") | |
| sheets.names[index].refers_to = "=OFFSET(Sheet1!$A$1,COUNT(Sheet1!$A:$A),0,-5,1)" | |
| # Create a chart object and set its data source. | |
| chartIndex = sheet.charts.add(ChartType.LINE, 10, 3, 25, 10) | |
| chart = sheet.charts[chartIndex] | |
| chart.n_series.add("Sales", True) | |
| chart.n_series[0].values = "Sheet1!ChtData" | |
| chart.n_series[0].x_values = "Sheet1!ChtLabels" | |
| # Save the workbook as an Excel file. | |
| workbook.save(LocalPath + "DynamicRollingChart.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType | |
| # How to Create a Dynamic Scrolling Chart | |
| # Your local test path | |
| LocalPath = r"" | |
| # Create a new workbook and access the first worksheet. | |
| workbook = Workbook() | |
| sheets = workbook.worksheets | |
| sheet = sheets[0] | |
| # Populate the data for the chart. Add values to cells and set series names. | |
| sheet.cells.get("A1").put_value("Day") | |
| sheet.cells.get("B1").put_value("Sales") | |
| # In this example, we will add 30 days of data | |
| allDays = 30 | |
| showDays = 10 | |
| currentDay = 1 | |
| for i in range(allDays): | |
| _cellA = "A" + str(i + 2) | |
| _cellB = "B" + str(i + 2) | |
| sheet.cells.get(_cellA).put_value(i + 1) | |
| value = 50 * (i % 2) + 20 * (i % 3) + 10 * (i / 3) | |
| sheet.cells.get(_cellB).put_value(value) | |
| # This is the Dynamic Scrolling Control Data | |
| sheet.cells.get("G19").put_value("Start Day") | |
| sheet.cells.get("G20").put_value(currentDay) | |
| sheet.cells.get("H19").put_value("Show Days") | |
| sheet.cells.get("H20").put_value(showDays) | |
| # Set the dynamic range for the chart's data source. | |
| index = sheets.names.add("Sheet1!ChtScrollData") | |
| sheets.names[index].refers_to = "=OFFSET(Sheet1!$B$2,Sheet1!$G$20,0,Sheet1!$H$20,1)" | |
| # Set the dynamic range for the chart's data labels. | |
| index = sheets.names.add("Sheet1!ChtScrollLabels") | |
| sheets.names[index].refers_to = "=OFFSET(Sheet1!$A$2,Sheet1!$G$20,0,Sheet1!$H$20,1)" | |
| # Add a ScrollBar for the Dynamic Scrolling Chart | |
| bar = sheet.shapes.add_scroll_bar(2, 0, 3, 0, 200, 30) | |
| bar.min = 0 | |
| bar.max = allDays - showDays | |
| bar.current_value = currentDay | |
| bar.linked_cell = "$G$20" | |
| # Create a chart object and set its data source. | |
| chartIndex = sheet.charts.add(ChartType.LINE, 2, 4, 15, 10) | |
| chart = sheet.charts[chartIndex] | |
| chart.n_series.add("Sales", True) | |
| chart.n_series[0].values = "Sheet1!ChtScrollData" | |
| chart.n_series[0].x_values = "Sheet1!ChtScrollLabels" | |
| # Save the workbook as an Excel file. | |
| workbook.save(LocalPath + "DynamicScrollingChart.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType | |
| from aspose.cells.drawing import FillType | |
| # Create an instance of Workbook | |
| workbook = Workbook("sample.xlsx") | |
| # Access the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Create BarStacked Chart | |
| i = worksheet.charts.add(ChartType.BAR_STACKED, 5, 6, 20, 15) | |
| # Retrieve the Chart object | |
| chart = worksheet.charts[i] | |
| # Set the chart title name | |
| chart.title.text = "Gantt Chart" | |
| # Set the chart title is Visible | |
| chart.title.is_visible = True | |
| # Set data range | |
| chart.set_chart_data_range("B1:B6", True) | |
| # Add series data range | |
| chart.n_series.add("C2:C6", True) | |
| # No fill for one serie | |
| chart.n_series[0].area.fill_format.fill_type = FillType.NONE | |
| # Set the Horizontal(Category) Axis | |
| chart.n_series.category_data = "A2:A6" | |
| # Reverse the Horizontal(Category) Axis | |
| chart.category_axis.is_plot_order_reversed = True | |
| # Set the value axis's MinValue and MaxValue | |
| chart.value_axis.min_value = worksheet.cells.get("B2").value | |
| chart.value_axis.max_value = worksheet.cells.get("D6").value | |
| chart.plot_area.area.fill_format.fill_type = FillType.NONE | |
| # Show the DataLabels | |
| chart.n_series[1].data_labels.show_value = True | |
| # Disable the Legend | |
| chart.show_legend = False | |
| # Save the result | |
| workbook.save("result.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartMarkerType, ChartType, FormattingType, LegendPositionType | |
| from aspose.cells.drawing import FillType | |
| from aspose.pydrawing import Color | |
| # Create an instance of Workbook | |
| workbook = Workbook("High-Low-Close.xlsx") | |
| # Access the first worksheet. | |
| worksheet = workbook.worksheets[0] | |
| # Create High-Low-Close-Stock Chart | |
| pieIdx = worksheet.charts.add(ChartType.STOCK_HIGH_LOW_CLOSE, 5, 6, 20, 12) | |
| # Retrieve the Chart object | |
| chart = worksheet.charts[pieIdx] | |
| # Set the legend can be showed | |
| chart.show_legend = True | |
| # Set the chart title name | |
| chart.title.text = "High-Low-Close Stock" | |
| # Set the Legend at the bottom of the chart area | |
| chart.legend.position = LegendPositionType.BOTTOM | |
| # Set data range | |
| chart.set_chart_data_range("A1:D9", True) | |
| # Set category data | |
| chart.n_series.category_data = "A2:A9" | |
| # Set the marker with the built-in data | |
| chart.n_series[2].marker.marker_style = ChartMarkerType.DASH | |
| chart.n_series[2].marker.marker_size = 20 | |
| chart.n_series[2].marker.area.formatting = FormattingType.CUSTOM | |
| chart.n_series[2].marker.area.foreground_color = Color.maroon | |
| # Fill the PlotArea area with nothing | |
| chart.plot_area.area.fill_format.fill_type = FillType.NONE | |
| # Save the Excel file | |
| workbook.save("out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType, LegendPositionType | |
| from aspose.cells.drawing import FillType | |
| from aspose.pydrawing import Color | |
| # Create an instance of Workbook | |
| workbook = Workbook("Open-High-Low-Close.xlsx") | |
| # Access the first worksheet. | |
| worksheet = workbook.worksheets[0] | |
| # Create High-Low-Close-Stock Chart | |
| pieIdx = worksheet.charts.add(ChartType.STOCK_OPEN_HIGH_LOW_CLOSE, 5, 6, 20, 12) | |
| # Retrieve the Chart object | |
| chart = worksheet.charts[pieIdx] | |
| # Set the legend can be showed | |
| chart.show_legend = True | |
| # Set the chart title name | |
| chart.title.text = "OPen-High-Low-Close Stock" | |
| # Set the Legend at the bottom of the chart area | |
| chart.legend.position = LegendPositionType.BOTTOM | |
| # Set data range | |
| chart.set_chart_data_range("A1:E9", True) | |
| # Set category data | |
| chart.n_series.category_data = "A2:A9" | |
| # Set the DownBars and UpBars with different color | |
| chart.n_series[0].down_bars.area.foreground_color = Color.green | |
| chart.n_series[0].up_bars.area.foreground_color = Color.red | |
| # Fill the PlotArea area with nothing | |
| chart.plot_area.area.fill_format.fill_type = FillType.NONE | |
| # Save the Excel file | |
| workbook.save("out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType | |
| from aspose.cells.drawing import FillType | |
| # Create an instance of Workbook | |
| workbook = Workbook("sunburst.xlsx") | |
| # Access the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Add a Treemap chart | |
| pieIdx = worksheet.charts.add(ChartType.SUNBURST, 5, 6, 25, 12) | |
| # Retrieve the Chart object | |
| chart = worksheet.charts[pieIdx] | |
| # Set the legend can be showed | |
| chart.show_legend = True | |
| # Set the chart title name | |
| chart.title.text = "Sunburst Chart" | |
| # Add series data range | |
| chart.n_series.add("D2:D16", True) | |
| # Set category data(A2:A16 is incorrect,as hierarchical catogory) | |
| chart.n_series.category_data = "A2:C16" | |
| # Show the DataLabels with category names | |
| chart.n_series[0].data_labels.show_category_name = True | |
| # Fill the PlotArea area with nothing | |
| chart.plot_area.area.fill_format.fill_type = FillType.NONE | |
| # Save the Excel file | |
| workbook.save("out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType, LegendPositionType, TickLabelPositionType | |
| from aspose.pydrawing import Color | |
| wb = Workbook("sample.xlsx") | |
| sheet = wb.worksheets[0] | |
| charts = sheet.charts | |
| # Add bar chart | |
| index = charts.add(ChartType.BAR_STACKED, 8, 1, 24, 8) | |
| chart = charts[index] | |
| # Set data for bar chart | |
| chart.set_chart_data_range("A1:C7", True) | |
| # Set properties for bar chart | |
| chart.title.text = "Tornado chart" | |
| chart.style = 2 | |
| chart.plot_area.area.foreground_color = Color.white | |
| chart.plot_area.border.color = Color.white | |
| chart.legend.position = LegendPositionType.BOTTOM | |
| chart.category_axis.tick_label_position = TickLabelPositionType.LOW | |
| chart.category_axis.is_plot_order_reversed = True | |
| chart.gap_width = 10 | |
| valueAxis = chart.value_axis | |
| valueAxis.tick_labels.number_format = "#,##0;#,##0" | |
| wb.save("out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType | |
| from aspose.cells.drawing import FillType | |
| # Create an instance of Workbook | |
| workbook = Workbook("treemap.xlsx") | |
| # Access the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Add a Treemap chart | |
| pieIdx = worksheet.charts.add(ChartType.TREEMAP, 5, 6, 20, 12) | |
| # Retrieve the Chart object | |
| chart = worksheet.charts[pieIdx] | |
| # Set the legend can be showed | |
| chart.show_legend = True | |
| # Set the chart title name | |
| chart.title.text = "TreeMap Chart" | |
| # Add series data range(D2:D13,actually) | |
| chart.n_series.add("D2:F13", True) | |
| # Set category data(A2:A13 is incorrect ) | |
| chart.n_series.category_data = "A2:C13" | |
| # Show the DataLabels with category names | |
| chart.n_series[0].data_labels.show_category_name = True | |
| # Fill the PlotArea area with nothing | |
| chart.plot_area.area.fill_format.fill_type = FillType.NONE | |
| # Save the Excel file | |
| workbook.save("out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType, LegendPositionType | |
| from aspose.cells.drawing import FillType | |
| from aspose.pydrawing import Color | |
| # Create an instance of Workbook | |
| workbook = Workbook("Volume-High-Low-Close.xlsx") | |
| # Access the first worksheet. | |
| worksheet = workbook.worksheets[0] | |
| # Create High-Low-Close-Stock Chart | |
| pieIdx = worksheet.charts.add(ChartType.STOCK_VOLUME_HIGH_LOW_CLOSE, 5, 6, 20, 12) | |
| # Retrieve the Chart object | |
| chart = worksheet.charts[pieIdx] | |
| # Set the legend can be showed | |
| chart.show_legend = True | |
| # Set the chart title name | |
| chart.title.text = "Volume-High-Low-Close Stock" | |
| # Set the Legend at the bottom of the chart area | |
| chart.legend.position = LegendPositionType.BOTTOM | |
| # Set data range | |
| chart.set_chart_data_range("A1:E9", True) | |
| # Set category data | |
| chart.n_series.category_data = "A2:A9" | |
| # Set Color for the first series(Volume) data | |
| chart.n_series[0].area.foreground_color = Color.from_argb(79, 129, 189) | |
| # Fill the PlotArea area with nothing | |
| chart.plot_area.area.fill_format.fill_type = FillType.NONE | |
| # Save the Excel file | |
| workbook.save("out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType, LegendPositionType | |
| from aspose.cells.drawing import FillType | |
| from aspose.pydrawing import Color | |
| # Create an instance of Workbook | |
| workbook = Workbook("Volume-Open-High-Low-Close.xlsx") | |
| # Access the first worksheet. | |
| worksheet = workbook.worksheets[0] | |
| # Create High-Low-Close-Stock Chart | |
| pieIdx = worksheet.charts.add(ChartType.STOCK_VOLUME_OPEN_HIGH_LOW_CLOSE, 5, 6, 20, 12) | |
| # Retrieve the Chart object | |
| chart = worksheet.charts[pieIdx] | |
| # Set the legend can be showed | |
| chart.show_legend = True | |
| # Set the chart title name | |
| chart.title.text = "Volume-Open-High-Low-Close Stock" | |
| # Set the Legend at the bottom of the chart area | |
| chart.legend.position = LegendPositionType.BOTTOM | |
| # Set data range | |
| chart.set_chart_data_range("A1:F9", True) | |
| # Set category data | |
| chart.n_series.category_data = "A2:A9" | |
| # Set Color for the first series(Volume) data | |
| chart.n_series[0].area.foreground_color = Color.from_argb(79, 129, 189) | |
| # Fill the PlotArea area with nothing | |
| chart.plot_area.area.fill_format.fill_type = FillType.NONE | |
| # Save the Excel file | |
| workbook.save("out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import PageLayoutAlignmentType, Workbook | |
| # Source directory | |
| sourceDir = "./" | |
| # Output directory | |
| outputDir = "./" | |
| # Load sample Excel file containing the chart. | |
| wb = Workbook(sourceDir + "sampleCreateChartPDFWithDesiredPageSize.xlsx") | |
| # Access first worksheet. | |
| ws = wb.worksheets[0] | |
| # Access first chart inside the worksheet. | |
| ch = ws.charts[0] | |
| # Create chart pdf with desired page size. | |
| ch.to_pdf(outputDir + "outputCreateChartPDFWithDesiredPageSize.pdf", 7, 7, PageLayoutAlignmentType.CENTER, PageLayoutAlignmentType.CENTER) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create an instance of Workbook | |
| book = Workbook() | |
| # Access first worksheet from the collection | |
| sheet = book.worksheets[0] | |
| # Access cells collection of the first worksheet | |
| cells = sheet.cells | |
| # Insert data column wise | |
| cells.get("A1").put_value("Category") | |
| cells.get("A2").put_value("Fruit") | |
| cells.get("A3").put_value("Fruit") | |
| cells.get("A4").put_value("Fruit") | |
| cells.get("A5").put_value("Fruit") | |
| cells.get("A6").put_value("Vegetables") | |
| cells.get("A7").put_value("Vegetables") | |
| cells.get("A8").put_value("Vegetables") | |
| cells.get("A9").put_value("Vegetables") | |
| cells.get("A10").put_value("Beverages") | |
| cells.get("A11").put_value("Beverages") | |
| cells.get("A12").put_value("Beverages") | |
| cells.get("B1").put_value("Food") | |
| cells.get("B2").put_value("Apple") | |
| cells.get("B3").put_value("Banana") | |
| cells.get("B4").put_value("Apricot") | |
| cells.get("B5").put_value("Grapes") | |
| cells.get("B6").put_value("Carrot") | |
| cells.get("B7").put_value("Onion") | |
| cells.get("B8").put_value("Cabage") | |
| cells.get("B9").put_value("Potatoe") | |
| cells.get("B10").put_value("Coke") | |
| cells.get("B11").put_value("Coladas") | |
| cells.get("B12").put_value("Fizz") | |
| cells.get("C1").put_value("Cost") | |
| cells.get("C2").put_value(2.2) | |
| cells.get("C3").put_value(3.1) | |
| cells.get("C4").put_value(4.1) | |
| cells.get("C5").put_value(5.1) | |
| cells.get("C6").put_value(4.4) | |
| cells.get("C7").put_value(5.4) | |
| cells.get("C8").put_value(6.5) | |
| cells.get("C9").put_value(5.3) | |
| cells.get("C10").put_value(3.2) | |
| cells.get("C11").put_value(3.6) | |
| cells.get("C12").put_value(5.2) | |
| cells.get("D1").put_value("Profit") | |
| cells.get("D2").put_value(0.1) | |
| cells.get("D3").put_value(0.4) | |
| cells.get("D4").put_value(0.5) | |
| cells.get("D5").put_value(0.6) | |
| cells.get("D6").put_value(0.7) | |
| cells.get("D7").put_value(1.3) | |
| cells.get("D8").put_value(0.8) | |
| cells.get("D9").put_value(1.3) | |
| cells.get("D10").put_value(2.2) | |
| cells.get("D11").put_value(2.4) | |
| cells.get("D12").put_value(3.3) | |
| # Create ListObject, Get the List objects collection in the first worksheet | |
| listObjects = sheet.list_objects | |
| # Add a List based on the data source range with headers on | |
| index = listObjects.add(0, 0, 11, 3, True) | |
| sheet.auto_fit_columns() | |
| # Create chart based on ListObject | |
| index = sheet.charts.add(ChartType.COLUMN, 21, 1, 35, 18) | |
| chart = sheet.charts[index] | |
| chart.set_chart_data_range("A1:D12", True) | |
| chart.n_series.category_data = "A2:B12" | |
| # Save spreadsheet | |
| book.save(dataDir + "output_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType | |
| from aspose.pydrawing import Color | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create a workbook object | |
| workbook = Workbook() | |
| # Get the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Create a range in the second worksheet | |
| range = worksheet.cells.create_range("C21", "C24") | |
| # Name the range | |
| range.name = "MyRange" | |
| # Fill different cells with data in the range | |
| range.get(0, 0).put_value("North") | |
| range.get(1, 0).put_value("South") | |
| range.get(2, 0).put_value("East") | |
| range.get(3, 0).put_value("West") | |
| comboBox = worksheet.shapes.add_combo_box(15, 0, 2, 0, 17, 64) | |
| comboBox.input_range = "=MyRange" | |
| comboBox.linked_cell = "=B16" | |
| comboBox.selected_index = 0 | |
| cell = worksheet.cells.get("B16") | |
| style = cell.get_style() | |
| style.font.color = Color.white | |
| cell.set_style(style) | |
| worksheet.cells.get("C16").formula = "=INDEX(Sheet1!$C$21:$C$24,$B$16,1)" | |
| # Put some data for chart source | |
| # Data Headers | |
| worksheet.cells.get("D15").put_value("Jan") | |
| worksheet.cells.get("D20").put_value("Jan") | |
| worksheet.cells.get("E15").put_value("Feb") | |
| worksheet.cells.get("E20").put_value("Feb") | |
| worksheet.cells.get("F15").put_value("Mar") | |
| worksheet.cells.get("F20").put_value("Mar") | |
| worksheet.cells.get("G15").put_value("Apr") | |
| worksheet.cells.get("G20").put_value("Apr") | |
| worksheet.cells.get("H15").put_value("May") | |
| worksheet.cells.get("H20").put_value("May") | |
| worksheet.cells.get("I15").put_value("Jun") | |
| worksheet.cells.get("I20").put_value("Jun") | |
| # Data | |
| worksheet.cells.get("D21").put_value(304) | |
| worksheet.cells.get("D22").put_value(402) | |
| worksheet.cells.get("D23").put_value(321) | |
| worksheet.cells.get("D24").put_value(123) | |
| worksheet.cells.get("E21").put_value(300) | |
| worksheet.cells.get("E22").put_value(500) | |
| worksheet.cells.get("E23").put_value(219) | |
| worksheet.cells.get("E24").put_value(422) | |
| worksheet.cells.get("F21").put_value(222) | |
| worksheet.cells.get("F22").put_value(331) | |
| worksheet.cells.get("F23").put_value(112) | |
| worksheet.cells.get("F24").put_value(350) | |
| worksheet.cells.get("G21").put_value(100) | |
| worksheet.cells.get("G22").put_value(200) | |
| worksheet.cells.get("G23").put_value(300) | |
| worksheet.cells.get("G24").put_value(400) | |
| worksheet.cells.get("H21").put_value(200) | |
| worksheet.cells.get("H22").put_value(300) | |
| worksheet.cells.get("H23").put_value(400) | |
| worksheet.cells.get("H24").put_value(500) | |
| worksheet.cells.get("I21").put_value(400) | |
| worksheet.cells.get("I22").put_value(200) | |
| worksheet.cells.get("I23").put_value(200) | |
| worksheet.cells.get("I24").put_value(100) | |
| # Dynamically load data on selection of Dropdown value | |
| worksheet.cells.get("D16").formula = "=IFERROR(VLOOKUP($C$16,$C$21:$I$24,2,FALSE),0)" | |
| worksheet.cells.get("E16").formula = "=IFERROR(VLOOKUP($C$16,$C$21:$I$24,3,FALSE),0)" | |
| worksheet.cells.get("F16").formula = "=IFERROR(VLOOKUP($C$16,$C$21:$I$24,4,FALSE),0)" | |
| worksheet.cells.get("G16").formula = "=IFERROR(VLOOKUP($C$16,$C$21:$I$24,5,FALSE),0)" | |
| worksheet.cells.get("H16").formula = "=IFERROR(VLOOKUP($C$16,$C$21:$I$24,6,FALSE),0)" | |
| worksheet.cells.get("I16").formula = "=IFERROR(VLOOKUP($C$16,$C$21:$I$24,7,FALSE),0)" | |
| # Create Chart | |
| index = worksheet.charts.add(ChartType.COLUMN, 0, 3, 12, 9) | |
| chart = worksheet.charts[index] | |
| chart.n_series.add("='Sheet1'!$D$16:$I$16", False) | |
| chart.n_series[0].name = "=C16" | |
| chart.n_series.category_data = "=$D$15:$I$15" | |
| # Save result on disc | |
| workbook.save(dataDir + "output_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import SaveFormat, Workbook | |
| from aspose.cells.charts import ChartType, FormattingType | |
| from aspose.pydrawing import Color | |
| # Output directory | |
| outputDir = "./" | |
| # Instantiate a workbook | |
| workbook = Workbook() | |
| # Access first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Set columns title | |
| worksheet.cells.get(0, 0).value = "X" | |
| worksheet.cells.get(0, 1).value = "Y" | |
| # Create random data and save in the cells | |
| for i in range(1, 21): | |
| worksheet.cells.get(i, 0).value = i | |
| worksheet.cells.get(i, 1).value = 0.8 | |
| for i in range(21, 41): | |
| worksheet.cells.get(i, 0).value = i - 20 | |
| worksheet.cells.get(i, 1).value = 0.9 | |
| # Add a chart to the worksheet | |
| idx = worksheet.charts.add(ChartType.LINE_WITH_DATA_MARKERS, 1, 3, 20, 20) | |
| # Access the newly created chart | |
| chart = worksheet.charts[idx] | |
| # Set chart style | |
| chart.style = 3 | |
| # Set autoscaling value to true | |
| chart.auto_scaling = True | |
| # Set foreground color white | |
| chart.plot_area.area.foreground_color = Color.white | |
| # Set Properties of chart title | |
| chart.title.text = "Sample Chart" | |
| # Set chart type | |
| chart.type = ChartType.LINE_WITH_DATA_MARKERS | |
| # Set Properties of categoryaxis title | |
| chart.category_axis.title.text = "Units" | |
| # Set Properties of nseries | |
| s2_idx = chart.n_series.add("A2: A2", True) | |
| s3_idx = chart.n_series.add("A22: A22", True) | |
| # Set IsColorVaried to true for varied points color | |
| chart.n_series.is_color_varied = True | |
| # Set properties of background area and series markers | |
| chart.n_series[s2_idx].area.formatting = FormattingType.CUSTOM | |
| chart.n_series[s2_idx].marker.area.foreground_color = Color.yellow | |
| chart.n_series[s2_idx].marker.border.is_visible = False | |
| # Set X and Y values of series chart | |
| chart.n_series[s2_idx].x_values = "A2: A21" | |
| chart.n_series[s2_idx].values = "B2: B21" | |
| # Set properties of background area and series markers | |
| chart.n_series[s3_idx].area.formatting = FormattingType.CUSTOM | |
| chart.n_series[s3_idx].marker.area.foreground_color = Color.green | |
| chart.n_series[s3_idx].marker.border.is_visible = False | |
| # Set X and Y values of series chart | |
| chart.n_series[s3_idx].x_values = "A22: A41" | |
| chart.n_series[s3_idx].values = "B22: B41" | |
| # Save the workbook | |
| workbook.save(outputDir + r"LineWithDataMarkerChart.xlsx", SaveFormat.XLSX) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import SheetType, Workbook | |
| from aspose.cells.charts import ChartType | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Instantiating an Workbook object | |
| # Opening the excel file | |
| workbook = Workbook(dataDir + "pivotTable_test.xlsx") | |
| # Adding a new sheet | |
| sheet3 = workbook.worksheets[workbook.worksheets.add(SheetType.CHART)] | |
| # Naming the sheet | |
| sheet3.name = "PivotChart" | |
| # Adding a column chart | |
| index = sheet3.charts.add(ChartType.COLUMN, 0, 5, 28, 16) | |
| # Setting the pivot chart data source | |
| sheet3.charts[index].pivot_source = "PivotTable!PivotTable1" | |
| sheet3.charts[index].hide_pivot_field_buttons = False | |
| # Saving the Excel file | |
| workbook.save(dataDir + "pivotChart_test_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.pivot import PivotFieldType, PivotTableAutoFormatType | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Instantiating an Workbook object | |
| workbook = Workbook() | |
| # Obtaining the reference of the first worksheet | |
| sheet = workbook.worksheets[0] | |
| # Name the sheet | |
| sheet.name = "Data" | |
| cells = sheet.cells | |
| # Setting the values to the cells | |
| cell = cells.get("A1") | |
| cell.put_value("Employee") | |
| cell = cells.get("B1") | |
| cell.put_value("Quarter") | |
| cell = cells.get("C1") | |
| cell.put_value("Product") | |
| cell = cells.get("D1") | |
| cell.put_value("Continent") | |
| cell = cells.get("E1") | |
| cell.put_value("Country") | |
| cell = cells.get("F1") | |
| cell.put_value("Sale") | |
| cell = cells.get("A2") | |
| cell.put_value("David") | |
| cell = cells.get("A3") | |
| cell.put_value("David") | |
| cell = cells.get("A4") | |
| cell.put_value("David") | |
| cell = cells.get("A5") | |
| cell.put_value("David") | |
| cell = cells.get("A6") | |
| cell.put_value("James") | |
| cell = cells.get("A7") | |
| cell.put_value("James") | |
| cell = cells.get("A8") | |
| cell.put_value("James") | |
| cell = cells.get("A9") | |
| cell.put_value("James") | |
| cell = cells.get("A10") | |
| cell.put_value("James") | |
| cell = cells.get("A11") | |
| cell.put_value("Miya") | |
| cell = cells.get("A12") | |
| cell.put_value("Miya") | |
| cell = cells.get("A13") | |
| cell.put_value("Miya") | |
| cell = cells.get("A14") | |
| cell.put_value("Miya") | |
| cell = cells.get("A15") | |
| cell.put_value("Miya") | |
| cell = cells.get("A16") | |
| cell.put_value("Miya") | |
| cell = cells.get("A17") | |
| cell.put_value("Miya") | |
| cell = cells.get("A18") | |
| cell.put_value("Elvis") | |
| cell = cells.get("A19") | |
| cell.put_value("Elvis") | |
| cell = cells.get("A20") | |
| cell.put_value("Elvis") | |
| cell = cells.get("A21") | |
| cell.put_value("Elvis") | |
| cell = cells.get("A22") | |
| cell.put_value("Elvis") | |
| cell = cells.get("A23") | |
| cell.put_value("Elvis") | |
| cell = cells.get("A24") | |
| cell.put_value("Elvis") | |
| cell = cells.get("A25") | |
| cell.put_value("Jean") | |
| cell = cells.get("A26") | |
| cell.put_value("Jean") | |
| cell = cells.get("A27") | |
| cell.put_value("Jean") | |
| cell = cells.get("A28") | |
| cell.put_value("Ada") | |
| cell = cells.get("A29") | |
| cell.put_value("Ada") | |
| cell = cells.get("A30") | |
| cell.put_value("Ada") | |
| cell = cells.get("B2") | |
| cell.put_value("1") | |
| cell = cells.get("B3") | |
| cell.put_value("2") | |
| cell = cells.get("B4") | |
| cell.put_value("3") | |
| cell = cells.get("B5") | |
| cell.put_value("4") | |
| cell = cells.get("B6") | |
| cell.put_value("1") | |
| cell = cells.get("B7") | |
| cell.put_value("2") | |
| cell = cells.get("B8") | |
| cell.put_value("3") | |
| cell = cells.get("B9") | |
| cell.put_value("4") | |
| cell = cells.get("B10") | |
| cell.put_value("4") | |
| cell = cells.get("B11") | |
| cell.put_value("1") | |
| cell = cells.get("B12") | |
| cell.put_value("1") | |
| cell = cells.get("B13") | |
| cell.put_value("2") | |
| cell = cells.get("B14") | |
| cell.put_value("2") | |
| cell = cells.get("B15") | |
| cell.put_value("3") | |
| cell = cells.get("B16") | |
| cell.put_value("4") | |
| cell = cells.get("B17") | |
| cell.put_value("4") | |
| cell = cells.get("B18") | |
| cell.put_value("1") | |
| cell = cells.get("B19") | |
| cell.put_value("1") | |
| cell = cells.get("B20") | |
| cell.put_value("2") | |
| cell = cells.get("B21") | |
| cell.put_value("3") | |
| cell = cells.get("B22") | |
| cell.put_value("3") | |
| cell = cells.get("B23") | |
| cell.put_value("4") | |
| cell = cells.get("B24") | |
| cell.put_value("4") | |
| cell = cells.get("B25") | |
| cell.put_value("1") | |
| cell = cells.get("B26") | |
| cell.put_value("2") | |
| cell = cells.get("B27") | |
| cell.put_value("3") | |
| cell = cells.get("B28") | |
| cell.put_value("1") | |
| cell = cells.get("B29") | |
| cell.put_value("2") | |
| cell = cells.get("B30") | |
| cell.put_value("3") | |
| cell = cells.get("C2") | |
| cell.put_value("Maxilaku") | |
| cell = cells.get("C3") | |
| cell.put_value("Maxilaku") | |
| cell = cells.get("C4") | |
| cell.put_value("Chai") | |
| cell = cells.get("C5") | |
| cell.put_value("Maxilaku") | |
| cell = cells.get("C6") | |
| cell.put_value("Chang") | |
| cell = cells.get("C7") | |
| cell.put_value("Chang") | |
| cell = cells.get("C8") | |
| cell.put_value("Chang") | |
| cell = cells.get("C9") | |
| cell.put_value("Chang") | |
| cell = cells.get("C10") | |
| cell.put_value("Chang") | |
| cell = cells.get("C11") | |
| cell.put_value("Geitost") | |
| cell = cells.get("C12") | |
| cell.put_value("Chai") | |
| cell = cells.get("C13") | |
| cell.put_value("Geitost") | |
| cell = cells.get("C14") | |
| cell.put_value("Geitost") | |
| cell = cells.get("C15") | |
| cell.put_value("Maxilaku") | |
| cell = cells.get("C16") | |
| cell.put_value("Geitost") | |
| cell = cells.get("C17") | |
| cell.put_value("Geitost") | |
| cell = cells.get("C18") | |
| cell.put_value("Ikuru") | |
| cell = cells.get("C19") | |
| cell.put_value("Ikuru") | |
| cell = cells.get("C20") | |
| cell.put_value("Ikuru") | |
| cell = cells.get("C21") | |
| cell.put_value("Ikuru") | |
| cell = cells.get("C22") | |
| cell.put_value("Ipoh Coffee") | |
| cell = cells.get("C23") | |
| cell.put_value("Ipoh Coffee") | |
| cell = cells.get("C24") | |
| cell.put_value("Ipoh Coffee") | |
| cell = cells.get("C25") | |
| cell.put_value("Chocolade") | |
| cell = cells.get("C26") | |
| cell.put_value("Chocolade") | |
| cell = cells.get("C27") | |
| cell.put_value("Chocolade") | |
| cell = cells.get("C28") | |
| cell.put_value("Chocolade") | |
| cell = cells.get("C29") | |
| cell.put_value("Chocolade") | |
| cell = cells.get("C30") | |
| cell.put_value("Chocolade") | |
| cell = cells.get("D2") | |
| cell.put_value("Asia") | |
| cell = cells.get("D3") | |
| cell.put_value("Asia") | |
| cell = cells.get("D4") | |
| cell.put_value("Asia") | |
| cell = cells.get("D5") | |
| cell.put_value("Asia") | |
| cell = cells.get("D6") | |
| cell.put_value("Europe") | |
| cell = cells.get("D7") | |
| cell.put_value("Europe") | |
| cell = cells.get("D8") | |
| cell.put_value("Europe") | |
| cell = cells.get("D9") | |
| cell.put_value("Europe") | |
| cell = cells.get("D10") | |
| cell.put_value("Europe") | |
| cell = cells.get("D11") | |
| cell.put_value("America") | |
| cell = cells.get("D12") | |
| cell.put_value("America") | |
| cell = cells.get("D13") | |
| cell.put_value("America") | |
| cell = cells.get("D14") | |
| cell.put_value("America") | |
| cell = cells.get("D15") | |
| cell.put_value("America") | |
| cell = cells.get("D16") | |
| cell.put_value("America") | |
| cell = cells.get("D17") | |
| cell.put_value("America") | |
| cell = cells.get("D18") | |
| cell.put_value("Europe") | |
| cell = cells.get("D19") | |
| cell.put_value("Europe") | |
| cell = cells.get("D20") | |
| cell.put_value("Europe") | |
| cell = cells.get("D21") | |
| cell.put_value("Oceania") | |
| cell = cells.get("D22") | |
| cell.put_value("Oceania") | |
| cell = cells.get("D23") | |
| cell.put_value("Oceania") | |
| cell = cells.get("D24") | |
| cell.put_value("Oceania") | |
| cell = cells.get("D25") | |
| cell.put_value("Africa") | |
| cell = cells.get("D26") | |
| cell.put_value("Africa") | |
| cell = cells.get("D27") | |
| cell.put_value("Africa") | |
| cell = cells.get("D28") | |
| cell.put_value("Africa") | |
| cell = cells.get("D29") | |
| cell.put_value("Africa") | |
| cell = cells.get("D30") | |
| cell.put_value("Africa") | |
| cell = cells.get("E2") | |
| cell.put_value("China") | |
| cell = cells.get("E3") | |
| cell.put_value("India") | |
| cell = cells.get("E4") | |
| cell.put_value("Korea") | |
| cell = cells.get("E5") | |
| cell.put_value("India") | |
| cell = cells.get("E6") | |
| cell.put_value("France") | |
| cell = cells.get("E7") | |
| cell.put_value("France") | |
| cell = cells.get("E8") | |
| cell.put_value("Germany") | |
| cell = cells.get("E9") | |
| cell.put_value("Italy") | |
| cell = cells.get("E10") | |
| cell.put_value("France") | |
| cell = cells.get("E11") | |
| cell.put_value("U.S.") | |
| cell = cells.get("E12") | |
| cell.put_value("U.S.") | |
| cell = cells.get("E13") | |
| cell.put_value("Brazil") | |
| cell = cells.get("E14") | |
| cell.put_value("U.S.") | |
| cell = cells.get("E15") | |
| cell.put_value("U.S.") | |
| cell = cells.get("E16") | |
| cell.put_value("Canada") | |
| cell = cells.get("E17") | |
| cell.put_value("U.S.") | |
| cell = cells.get("E18") | |
| cell.put_value("Italy") | |
| cell = cells.get("E19") | |
| cell.put_value("France") | |
| cell = cells.get("E20") | |
| cell.put_value("Italy") | |
| cell = cells.get("E21") | |
| cell.put_value("New Zealand") | |
| cell = cells.get("E22") | |
| cell.put_value("Australia") | |
| cell = cells.get("E23") | |
| cell.put_value("Australia") | |
| cell = cells.get("E24") | |
| cell.put_value("New Zealand") | |
| cell = cells.get("E25") | |
| cell.put_value("S.Africa") | |
| cell = cells.get("E26") | |
| cell.put_value("S.Africa") | |
| cell = cells.get("E27") | |
| cell.put_value("S.Africa") | |
| cell = cells.get("E28") | |
| cell.put_value("Egypt") | |
| cell = cells.get("E29") | |
| cell.put_value("Egypt") | |
| cell = cells.get("E30") | |
| cell.put_value("Egypt") | |
| cell = cells.get("F2") | |
| cell.put_value(2000) | |
| cell = cells.get("F3") | |
| cell.put_value(500) | |
| cell = cells.get("F4") | |
| cell.put_value(1200) | |
| cell = cells.get("F5") | |
| cell.put_value(1500) | |
| cell = cells.get("F6") | |
| cell.put_value(500) | |
| cell = cells.get("F7") | |
| cell.put_value(1500) | |
| cell = cells.get("F8") | |
| cell.put_value(800) | |
| cell = cells.get("F9") | |
| cell.put_value(900) | |
| cell = cells.get("F10") | |
| cell.put_value(500) | |
| cell = cells.get("F11") | |
| cell.put_value(1600) | |
| cell = cells.get("F12") | |
| cell.put_value(600) | |
| cell = cells.get("F13") | |
| cell.put_value(2000) | |
| cell = cells.get("F14") | |
| cell.put_value(500) | |
| cell = cells.get("F15") | |
| cell.put_value(900) | |
| cell = cells.get("F16") | |
| cell.put_value(700) | |
| cell = cells.get("F17") | |
| cell.put_value(1400) | |
| cell = cells.get("F18") | |
| cell.put_value(1350) | |
| cell = cells.get("F19") | |
| cell.put_value(300) | |
| cell = cells.get("F20") | |
| cell.put_value(500) | |
| cell = cells.get("F21") | |
| cell.put_value(1000) | |
| cell = cells.get("F22") | |
| cell.put_value(1500) | |
| cell = cells.get("F23") | |
| cell.put_value(1500) | |
| cell = cells.get("F24") | |
| cell.put_value(1600) | |
| cell = cells.get("F25") | |
| cell.put_value(1000) | |
| cell = cells.get("F26") | |
| cell.put_value(1200) | |
| cell = cells.get("F27") | |
| cell.put_value(1300) | |
| cell = cells.get("F28") | |
| cell.put_value(1500) | |
| cell = cells.get("F29") | |
| cell.put_value(1400) | |
| cell = cells.get("F30") | |
| cell.put_value(1000) | |
| # Adding a new sheet | |
| sheet2 = workbook.worksheets[workbook.worksheets.add()] | |
| # Naming the sheet | |
| sheet2.name = "PivotTable" | |
| # Getting the pivottables collection in the sheet | |
| pivotTables = sheet2.pivot_tables | |
| # Adding a PivotTable to the worksheet | |
| index = pivotTables.add("=Data!A1:F30", "B3", "PivotTable1") | |
| # Accessing the instance of the newly added PivotTable | |
| pivotTable = pivotTables[index] | |
| # Showing the grand totals | |
| pivotTable.row_grand = True | |
| pivotTable.column_grand = True | |
| # Setting the PivotTable report is automatically formatted | |
| pivotTable.is_auto_format = True | |
| # Setting the PivotTable autoformat type. | |
| pivotTable.auto_format_type = PivotTableAutoFormatType.REPORT6 | |
| # Draging the first field to the row area. | |
| pivotTable.add_field_to_area(PivotFieldType.ROW, 0) | |
| # Draging the third field to the row area. | |
| pivotTable.add_field_to_area(PivotFieldType.ROW, 2) | |
| # Draging the second field to the row area. | |
| pivotTable.add_field_to_area(PivotFieldType.ROW, 1) | |
| # Draging the fourth field to the column area. | |
| pivotTable.add_field_to_area(PivotFieldType.COLUMN, 3) | |
| # Draging the fifth field to the data area. | |
| pivotTable.add_field_to_area(PivotFieldType.DATA, 5) | |
| # Setting the number format of the first data field | |
| pivotTable.data_fields[0].number_format = "$#,##0.00" | |
| # Saving the Excel file | |
| workbook.save(dataDir + "pivotTable_test.out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType, FormattingType | |
| from aspose.pydrawing import Color | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create an instance of Workbook | |
| workbook = Workbook() | |
| # Retrieve the first Worksheet in Workbook | |
| worksheet = workbook.worksheets[0] | |
| # Retrieve the Cells of the first Worksheet | |
| cells = worksheet.cells | |
| # Input some data which chart will use as source | |
| cells.get("A1").put_value("Previous Year") | |
| cells.get("A2").put_value("January") | |
| cells.get("A3").put_value("March") | |
| cells.get("A4").put_value("August") | |
| cells.get("A5").put_value("October") | |
| cells.get("A6").put_value("Current Year") | |
| cells.get("B1").put_value(8.5) | |
| cells.get("B2").put_value(1.5) | |
| cells.get("B3").put_value(7.5) | |
| cells.get("B4").put_value(7.5) | |
| cells.get("B5").put_value(8.5) | |
| cells.get("B6").put_value(3.5) | |
| cells.get("C1").put_value(1.5) | |
| cells.get("C2").put_value(4.5) | |
| cells.get("C3").put_value(3.5) | |
| cells.get("C4").put_value(9.5) | |
| cells.get("C5").put_value(7.5) | |
| cells.get("C6").put_value(9.5) | |
| # Add a Chart of type Line in same worksheet as of data | |
| idx = worksheet.charts.add(ChartType.LINE, 4, 4, 25, 13) | |
| # Retrieve the Chart object | |
| chart = worksheet.charts[idx] | |
| # Add Series | |
| chart.n_series.add("$B$1:$C$6", True) | |
| # Add Category Data | |
| chart.n_series.category_data = "$A$1:$A$6" | |
| # Series has Up Down Bars | |
| chart.n_series[0].has_up_down_bars = True | |
| # Set the colors of Up and Down Bars | |
| chart.n_series[0].up_bars.area.foreground_color = Color.green | |
| chart.n_series[0].down_bars.area.foreground_color = Color.red | |
| # Make both Series Lines invisible | |
| chart.n_series[0].border.is_visible = False | |
| chart.n_series[1].border.is_visible = False | |
| # Set the Plot Area Formatting Automatic | |
| chart.plot_area.area.formatting = FormattingType.AUTOMATIC | |
| # Delete the Legend | |
| chart.legend.legend_entries[0].is_deleted = True | |
| chart.legend.legend_entries[1].is_deleted = True | |
| # Save the workbook | |
| workbook.save(dataDir + "output_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import FileFormatType, Workbook | |
| from aspose.cells.charts import ChartType, DataLabelsSeparatorType, LabelPositionType | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create an instance of Workbook in XLSX format | |
| workbook = Workbook(FileFormatType.XLSX) | |
| # Access the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Add two columns of data | |
| worksheet.cells.get("A1").put_value("Retail") | |
| worksheet.cells.get("A2").put_value("Services") | |
| worksheet.cells.get("A3").put_value("Info & Communication") | |
| worksheet.cells.get("A4").put_value("Transport Equip") | |
| worksheet.cells.get("A5").put_value("Construction") | |
| worksheet.cells.get("A6").put_value("Other Products") | |
| worksheet.cells.get("A7").put_value("Wholesale") | |
| worksheet.cells.get("A8").put_value("Land Transport") | |
| worksheet.cells.get("A9").put_value("Air Transport") | |
| worksheet.cells.get("A10").put_value("Electric Appliances") | |
| worksheet.cells.get("A11").put_value("Securities") | |
| worksheet.cells.get("A12").put_value("Textiles & Apparel") | |
| worksheet.cells.get("A13").put_value("Machinery") | |
| worksheet.cells.get("A14").put_value("Metal Products") | |
| worksheet.cells.get("A15").put_value("Cash") | |
| worksheet.cells.get("A16").put_value("Banks") | |
| worksheet.cells.get("B1").put_value(10.4) | |
| worksheet.cells.get("B2").put_value(5.2) | |
| worksheet.cells.get("B3").put_value(6.4) | |
| worksheet.cells.get("B4").put_value(10.4) | |
| worksheet.cells.get("B5").put_value(7.9) | |
| worksheet.cells.get("B6").put_value(4.1) | |
| worksheet.cells.get("B7").put_value(3.5) | |
| worksheet.cells.get("B8").put_value(5.7) | |
| worksheet.cells.get("B9").put_value(3) | |
| worksheet.cells.get("B10").put_value(14.7) | |
| worksheet.cells.get("B11").put_value(3.6) | |
| worksheet.cells.get("B12").put_value(2.8) | |
| worksheet.cells.get("B13").put_value(7.8) | |
| worksheet.cells.get("B14").put_value(2.4) | |
| worksheet.cells.get("B15").put_value(1.8) | |
| worksheet.cells.get("B16").put_value(10.1) | |
| # Create a pie chart and add it to the collection of charts | |
| id = worksheet.charts.add(ChartType.PIE, 3, 3, 23, 13) | |
| # Access newly created Chart instance | |
| chart = worksheet.charts[id] | |
| # Set series data range | |
| chart.n_series.add("B1:B16", True) | |
| # Set category data range | |
| chart.n_series.category_data = "A1:A16" | |
| # Turn off legend | |
| chart.show_legend = False | |
| # Access data labels | |
| dataLabels = chart.n_series[0].data_labels | |
| # Turn on category names | |
| dataLabels.show_category_name = True | |
| # Turn on percentage format | |
| dataLabels.show_percentage = True | |
| # Set position | |
| dataLabels.position = LabelPositionType.OUTSIDE_END | |
| # Set separator | |
| dataLabels.separator_type = DataLabelsSeparatorType.COMMA |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import SaveFormat, Workbook | |
| from aspose.cells.charts import ChartType, LegendPositionType | |
| from aspose.pydrawing import Color | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create a workbook object from the template file | |
| workbook = Workbook() | |
| # Access the first worksheet. | |
| worksheet = workbook.worksheets[0] | |
| # Put the sample values used in a pie chart | |
| worksheet.cells.get("C3").put_value("India") | |
| worksheet.cells.get("C4").put_value("China") | |
| worksheet.cells.get("C5").put_value("United States") | |
| worksheet.cells.get("C6").put_value("Russia") | |
| worksheet.cells.get("C7").put_value("United Kingdom") | |
| worksheet.cells.get("C8").put_value("Others") | |
| # Put the sample values used in a pie chart | |
| worksheet.cells.get("D2").put_value("% of world population") | |
| worksheet.cells.get("D3").put_value(25) | |
| worksheet.cells.get("D4").put_value(30) | |
| worksheet.cells.get("D5").put_value(10) | |
| worksheet.cells.get("D6").put_value(13) | |
| worksheet.cells.get("D7").put_value(9) | |
| worksheet.cells.get("D8").put_value(13) | |
| # Create a pie chart with desired length and width | |
| pieIdx = worksheet.charts.add(ChartType.PIE, 1, 6, 15, 14) | |
| # Access the pie chart | |
| pie = worksheet.charts[pieIdx] | |
| # Set the pie chart series | |
| pie.n_series.add("D3:D8", True) | |
| # Set the category data | |
| pie.n_series.category_data = "=Sheet1!$C$3:$C$8" | |
| # Set the chart title that is linked to cell D2 | |
| pie.title.linked_source = "D2" | |
| # Set the legend position at the bottom. | |
| pie.legend.position = LegendPositionType.BOTTOM | |
| # Set the chart title's font name and color | |
| pie.title.font.name = "Calibri" | |
| pie.title.font.size = 18 | |
| # Access the chart series | |
| srs = pie.n_series[0] | |
| # Color the indvidual points with custom colors | |
| srs.points[0].area.foreground_color = Color.from_argb(0, 246, 22, 219) | |
| srs.points[1].area.foreground_color = Color.from_argb(0, 51, 34, 84) | |
| srs.points[2].area.foreground_color = Color.from_argb(0, 46, 74, 44) | |
| srs.points[3].area.foreground_color = Color.from_argb(0, 19, 99, 44) | |
| srs.points[4].area.foreground_color = Color.from_argb(0, 208, 223, 7) | |
| srs.points[5].area.foreground_color = Color.from_argb(0, 222, 69, 8) | |
| # Autofit all columns | |
| worksheet.auto_fit_columns() | |
| dataDir = dataDir + "output.out.xlsx" | |
| # Save the workbook | |
| workbook.save(dataDir, SaveFormat.XLSX) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType | |
| # Create an instance of Workbook | |
| workbook = Workbook() | |
| # Get the First sheet. | |
| sheet = workbook.worksheets.get("Sheet1") | |
| # Add data into details cells. | |
| sheet.cells.get(0, 0).put_value("Fruits Name") | |
| sheet.cells.get(0, 1).put_value("Fruits Price") | |
| sheet.cells.get(1, 0).put_value("Apples") | |
| sheet.cells.get(2, 0).put_value("Bananas") | |
| sheet.cells.get(3, 0).put_value("Grapes") | |
| sheet.cells.get(4, 0).put_value("Oranges") | |
| sheet.cells.get(1, 1).put_value(5) | |
| sheet.cells.get(2, 1).put_value(2) | |
| sheet.cells.get(3, 1).put_value(1) | |
| sheet.cells.get(4, 1).put_value(4) | |
| # Add a chart to the worksheet | |
| chartIndex = sheet.charts.add(ChartType.COLUMN, 7, 7, 15, 15) | |
| # Access the instance of the newly added chart | |
| chart = sheet.charts[chartIndex] | |
| # Set data range | |
| chart.set_chart_data_range("A1:B5", True) | |
| # Set AutoFilter range | |
| sheet.auto_filter.range = "A1:B5" | |
| # Add filters for a filter column. | |
| sheet.auto_filter.add_filter(0, "Bananas") | |
| sheet.auto_filter.add_filter(0, "Oranges") | |
| # Apply the filters | |
| sheet.auto_filter.refresh() | |
| chart.to_image("Autofilter.png") | |
| workbook.save("Autofilter.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType, LabelPositionType | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Workbook object | |
| sheetIndex = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[sheetIndex] | |
| # Adding sample values to cells | |
| worksheet.cells.get("A1").put_value(50) | |
| worksheet.cells.get("A2").put_value(100) | |
| worksheet.cells.get("A3").put_value(150) | |
| worksheet.cells.get("B1").put_value(60) | |
| worksheet.cells.get("B2").put_value(32) | |
| worksheet.cells.get("B3").put_value(50) | |
| # Adding a chart to the worksheet | |
| chartIndex = worksheet.charts.add(ChartType.COLUMN, 5, 0, 15, 5) | |
| # Accessing the instance of the newly added chart | |
| chart = worksheet.charts[chartIndex] | |
| # Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3" | |
| chart.n_series.add("A1:B3", True) | |
| # Show value labels | |
| chart.n_series[0].data_labels.show_value = True | |
| # Show series name labels | |
| chart.n_series[1].data_labels.show_series_name = True | |
| # Move labels to center | |
| chart.n_series[1].data_labels.position = LabelPositionType.CENTER | |
| # Save the file | |
| workbook.save("chart_datalabels.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import CategoryType, ChartTextDirectionType, ChartType, TimeUnit | |
| from aspose.cells.drawing import FillType | |
| from datetime import datetime | |
| # Create an instance of Workbook | |
| workbook = Workbook() | |
| # Get the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Add the sample values to cells | |
| worksheet.cells.get("A1").put_value("Date") | |
| # 14 means datetime format | |
| style = worksheet.cells.style | |
| style.number = 14 | |
| # Put values to cells for creating chart | |
| worksheet.cells.get("A2").set_style(style) | |
| worksheet.cells.get("A2").put_value(datetime(2022, 6, 26)) | |
| worksheet.cells.get("A3").set_style(style) | |
| worksheet.cells.get("A3").put_value(datetime(2022, 5, 22)) | |
| worksheet.cells.get("A4").set_style(style) | |
| worksheet.cells.get("A4").put_value(datetime(2022, 8, 3)) | |
| worksheet.cells.get("B1").put_value("Price") | |
| worksheet.cells.get("B2").put_value(40) | |
| worksheet.cells.get("B3").put_value(50) | |
| worksheet.cells.get("B4").put_value(60) | |
| # Adda chart to the worksheet | |
| chartIndex = worksheet.charts.add(ChartType.COLUMN, 9, 6, 21, 13) | |
| # Access the instance of the newly added chart | |
| chart = worksheet.charts[chartIndex] | |
| # Add SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B4" | |
| chart.set_chart_data_range("A1:B4", True) | |
| # Set the Axis type to Date time | |
| chart.category_axis.category_type = CategoryType.TIME_SCALE | |
| # Set the base unit for CategoryAxis to days | |
| chart.category_axis.base_unit_scale = TimeUnit.DAYS | |
| # Set the direction for the axis text to be vertical | |
| chart.category_axis.tick_labels.direction_type = ChartTextDirectionType.VERTICAL | |
| # Fill the PlotArea area with nothing | |
| chart.plot_area.area.fill_format.fill_type = FillType.NONE | |
| # Set max value of Y axis. | |
| chart.value_axis.max_value = 70 | |
| # Set major unit. | |
| chart.value_axis.major_unit = 10.0 | |
| # Save the file | |
| workbook.save("DateAxis.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import AxisType | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create workbook object | |
| workbook = Workbook(dataDir + "source.xlsx") | |
| # Access the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Access the chart | |
| chart = worksheet.charts[0] | |
| # Determine which axis exists in chart | |
| ret = chart.has_axis(AxisType.CATEGORY, True) | |
| print("Has Primary Category Axis: " + str(ret)) | |
| ret = chart.has_axis(AxisType.CATEGORY, False) | |
| print("Has Secondary Category Axis: " + str(ret)) | |
| ret = chart.has_axis(AxisType.VALUE, True) | |
| print("Has Primary Value Axis: " + str(ret)) | |
| ret = chart.has_axis(AxisType.VALUE, False) | |
| print("Has Secondary Value Axis: " + str(ret)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Load the sample Excel file inside the workbook object | |
| workbook = Workbook(dataDir + "sample.xlsx") | |
| # Access the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Access the first chart inside the worksheet | |
| chart = worksheet.charts[0] | |
| # Disable the Text Wrapping of Data Labels in all Series | |
| chart.n_series[0].data_labels.is_text_wrapped = False | |
| chart.n_series[1].data_labels.is_text_wrapped = False | |
| chart.n_series[2].data_labels.is_text_wrapped = False | |
| # Save the workbook | |
| workbook.save(dataDir + "Output_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import FileFormatType, SaveFormat, Workbook | |
| from aspose.cells.charts import ChartType | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create new workbook | |
| workbook = Workbook(FileFormatType.XLSX) | |
| # Access first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Add data for chart | |
| # Category Axis Values | |
| worksheet.cells.get("A2").put_value("C1") | |
| worksheet.cells.get("A3").put_value("C2") | |
| worksheet.cells.get("A4").put_value("C3") | |
| # First vertical series | |
| worksheet.cells.get("B1").put_value("T1") | |
| worksheet.cells.get("B2").put_value(6) | |
| worksheet.cells.get("B3").put_value(3) | |
| worksheet.cells.get("B4").put_value(2) | |
| # Second vertical series | |
| worksheet.cells.get("C1").put_value("T2") | |
| worksheet.cells.get("C2").put_value(7) | |
| worksheet.cells.get("C3").put_value(2) | |
| worksheet.cells.get("C4").put_value(5) | |
| # Third vertical series | |
| worksheet.cells.get("D1").put_value("T3") | |
| worksheet.cells.get("D2").put_value(8) | |
| worksheet.cells.get("D3").put_value(4) | |
| worksheet.cells.get("D4").put_value(2) | |
| # Create Column chart with easy way | |
| idx = worksheet.charts.add(ChartType.COLUMN, 6, 5, 20, 13) | |
| ch = worksheet.charts[idx] | |
| ch.set_chart_data_range("A1:D4", True) | |
| # Save the workbook | |
| workbook.save(dataDir + "output_out.xlsx", SaveFormat.XLSX) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import SaveFormat, Workbook | |
| from aspose.cells.rendering import ImageOrPrintOptions | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create workbook object from source file | |
| workbook = Workbook(dataDir + "SampleChartBook.xlsx") | |
| # Access first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Access first chart inside the worksheet | |
| chart = worksheet.charts[0] | |
| # Set image or print options with SVGFitToViewPort true | |
| opts = ImageOrPrintOptions() | |
| opts.save_format = SaveFormat.SVG | |
| opts.svg_fit_to_view_port = True | |
| # Save the chart to svg format | |
| chart.to_image(dataDir + "Image_out.svg", opts) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Load source excel file containing Bar of Pie chart | |
| wb = Workbook(dataDir + "PieBars.xlsx") | |
| # Access first worksheet | |
| ws = wb.worksheets[0] | |
| # Access first chart which is Bar of Pie chart and calculate it | |
| ch = ws.charts[0] | |
| ch.calculate() | |
| # Access the chart series | |
| srs = ch.n_series[0] | |
| /* | |
| * Print the data points of the chart series and | |
| * check its IsInSecondaryPlot property to determine | |
| * if data point is inside the bar or pie | |
| */ | |
| for i in range(srs.points.count): | |
| # Access chart point | |
| cp = srs.points[i] | |
| # Skip null values | |
| if cp.y_value == None: | |
| continue | |
| /* | |
| * Print the chart point value and see if it is inside bar or pie. | |
| * If the IsInSecondaryPlot is true, then the data point is inside bar | |
| * otherwise it is inside the pie. | |
| */ | |
| print("Value: " + str(cp.y_value)) | |
| print("IsInSecondaryPlot: " + str(cp.is_in_secondary_plot)) | |
| print() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Source directory | |
| sourceDir = "./" | |
| # Load sample Excel file containing chart. | |
| wb = Workbook(sourceDir + "sampleFindTypeOfXandYValuesOfPointsInChartSeries.xlsx") | |
| # Access first worksheet. | |
| ws = wb.worksheets[0] | |
| # Access first chart. | |
| ch = ws.charts[0] | |
| # Calculate chart data. | |
| ch.calculate() | |
| # Access first chart point in the first series. | |
| pnt = ch.n_series[0].points[0] | |
| # Print the types of X and Y values of chart point. | |
| print("X Value Type: " + str(pnt.x_value_type)) | |
| print("Y Value Type: " + str(pnt.y_value_type)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Source directory | |
| sourceDir = "./" | |
| # Load excel file containing charts | |
| workbook = Workbook(sourceDir + "SampleChart.ods") | |
| # Access first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Access first chart inside the worksheet | |
| chart = worksheet.charts[0] | |
| print("Chart Subtitle: " + chart.sub_title.text) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create workbook object from source Excel file | |
| workbook = Workbook(dataDir + "source.xlsx") | |
| # Access the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Access the first chart inside the worksheet | |
| chart = worksheet.charts[0] | |
| # Calculate the Chart first to get the Equation Text of Trendline | |
| chart.calculate() | |
| # Access the Trendline | |
| trendLine = chart.n_series[0].trend_lines[0] | |
| # Read the Equation Text of Trendline | |
| print("Equation Text: " + trendLine.data_labels.text) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create workbook from sample Excel file | |
| workbook = Workbook(dataDir + "sample.xlsx") | |
| # Access first worksheet of the workbook | |
| worksheet = workbook.worksheets[0] | |
| # Print worksheet name | |
| print("Sheet Name: " + worksheet.name) | |
| # Access the first chart inside this worksheet | |
| chart = worksheet.charts[0] | |
| # Access the chart's sheet and display its name again | |
| print("Chart's Sheet Name: " + chart.worksheet.name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Load the sample Excel file | |
| wb = Workbook("sampleHandleAutomaticUnitsOfChartAxisLikeMicrosoftExcel.xlsx") | |
| # Access first worksheet | |
| ws = wb.worksheets[0] | |
| # Access first chart | |
| ch = ws.charts[0] | |
| # Render chart to pdf | |
| ch.to_pdf("outputHandleAutomaticUnitsOfChartAxisLikeMicrosoftExcel.pdf") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Excel object | |
| sheetIndex = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[sheetIndex] | |
| # Adding sample values to cells | |
| worksheet.cells.get("A1").put_value(50) | |
| worksheet.cells.get("A2").put_value(100) | |
| worksheet.cells.get("A3").put_value(150) | |
| worksheet.cells.get("B1").put_value(4) | |
| worksheet.cells.get("B2").put_value(20) | |
| worksheet.cells.get("B3").put_value(50) | |
| # Adding a chart to the worksheet | |
| chartIndex = worksheet.charts.add(ChartType.PYRAMID, 5, 0, 15, 5) | |
| # Accessing the instance of the newly added chart | |
| chart = worksheet.charts[chartIndex] | |
| # Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3" | |
| chart.n_series.add("A1:B3", True) | |
| # Saving the Excel file | |
| workbook.save(dataDir + "book1.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.drawing import PlacementType | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Open the existing file. | |
| workbook = Workbook(dataDir + "chart.xls") | |
| # Get the designer chart in the second sheet. | |
| sheet = workbook.worksheets[1] | |
| chart = sheet.charts[0] | |
| # Add a new label to the chart. | |
| label = chart.shapes.add_label_in_chart(100, 100, 350, 900) | |
| # Set the caption of the label. | |
| label.text = "A Label In Chart" | |
| # Set the Placement Type, the way the | |
| # Label is attached to the cells. | |
| label.placement = PlacementType.FREE_FLOATING | |
| # Save the excel file. | |
| workbook.save(dataDir + "chart.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.drawing import MsoLineDashStyle | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Open the existing file. | |
| workbook = Workbook(dataDir + "chart.xls") | |
| # Get an image file to the stream. | |
| stream = open(dataDir + "logo.jpg", "rb") | |
| # Get the designer chart in the second sheet. | |
| sheet = workbook.worksheets[0] | |
| chart = sheet.charts[0] | |
| # Add a new picture to the chart. | |
| pic0 = chart.shapes.add_picture_in_chart(50, 50, stream, 40, 40) | |
| # Get the lineformat type of the picture. | |
| lineformat = pic0.line | |
| # Set the dash style. | |
| lineformat.dash_style = MsoLineDashStyle.SOLID | |
| # Set the line weight. | |
| lineformat.weight = 4.0 | |
| # Save the excel file. | |
| workbook.save(dataDir + "chart.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.drawing import MsoLineDashStyle | |
| from aspose.pydrawing import Color | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Open the existing file. | |
| workbook = Workbook(dataDir + "chart.xls") | |
| # Get the designer chart in the second sheet. | |
| sheet = workbook.worksheets[1] | |
| chart = sheet.charts[0] | |
| # Add a new textbox to the chart. | |
| textbox0 = chart.shapes.add_text_box_in_chart(100, 1100, 350, 2550) | |
| # Fill the text. | |
| textbox0.text = "Sales By Region" | |
| # Get the textbox text frame. | |
| # Aspose.Cells.Drawing.MsoTextFrame textframe0 = textbox0.TextFrame; | |
| # Set the textbox to adjust it according to its contents. | |
| # textframe0.AutoSize = true; | |
| # Set the font color. | |
| textbox0.font.color = Color.maroon | |
| # Set the font to bold. | |
| textbox0.font.is_bold = True | |
| # Set the font size. | |
| textbox0.font.size = 14 | |
| # Set font attribute to italic. | |
| textbox0.font.is_italic = True | |
| # Get the filformat of the textbox. | |
| fillformat = textbox0.fill | |
| # Get the lineformat type of the textbox. | |
| lineformat = textbox0.line | |
| # Set the line weight. | |
| lineformat.weight = 2.0 | |
| # Set the dash style to solid. | |
| lineformat.dash_style = MsoLineDashStyle.SOLID | |
| # Save the excel file. | |
| workbook.save(dataDir + "chart.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import SheetType, Workbook | |
| from aspose.cells.charts import ChartType | |
| from aspose.cells.drawing import MsoDrawingType, PlacementType | |
| # Output directory | |
| outputDir = "./" | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a chart to the worksheet | |
| index = workbook.worksheets.add(SheetType.CHART) | |
| sheet = workbook.worksheets[index] | |
| sheet.charts.add_floating_chart(ChartType.COLUMN, 0, 0, 1024, 960) | |
| sheet.charts[0].n_series.add("{1,2,3}", False) | |
| # Add checkbox to the chart. | |
| sheet.charts[0].shapes.add_shape_in_chart(MsoDrawingType.CHECK_BOX, PlacementType.MOVE, 400, 400, 1000, 600) | |
| sheet.charts[0].shapes[0].text = "CheckBox 1" | |
| # Save the excel file. | |
| workbook.save(outputDir + "InsertCheckboxInChartSheet_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Obtaining the reference of the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Adding sample values to cells | |
| worksheet.cells.get("A2").put_value("Category1") | |
| worksheet.cells.get("A3").put_value("Category2") | |
| worksheet.cells.get("A4").put_value("Category3") | |
| worksheet.cells.get("B1").put_value("Column1") | |
| worksheet.cells.get("B2").put_value(4) | |
| worksheet.cells.get("B3").put_value(20) | |
| worksheet.cells.get("B4").put_value(50) | |
| worksheet.cells.get("C1").put_value("Column2") | |
| worksheet.cells.get("C2").put_value(50) | |
| worksheet.cells.get("C3").put_value(100) | |
| worksheet.cells.get("C4").put_value(150) | |
| # Adding a chart to the worksheet | |
| chartIndex = worksheet.charts.add(ChartType.COLUMN, 5, 0, 15, 5) | |
| # Accessing the instance of the newly added chart | |
| chart = worksheet.charts[chartIndex] | |
| # Setting chart data source as the range "A1:C4" | |
| chart.set_chart_data_range("A1:C4", True) | |
| # Saving the Excel file | |
| workbook.save(dataDir + "output.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Workbook object | |
| sheetIndex = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[sheetIndex] | |
| # Adding sample values to cells | |
| worksheet.cells.get("A1").put_value(50) | |
| worksheet.cells.get("A2").put_value(100) | |
| worksheet.cells.get("A3").put_value(150) | |
| worksheet.cells.get("A4").put_value(110) | |
| worksheet.cells.get("B1").put_value(260) | |
| worksheet.cells.get("B2").put_value(12) | |
| worksheet.cells.get("B3").put_value(50) | |
| worksheet.cells.get("B4").put_value(100) | |
| # Adding a chart to the worksheet | |
| chartIndex = worksheet.charts.add(ChartType.COLUMN, 5, 0, 15, 5) | |
| # Accessing the instance of the newly added chart | |
| chart = worksheet.charts[chartIndex] | |
| # Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B4" | |
| chart.n_series.add("A1:B4", True) | |
| # Setting the chart type of 2nd NSeries to display as line chart | |
| chart.n_series[1].type = ChartType.LINE | |
| # Saving the Excel file | |
| workbook.save(dataDir + "output.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Excel object | |
| sheetIndex = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[sheetIndex] | |
| # Adding sample values to cells | |
| worksheet.cells.get("A1").put_value(50) | |
| worksheet.cells.get("A2").put_value(100) | |
| worksheet.cells.get("A3").put_value(150) | |
| worksheet.cells.get("B1").put_value(4) | |
| worksheet.cells.get("B2").put_value(20) | |
| worksheet.cells.get("B3").put_value(50) | |
| # Adding a chart to the worksheet | |
| chartIndex = worksheet.charts.add(ChartType.LINE, 5, 0, 15, 5) | |
| # Accessing the instance of the newly added chart | |
| chart = worksheet.charts[chartIndex] | |
| # Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3" | |
| chart.n_series.add("A1:B3", True) | |
| # Saving the Excel file | |
| workbook.save(dataDir + "output.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Excel object | |
| sheetIndex = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[sheetIndex] | |
| # Adding sample values to cells | |
| worksheet.cells.get("A1").put_value(50) | |
| worksheet.cells.get("A2").put_value(100) | |
| worksheet.cells.get("A3").put_value(150) | |
| worksheet.cells.get("B1").put_value(4) | |
| worksheet.cells.get("B2").put_value(20) | |
| worksheet.cells.get("B3").put_value(50) | |
| # Adding a chart to the worksheet | |
| chartIndex = worksheet.charts.add(ChartType.PYRAMID, 5, 0, 15, 5) | |
| # Accessing the instance of the newly added chart | |
| chart = worksheet.charts[chartIndex] | |
| # Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3" | |
| chart.n_series.add("A1:B3", True) | |
| # Saving the Excel file | |
| workbook.save(dataDir + "output.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.pydrawing import Color | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Open the existing file. | |
| workbook = Workbook(dataDir + "Book1.xlsx") | |
| # Get the designer chart in the first worksheet. | |
| chart = workbook.worksheets[0].charts[0] | |
| # Add the third data series to it. | |
| chart.n_series.add("{60, 80, 10}", True) | |
| # Add another data series (fourth) to it. | |
| chart.n_series.add("{0.3, 0.7, 1.2}", True) | |
| # Plot the fourth data series on the second axis. | |
| chart.n_series[3].plot_on_second_axis = True | |
| # Change the Border color of the second data series. | |
| chart.n_series[1].border.color = Color.green | |
| # Change the Border color of the third data series. | |
| chart.n_series[2].border.color = Color.red | |
| # Make the second value axis visible. | |
| chart.second_value_axis.is_visible = True | |
| # Save the excel file. | |
| workbook.save(dataDir + "output.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Open the existing file. | |
| workbook = Workbook(dataDir + "piechart.xls") | |
| # Get the designer chart in the second sheet. | |
| sheet = workbook.worksheets[1] | |
| chart = sheet.charts[0] | |
| # Get the data labels in the data series of the third data point. | |
| datalabels = chart.n_series[0].points[2].data_labels | |
| # Change the text of the label. | |
| datalabels.text = "Unided Kingdom, 400K " | |
| # Save the excel file. | |
| workbook.save(dataDir + "output.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # How to manage PivotChart with PivotOptions | |
| path = "" | |
| book = Workbook(path + "Sample.xlsx") | |
| chart = book.worksheets[0].charts[0] | |
| opt = chart.pivot_options | |
| # Hide ZoneFilter in PivotChart | |
| opt.drop_zone_filter = False | |
| # You can set more properties, try them! | |
| # opt.DropZoneCategories = false; # HideZoneCategories | |
| # opt.DropZoneData = false; # HideZoneData | |
| # opt.DropZoneSeries = false; # HideZoneSeries | |
| # opt.DropZonesVisible = false; # Hide All | |
| # Save the file and see the effect. | |
| book.save(path + "HideZoneFilter.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType, LegendPositionType | |
| from aspose.cells.drawing import FillType | |
| # Create an instance of Workbook | |
| workbook = Workbook() | |
| # Access the first worksheet. | |
| worksheet = workbook.worksheets[0] | |
| # Put the sample values used in a chart | |
| worksheet.cells.get("A1").put_value("Region") | |
| worksheet.cells.get("A2").put_value("Peking") | |
| worksheet.cells.get("A3").put_value("New York") | |
| worksheet.cells.get("A4").put_value("Paris") | |
| worksheet.cells.get("B1").put_value("Sales Volume") | |
| worksheet.cells.get("C1").put_value("Growth Rate") | |
| worksheet.cells.get("B2").put_value(100) | |
| worksheet.cells.get("B3").put_value(80) | |
| worksheet.cells.get("B4").put_value(140) | |
| worksheet.cells.get("C2").put_value(0.7) | |
| worksheet.cells.get("C3").put_value(0.8) | |
| worksheet.cells.get("C4").put_value(1.0) | |
| # Create a Scatter chart | |
| pieIdx = worksheet.charts.add(ChartType.SCATTER, 6, 6, 15, 11) | |
| # Retrieve the Chart object | |
| chart = worksheet.charts[pieIdx] | |
| # Add Series | |
| chart.n_series.add("B2:C4", True) | |
| # Set the category data | |
| chart.n_series.category_data = "=Sheet1!$A$2:$A$4" | |
| # Set the Second-Axis | |
| chart.n_series[1].plot_on_second_axis = True | |
| # Show the Second-Axis | |
| chart.second_value_axis.is_visible = True | |
| # Set the second series ChartType to line | |
| chart.n_series[1].type = ChartType.LINE | |
| # Set the series name | |
| chart.n_series[0].name = "Sales Volume" | |
| chart.n_series[1].name = "Growth Rate" | |
| # Set the Legend at the bottom of the chart area | |
| chart.legend.position = LegendPositionType.BOTTOM | |
| # Fill the PlotArea area with nothing | |
| chart.plot_area.area.fill_format.fill_type = FillType.NONE | |
| # Save the file | |
| workbook.save("PrimaryandSecondaryAxis.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Load source excel file containing excel 2016 charts | |
| book = Workbook(dataDir + "excel2016Charts.xlsx") | |
| # Access the first worksheet which contains the charts | |
| sheet = book.worksheets[0] | |
| # Access all charts one by one and read their types | |
| for i in range(len(sheet.charts)): | |
| # Access the chart | |
| ch = sheet.charts[i] | |
| # Print chart type | |
| print(ch.type) | |
| # Change the title of the charts as per their types | |
| ch.title.text = "Chart Type is " + str(ch.type) | |
| # Save the workbook | |
| book.save(dataDir + "out_excel2016Charts.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Load the Excel file containing chart | |
| wb = Workbook("ReadAxisLabels.xlsx") | |
| # Access first worksheet | |
| ws = wb.worksheets[0] | |
| # Access the chart | |
| ch = ws.charts[0] | |
| # Calculate the chart | |
| ch.calculate() | |
| # Read axis labels of category axis | |
| lstLabels = ch.category_axis.get_axis_texts() | |
| # Print axis labels on console | |
| print("Category Axis Labels: ") | |
| print("---------------------") | |
| # Iterate axis labels and print them one by one | |
| for i in range(len(lstLabels)): | |
| print(lstLabels[i]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create an instance of Workbook containing the Chart | |
| book = Workbook(dataDir + "source.xlsx") | |
| # Access the Worksheet that contains the Chart | |
| sheet = book.worksheets[0] | |
| for chart in sheet.charts: | |
| for index in range(len(chart.n_series)): | |
| # Access the DataLabels of indexed NSeries | |
| labels = chart.n_series[index].data_labels | |
| # Set ResizeShapeToFitText property to true | |
| labels.is_resize_shape_to_fit_text = True | |
| # Calculate Chart | |
| chart.calculate() | |
| # Save the result | |
| book.save(dataDir + "output_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.pydrawing import Color | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create a workbook from source Excel file | |
| workbook = Workbook(dataDir + "sample.xlsx") | |
| # Access first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Access the first chart inside the sheet | |
| chart = worksheet.charts[0] | |
| # Access the data label of first series first point | |
| dlbls = chart.n_series[0].points[0].data_labels | |
| # Set data label text | |
| dlbls.text = "Rich Text Label" | |
| # Set the font setting of the first 10 characters | |
| fntSetting = dlbls.characters(0, 10) | |
| fntSetting.font.color = Color.red | |
| fntSetting.font.is_bold = True | |
| # Save the workbook | |
| workbook.save(dataDir + "output_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import FileFormatType, Workbook | |
| from aspose.cells.charts import ChartType, DataLabelsSeparatorType, LabelPositionType | |
| from aspose.cells.drawing import ImageType | |
| from aspose.cells.rendering import ImageOrPrintOptions | |
| # Create an instance of Workbook in XLSX format | |
| workbook = Workbook(FileFormatType.XLSX) | |
| # Access the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Add two columns of data | |
| worksheet.cells.get("A1").put_value("Retail") | |
| worksheet.cells.get("A2").put_value("Services") | |
| worksheet.cells.get("A3").put_value("Info & Communication") | |
| worksheet.cells.get("A4").put_value("Transport Equip") | |
| worksheet.cells.get("A5").put_value("Construction") | |
| worksheet.cells.get("A6").put_value("Other Products") | |
| worksheet.cells.get("A7").put_value("Wholesale") | |
| worksheet.cells.get("A8").put_value("Land Transport") | |
| worksheet.cells.get("A9").put_value("Air Transport") | |
| worksheet.cells.get("A10").put_value("Electric Appliances") | |
| worksheet.cells.get("A11").put_value("Securities") | |
| worksheet.cells.get("A12").put_value("Textiles & Apparel") | |
| worksheet.cells.get("A13").put_value("Machinery") | |
| worksheet.cells.get("A14").put_value("Metal Products") | |
| worksheet.cells.get("A15").put_value("Cash") | |
| worksheet.cells.get("A16").put_value("Banks") | |
| worksheet.cells.get("B1").put_value(10.4) | |
| worksheet.cells.get("B2").put_value(5.2) | |
| worksheet.cells.get("B3").put_value(6.4) | |
| worksheet.cells.get("B4").put_value(10.4) | |
| worksheet.cells.get("B5").put_value(7.9) | |
| worksheet.cells.get("B6").put_value(4.1) | |
| worksheet.cells.get("B7").put_value(3.5) | |
| worksheet.cells.get("B8").put_value(5.7) | |
| worksheet.cells.get("B9").put_value(3) | |
| worksheet.cells.get("B10").put_value(14.7) | |
| worksheet.cells.get("B11").put_value(3.6) | |
| worksheet.cells.get("B12").put_value(2.8) | |
| worksheet.cells.get("B13").put_value(7.8) | |
| worksheet.cells.get("B14").put_value(2.4) | |
| worksheet.cells.get("B15").put_value(1.8) | |
| worksheet.cells.get("B16").put_value(10.1) | |
| # Create a pie chart and add it to the collection of charts | |
| id = worksheet.charts.add(ChartType.PIE, 3, 3, 23, 13) | |
| # Access newly created Chart instance | |
| chart = worksheet.charts[id] | |
| # Set series data range | |
| chart.n_series.add("B1:B16", True) | |
| # Set category data range | |
| chart.n_series.category_data = "A1:A16" | |
| # Turn off legend | |
| chart.show_legend = False | |
| # Access data labels | |
| dataLabels = chart.n_series[0].data_labels | |
| # Turn on category names | |
| dataLabels.show_category_name = True | |
| # Turn on percentage format | |
| dataLabels.show_percentage = True | |
| # Set position | |
| dataLabels.position = LabelPositionType.OUTSIDE_END | |
| # Set separator | |
| dataLabels.separator_type = DataLabelsSeparatorType.COMMA | |
| # In order to save the chart image, create an instance of ImageOrPrintOptions | |
| anOption = ImageOrPrintOptions() | |
| # Set image format | |
| anOption.image_type = ImageType.PNG | |
| # Set resolution | |
| anOption.horizontal_resolution = 200 | |
| anOption.vertical_resolution = 200 | |
| # Render chart to image | |
| chart.to_image(dataDir + "output_out.png", anOption) | |
| # Save the workbook to see chart inside the Excel | |
| workbook.save(dataDir + "output_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Create an instance of existing Workbook | |
| workbook = Workbook("seriesFiltered.xlsx") | |
| # Get filtered series list | |
| nSeriesFiltered = workbook.worksheets[0].charts.get("Chart 1").filtered_n_series | |
| # Get selected series list | |
| nSeries = workbook.worksheets[0].charts.get("Chart 1").n_series | |
| # Should be 0 | |
| print("Filtered Series count" + str(len(nSeriesFiltered))) | |
| # Should be 6 | |
| print("Visiable Series count" + str(len(nSeries))) | |
| # Process from the end to the beginning | |
| nSeries[1].is_filtered = True | |
| nSeries[0].is_filtered = True | |
| # Should be 2 | |
| print("Filtered Series count" + str(len(nSeriesFiltered))) | |
| # Should be 4 | |
| print("Visiable Series count" + str(len(nSeries))) | |
| workbook.save("seriesFiltered-out.xlsx") | |
| workbook = Workbook("seriesFiltered-out.xlsx") | |
| # Should be 2 | |
| print("Filtered Series count" + str(len(nSeriesFiltered))) | |
| # Should be 4 | |
| print("Visiable Series count" + str(len(nSeries))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import SheetType, Workbook | |
| from aspose.cells.charts import ChartType, LegendPositionType | |
| from aspose.pydrawing import Color | |
| import bytearray | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create a new Workbook. | |
| workbook = Workbook() | |
| # Get the first worksheet. | |
| sheet = workbook.worksheets[0] | |
| # Set the name of worksheet | |
| sheet.name = "Data" | |
| # Get the cells collection in the sheet. | |
| cells = workbook.worksheets[0].cells | |
| # Put some values into a cells of the Data sheet. | |
| cells.get("A1").put_value("Region") | |
| cells.get("A2").put_value("France") | |
| cells.get("A3").put_value("Germany") | |
| cells.get("A4").put_value("England") | |
| cells.get("A5").put_value("Sweden") | |
| cells.get("A6").put_value("Italy") | |
| cells.get("A7").put_value("Spain") | |
| cells.get("A8").put_value("Portugal") | |
| cells.get("B1").put_value("Sale") | |
| cells.get("B2").put_value(70000) | |
| cells.get("B3").put_value(55000) | |
| cells.get("B4").put_value(30000) | |
| cells.get("B5").put_value(40000) | |
| cells.get("B6").put_value(35000) | |
| cells.get("B7").put_value(32000) | |
| cells.get("B8").put_value(10000) | |
| # Add a chart sheet. | |
| sheetIndex = workbook.worksheets.add(SheetType.CHART) | |
| sheet = workbook.worksheets[sheetIndex] | |
| # Set the name of worksheet | |
| sheet.name = "Chart" | |
| # Create chart | |
| chartIndex = 0 | |
| chartIndex = sheet.charts.add(ChartType.COLUMN, 1, 1, 25, 10) | |
| chart = sheet.charts[chartIndex] | |
| # Set some properties of chart plot area. | |
| # To set a picture as fill format and make the border invisible. | |
| fs = open(dataDir + "aspose.png", "rb") | |
| data = bytearray(utils.filesize(fs)) | |
| fs.readinto(data) | |
| chart.plot_area.area.fill_format.image_data = data | |
| chart.plot_area.border.is_visible = False | |
| # Set properties of chart title | |
| chart.title.text = "Sales By Region" | |
| chart.title.font.color = Color.blue | |
| chart.title.font.is_bold = True | |
| chart.title.font.size = 12 | |
| # Set properties of nseries | |
| chart.n_series.add("Data!B2:B8", True) | |
| chart.n_series.category_data = "Data!A2:A8" | |
| chart.n_series.is_color_varied = True | |
| # Set the Legend. | |
| legend = chart.legend | |
| legend.position = LegendPositionType.TOP | |
| # Save the excel file | |
| workbook.save(dataDir + "column_chart_out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.drawing import DataLabelShapeType | |
| # Load source Excel file | |
| wb = Workbook("sampleSetShapeTypeOfDataLabelsOfChart.xlsx") | |
| # Access first worksheet | |
| ws = wb.worksheets[0] | |
| # Access first chart | |
| ch = ws.charts[0] | |
| # Access first series | |
| srs = ch.n_series[0] | |
| # Set the shape type of data labels i.e. Speech Bubble Oval | |
| srs.data_labels.shape_type = DataLabelShapeType.WEDGE_ELLIPSE_CALLOUT | |
| # Save the output Excel file | |
| wb.save("outputSetShapeTypeOfDataLabelsOfChart.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Excel object | |
| sheetIndex = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[sheetIndex] | |
| # Adding sample values to cells | |
| worksheet.cells.get("A1").put_value(10) | |
| worksheet.cells.get("A2").put_value(100) | |
| worksheet.cells.get("A3").put_value(170) | |
| worksheet.cells.get("A4").put_value(200) | |
| worksheet.cells.get("B1").put_value(120) | |
| worksheet.cells.get("B2").put_value(320) | |
| worksheet.cells.get("B3").put_value(50) | |
| worksheet.cells.get("B4").put_value(40) | |
| # Adding sample values to cells as category data | |
| worksheet.cells.get("C1").put_value("Q1") | |
| worksheet.cells.get("C2").put_value("Q2") | |
| worksheet.cells.get("C3").put_value("Y1") | |
| worksheet.cells.get("C4").put_value("Y2") | |
| # Adding a chart to the worksheet | |
| chartIndex = worksheet.charts.add(ChartType.COLUMN, 5, 0, 15, 5) | |
| # Accessing the instance of the newly added chart | |
| chart = worksheet.charts[chartIndex] | |
| # Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B4" | |
| chart.n_series.add("A1:B4", True) | |
| # Setting the data source for the category data of SeriesCollection | |
| chart.n_series.category_data = "C1:C4" | |
| # Saving the Excel file | |
| workbook.save(dataDir + "output.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import ThemeColor, ThemeColorType, Workbook | |
| from aspose.cells.drawing import FillType | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Instantiate the workbook to open the file that contains a chart | |
| workbook = Workbook(dataDir + "book1.xlsx") | |
| # Get the first worksheet | |
| worksheet = workbook.worksheets[1] | |
| # Get the first chart in the sheet | |
| chart = worksheet.charts[0] | |
| # Specify the FilFormat's type to Solid Fill of the first series | |
| chart.n_series[0].area.fill_format.fill_type = FillType.SOLID | |
| # Get the CellsColor of SolidFill | |
| cc = chart.n_series[0].area.fill_format.solid_fill.cells_color | |
| # Create a theme in Accent style | |
| cc.theme_color = ThemeColor(ThemeColorType.ACCENT6, 0.6) | |
| # Apply the them to the series | |
| chart.n_series[0].area.fill_format.solid_fill.cells_color = cc | |
| # Save the Excel file | |
| workbook.save(dataDir + "output.out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType | |
| from aspose.cells.drawing import GradientStyleType | |
| from aspose.pydrawing import Color | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Workbook object | |
| sheetIndex = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[sheetIndex] | |
| # Adding sample values to cells | |
| worksheet.cells.get("A1").put_value(50) | |
| worksheet.cells.get("A2").put_value(100) | |
| worksheet.cells.get("A3").put_value(150) | |
| worksheet.cells.get("B1").put_value(60) | |
| worksheet.cells.get("B2").put_value(32) | |
| worksheet.cells.get("B3").put_value(50) | |
| # Adding a chart to the worksheet | |
| chartIndex = worksheet.charts.add(ChartType.COLUMN, 5, 0, 15, 5) | |
| # Accessing the instance of the newly added chart | |
| chart = worksheet.charts[chartIndex] | |
| # Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3" | |
| chart.n_series.add("A1:B3", True) | |
| # Setting the foreground color of the plot area | |
| chart.plot_area.area.foreground_color = Color.blue | |
| # Setting the foreground color of the chart area | |
| chart.chart_area.area.foreground_color = Color.yellow | |
| # Setting the foreground color of the 1st SeriesCollection area | |
| chart.n_series[0].area.foreground_color = Color.red | |
| # Setting the foreground color of the area of the 1st SeriesCollection point | |
| chart.n_series[0].points[0].area.foreground_color = Color.cyan | |
| # Filling the area of the 2nd SeriesCollection with a gradient | |
| chart.n_series[1].area.fill_format.set_one_color_gradient(Color.lime, 1, GradientStyleType.HORIZONTAL, 1) | |
| # Setting the color of Category Axis' major gridlines to silver | |
| chart.category_axis.major_grid_lines.color = Color.silver | |
| # Setting the color of Value Axis' major gridlines to red | |
| chart.value_axis.major_grid_lines.color = Color.red | |
| # Saving the Excel file | |
| workbook.save(dataDir + "book1.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType | |
| from aspose.cells.drawing import GradientStyleType | |
| from aspose.pydrawing import Color | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Workbook object | |
| sheetIndex = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[sheetIndex] | |
| # Adding sample values to cells | |
| worksheet.cells.get("A1").put_value(50) | |
| worksheet.cells.get("A2").put_value(100) | |
| worksheet.cells.get("A3").put_value(150) | |
| worksheet.cells.get("B1").put_value(60) | |
| worksheet.cells.get("B2").put_value(32) | |
| worksheet.cells.get("B3").put_value(50) | |
| # Adding a chart to the worksheet | |
| chartIndex = worksheet.charts.add(ChartType.COLUMN, 5, 0, 15, 5) | |
| # Accessing the instance of the newly added chart | |
| chart = worksheet.charts[chartIndex] | |
| # Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3" | |
| chart.n_series.add("A1:B3", True) | |
| # Setting the foreground color of the plot area | |
| chart.plot_area.area.foreground_color = Color.blue | |
| # Setting the foreground color of the chart area | |
| chart.chart_area.area.foreground_color = Color.yellow | |
| # Setting the foreground color of the 1st SeriesCollection area | |
| chart.n_series[0].area.foreground_color = Color.red | |
| # Setting the foreground color of the area of the 1st SeriesCollection point | |
| chart.n_series[0].points[0].area.foreground_color = Color.cyan | |
| # Filling the area of the 2nd SeriesCollection with a gradient | |
| chart.n_series[1].area.fill_format.set_one_color_gradient(Color.lime, 1, GradientStyleType.HORIZONTAL, 1) | |
| # Hiding the major gridlines of Category Axis | |
| chart.category_axis.major_grid_lines.is_visible = False | |
| # Hiding the major gridlines of Value Axis | |
| chart.value_axis.major_grid_lines.is_visible = False | |
| # Saving the Excel file | |
| workbook.save(dataDir + "book1.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType | |
| from aspose.cells.drawing import GradientStyleType | |
| from aspose.pydrawing import Color | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Workbook object | |
| sheetIndex = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[sheetIndex] | |
| # Adding sample values to cells | |
| worksheet.cells.get("A1").put_value(50) | |
| worksheet.cells.get("A2").put_value(100) | |
| worksheet.cells.get("A3").put_value(150) | |
| worksheet.cells.get("B1").put_value(60) | |
| worksheet.cells.get("B2").put_value(32) | |
| worksheet.cells.get("B3").put_value(50) | |
| # Adding a chart to the worksheet | |
| chartIndex = worksheet.charts.add(ChartType.COLUMN, 5, 0, 15, 5) | |
| # Accessing the instance of the newly added chart | |
| chart = worksheet.charts[chartIndex] | |
| # Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3" | |
| chart.n_series.add("A1:B3", True) | |
| # Setting the foreground color of the plot area | |
| chart.plot_area.area.foreground_color = Color.blue | |
| # Setting the foreground color of the chart area | |
| chart.chart_area.area.foreground_color = Color.yellow | |
| # Setting the foreground color of the 1st SeriesCollection area | |
| chart.n_series[0].area.foreground_color = Color.red | |
| # Setting the foreground color of the area of the 1st SeriesCollection point | |
| chart.n_series[0].points[0].area.foreground_color = Color.cyan | |
| # Filling the area of the 2nd SeriesCollection with a gradient | |
| chart.n_series[1].area.fill_format.set_one_color_gradient(Color.lime, 1, GradientStyleType.HORIZONTAL, 1) | |
| # Saving the Excel file | |
| workbook.save(dataDir + "book1.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartMarkerType, ChartType | |
| from aspose.cells.drawing import GradientStyleType, LineType, WeightType | |
| from aspose.pydrawing import Color | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Workbook object | |
| sheetIndex = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[sheetIndex] | |
| # Adding sample values to cells | |
| worksheet.cells.get("A1").put_value(50) | |
| worksheet.cells.get("A2").put_value(100) | |
| worksheet.cells.get("A3").put_value(150) | |
| worksheet.cells.get("B1").put_value(60) | |
| worksheet.cells.get("B2").put_value(32) | |
| worksheet.cells.get("B3").put_value(50) | |
| # Adding a chart to the worksheet | |
| chartIndex = worksheet.charts.add(ChartType.COLUMN, 5, 0, 15, 5) | |
| # Accessing the instance of the newly added chart | |
| chart = worksheet.charts[chartIndex] | |
| # Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3" | |
| chart.n_series.add("A1:B3", True) | |
| # Setting the foreground color of the plot area | |
| chart.plot_area.area.foreground_color = Color.blue | |
| # Setting the foreground color of the chart area | |
| chart.chart_area.area.foreground_color = Color.yellow | |
| # Setting the foreground color of the 1st SeriesCollection area | |
| chart.n_series[0].area.foreground_color = Color.red | |
| # Setting the foreground color of the area of the 1st SeriesCollection point | |
| chart.n_series[0].points[0].area.foreground_color = Color.cyan | |
| # Filling the area of the 2nd SeriesCollection with a gradient | |
| chart.n_series[1].area.fill_format.set_one_color_gradient(Color.lime, 1, GradientStyleType.HORIZONTAL, 1) | |
| # Applying a dotted line style on the lines of a SeriesCollection | |
| chart.n_series[0].border.style = LineType.DOT | |
| # Applying a triangular marker style on the data markers of a SeriesCollection | |
| chart.n_series[0].marker.marker_style = ChartMarkerType.TRIANGLE | |
| # Setting the weight of all lines in a SeriesCollection to medium | |
| chart.n_series[1].border.weight = WeightType.MEDIUM_LINE | |
| # Saving the Excel file | |
| workbook.save(dataDir + "book1.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType | |
| from aspose.cells.drawing import GradientStyleType | |
| from aspose.pydrawing import Color | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Workbook object | |
| sheetIndex = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[sheetIndex] | |
| # Adding sample values to cells | |
| worksheet.cells.get("A1").put_value(50) | |
| worksheet.cells.get("A2").put_value(100) | |
| worksheet.cells.get("A3").put_value(150) | |
| worksheet.cells.get("B1").put_value(60) | |
| worksheet.cells.get("B2").put_value(32) | |
| worksheet.cells.get("B3").put_value(50) | |
| # Adding a chart to the worksheet | |
| chartIndex = worksheet.charts.add(ChartType.COLUMN, 5, 0, 15, 5) | |
| # Accessing the instance of the newly added chart | |
| chart = worksheet.charts[chartIndex] | |
| # Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3" | |
| chart.n_series.add("A1:B3", True) | |
| # Setting the foreground color of the plot area | |
| chart.plot_area.area.foreground_color = Color.blue | |
| # Setting the foreground color of the chart area | |
| chart.chart_area.area.foreground_color = Color.yellow | |
| # Setting the foreground color of the 1st SeriesCollection area | |
| chart.n_series[0].area.foreground_color = Color.red | |
| # Setting the foreground color of the area of the 1st SeriesCollection point | |
| chart.n_series[0].points[0].area.foreground_color = Color.cyan | |
| # Filling the area of the 2nd SeriesCollection with a gradient | |
| chart.n_series[1].area.fill_format.set_one_color_gradient(Color.lime, 1, GradientStyleType.HORIZONTAL, 1) | |
| # Setting the title of a chart | |
| chart.title.text = "Title" | |
| # Setting the font color of the chart title to blue | |
| chart.title.font.color = Color.blue | |
| # Setting the title of category axis of the chart | |
| chart.category_axis.title.text = "Category" | |
| # Setting the title of value axis of the chart | |
| chart.value_axis.title.text = "Value" | |
| # Saving the Excel file | |
| workbook.save(dataDir + "book1.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Excel object | |
| sheetIndex = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[sheetIndex] | |
| # Adding sample values to cells | |
| worksheet.cells.get("A1").put_value(50) | |
| worksheet.cells.get("A2").put_value(100) | |
| worksheet.cells.get("A3").put_value(170) | |
| worksheet.cells.get("A4").put_value(300) | |
| worksheet.cells.get("B1").put_value(160) | |
| worksheet.cells.get("B2").put_value(32) | |
| worksheet.cells.get("B3").put_value(50) | |
| worksheet.cells.get("B4").put_value(40) | |
| # Adding sample values to cells as category data | |
| worksheet.cells.get("C1").put_value("Q1") | |
| worksheet.cells.get("C2").put_value("Q2") | |
| worksheet.cells.get("C3").put_value("Y1") | |
| worksheet.cells.get("C4").put_value("Y2") | |
| # Adding a chart to the worksheet | |
| chartIndex = worksheet.charts.add(ChartType.COLUMN, 5, 0, 15, 5) | |
| # Accessing the instance of the newly added chart | |
| chart = worksheet.charts[chartIndex] | |
| # Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B4" | |
| chart.n_series.add("A1:B4", True) | |
| # Saving the Excel file | |
| workbook.save(dataDir + "output.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType | |
| from aspose.cells.drawing import GradientStyleType | |
| from aspose.pydrawing import Color | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Workbook object | |
| sheetIndex = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[sheetIndex] | |
| # Adding sample values to cells | |
| worksheet.cells.get("A1").put_value(50) | |
| worksheet.cells.get("A2").put_value(100) | |
| worksheet.cells.get("A3").put_value(150) | |
| worksheet.cells.get("B1").put_value(60) | |
| worksheet.cells.get("B2").put_value(32) | |
| worksheet.cells.get("B3").put_value(50) | |
| # Adding a chart to the worksheet | |
| chartIndex = worksheet.charts.add(ChartType.COLUMN, 5, 0, 15, 5) | |
| # Accessing the instance of the newly added chart | |
| chart = worksheet.charts[chartIndex] | |
| # Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3" | |
| chart.n_series.add("A1:B3", True) | |
| # Setting the foreground color of the plot area | |
| chart.plot_area.area.foreground_color = Color.blue | |
| # Setting the foreground color of the chart area | |
| chart.chart_area.area.foreground_color = Color.yellow | |
| # Setting the foreground color of the 1st SeriesCollection area | |
| chart.n_series[0].area.foreground_color = Color.red | |
| # Setting the foreground color of the area of the 1st SeriesCollection point | |
| chart.n_series[0].points[0].area.foreground_color = Color.cyan | |
| # Filling the area of the 2nd SeriesCollection with a gradient | |
| chart.n_series[1].area.fill_format.set_one_color_gradient(Color.lime, 1, GradientStyleType.HORIZONTAL, 1) | |
| # Setting the title of a chart | |
| chart.title.text = "Title" | |
| # Setting the font color of the chart title to blue | |
| chart.title.font.color = Color.blue | |
| # Setting the title of category axis of the chart | |
| chart.category_axis.title.text = "Category" | |
| # Setting the title of value axis of the chart | |
| chart.value_axis.title.text = "Value" | |
| # Saving the Excel file | |
| workbook.save(dataDir + "book1.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Load the source Excel file | |
| wb = Workbook("sampleSeries_ValuesFormatCode.xlsx") | |
| # Access first worksheet | |
| worksheet = wb.worksheets[0] | |
| # Access first chart | |
| ch = worksheet.charts[0] | |
| # Add series using an array of values | |
| ch.n_series.add("{10000, 20000, 30000, 40000}", True) | |
| # Access the series and set its values format code | |
| srs = ch.n_series[0] | |
| srs.values_format_code = "$#,##0" | |
| # Save the output Excel file | |
| wb.save("outputSeries_ValuesFormatCode.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create workbook from the source Excel file | |
| workbook = Workbook(dataDir + "source.xlsx") | |
| # Access the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Access the chart inside the worksheet | |
| chart = worksheet.charts[0] | |
| # Check the "Label Contains - Value From Cells" | |
| dataLabels = chart.n_series[0].data_labels | |
| dataLabels.show_cell_range = True | |
| # Save the workbook | |
| workbook.save(dataDir + "output_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType | |
| from aspose.cells.tables import TableStyleType | |
| # Create a workbook. | |
| workbook = Workbook("TableFilters.xlsx") | |
| # Access first worksheet | |
| sheet = workbook.worksheets[0] | |
| # Access the instance of the newly added chart | |
| chartIndex = sheet.charts.add(ChartType.COLUMN, 7, 7, 15, 15) | |
| chart = sheet.charts[chartIndex] | |
| # Set data range | |
| chart.set_chart_data_range("A1:B7", True) | |
| # Convert the chart to image | |
| chart.to_image("TableFilters.before.png") | |
| # Add a new List Object to the worksheet | |
| listObject = sheet.list_objects[sheet.list_objects.add("A1", "B7", True)] | |
| # Add default style to the table | |
| listObject.table_style_type = TableStyleType.TABLE_STYLE_MEDIUM10 | |
| # Show Total | |
| listObject.show_totals = False | |
| # Add filters for a filter column. | |
| listObject.auto_filter.add_filter(0, "James") | |
| # Apply the filters | |
| listObject.auto_filter.refresh() | |
| # After adding new value the chart will change | |
| listObject.put_cell_value(7, 0, "Me") | |
| listObject.put_cell_value(7, 1, 1000) | |
| # Check the changed images | |
| chart.to_image("TableFilters.after.png") | |
| # Saving the Excel file | |
| workbook.save("TableFilter.out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import FileFormatType, Workbook | |
| from aspose.cells.charts import ChartType, DataLabelsSeparatorType, LabelPositionType | |
| # Create an instance of Workbook in XLSX format | |
| workbook = Workbook(FileFormatType.XLSX) | |
| # Access the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Add two columns of data | |
| worksheet.cells.get("A1").put_value("Retail") | |
| worksheet.cells.get("A2").put_value("Services") | |
| worksheet.cells.get("A3").put_value("Info & Communication") | |
| worksheet.cells.get("A4").put_value("Transport Equip") | |
| worksheet.cells.get("A5").put_value("Construction") | |
| worksheet.cells.get("A6").put_value("Other Products") | |
| worksheet.cells.get("A7").put_value("Wholesale") | |
| worksheet.cells.get("A8").put_value("Land Transport") | |
| worksheet.cells.get("A9").put_value("Air Transport") | |
| worksheet.cells.get("A10").put_value("Electric Appliances") | |
| worksheet.cells.get("A11").put_value("Securities") | |
| worksheet.cells.get("A12").put_value("Textiles & Apparel") | |
| worksheet.cells.get("A13").put_value("Machinery") | |
| worksheet.cells.get("A14").put_value("Metal Products") | |
| worksheet.cells.get("A15").put_value("Cash") | |
| worksheet.cells.get("A16").put_value("Banks") | |
| worksheet.cells.get("B1").put_value(10.4) | |
| worksheet.cells.get("B2").put_value(5.2) | |
| worksheet.cells.get("B3").put_value(6.4) | |
| worksheet.cells.get("B4").put_value(10.4) | |
| worksheet.cells.get("B5").put_value(7.9) | |
| worksheet.cells.get("B6").put_value(4.1) | |
| worksheet.cells.get("B7").put_value(3.5) | |
| worksheet.cells.get("B8").put_value(5.7) | |
| worksheet.cells.get("B9").put_value(3) | |
| worksheet.cells.get("B10").put_value(14.7) | |
| worksheet.cells.get("B11").put_value(3.6) | |
| worksheet.cells.get("B12").put_value(2.8) | |
| worksheet.cells.get("B13").put_value(7.8) | |
| worksheet.cells.get("B14").put_value(2.4) | |
| worksheet.cells.get("B15").put_value(1.8) | |
| worksheet.cells.get("B16").put_value(10.1) | |
| # Create a pie chart and add it to the collection of charts | |
| id = worksheet.charts.add(ChartType.PIE, 3, 3, 23, 13) | |
| # Access newly created Chart instance | |
| chart = worksheet.charts[id] | |
| # Set series data range | |
| chart.n_series.add("B1:B16", True) | |
| # Set category data range | |
| chart.n_series.category_data = "A1:A16" | |
| # Turn off legend | |
| chart.show_legend = False | |
| # Access data labels | |
| dataLabels = chart.n_series[0].data_labels | |
| # Turn on category names | |
| dataLabels.show_category_name = True | |
| # Turn on percentage format | |
| dataLabels.show_percentage = True | |
| # Set position | |
| dataLabels.position = LabelPositionType.OUTSIDE_END | |
| # Set separator | |
| dataLabels.separator_type = DataLabelsSeparatorType.COMMA | |
| # Turn on leader lines | |
| chart.n_series[0].has_leader_lines = True | |
| # Calculete chart | |
| chart.calculate() | |
| # You need to move DataLabels a little leftward or rightward depending on their position to show leader lines | |
| DELTA = 100 | |
| for i in range(chart.n_series[0].points.count): | |
| X = chart.n_series[0].points[i].data_labels.x | |
| # If it is greater than 2000, then move the X position a little right otherwise move the X position a little left | |
| if X > 2000: | |
| chart.n_series[0].points[i].data_labels.x = X + DELTA | |
| else: | |
| chart.n_series[0].points[i].data_labels.x = X - DELTA |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType, LegendPositionType | |
| from aspose.cells.drawing import FillType | |
| # Create an instance of Workbook | |
| workbook = Workbook() | |
| # Access the first worksheet. | |
| worksheet = workbook.worksheets[0] | |
| # Put the sample values used in charts | |
| worksheet.cells.get("A2").put_value(1) | |
| worksheet.cells.get("A3").put_value(3) | |
| worksheet.cells.get("A4").put_value(2.5) | |
| worksheet.cells.get("A5").put_value(3.5) | |
| worksheet.cells.get("B1").put_value("Cats") | |
| worksheet.cells.get("C1").put_value("Dogs") | |
| worksheet.cells.get("D1").put_value("Fishes") | |
| worksheet.cells.get("B2").put_value(7) | |
| worksheet.cells.get("B3").put_value(6) | |
| worksheet.cells.get("B4").put_value(5) | |
| worksheet.cells.get("B5").put_value(4) | |
| worksheet.cells.get("C2").put_value(7) | |
| worksheet.cells.get("C3").put_value(5) | |
| worksheet.cells.get("C4").put_value(4) | |
| worksheet.cells.get("C5").put_value(3) | |
| worksheet.cells.get("D2").put_value(8) | |
| worksheet.cells.get("D3").put_value(7) | |
| worksheet.cells.get("D4").put_value(3) | |
| worksheet.cells.get("D5").put_value(2) | |
| # Create Line Chart: X as Category Axis | |
| pieIdx = worksheet.charts.add(ChartType.LINE_WITH_DATA_MARKERS, 6, 15, 20, 21) | |
| # Retrieve the Chart object | |
| chart = worksheet.charts[pieIdx] | |
| # Add Series | |
| chart.n_series.add("B2:D5", True) | |
| # Set the category data | |
| chart.n_series.category_data = "=Sheet1!$A$2:$A$5" | |
| # Set the first series mame | |
| chart.n_series[0].name = "Cats" | |
| # Set the second series mame | |
| chart.n_series[1].name = "Dogs" | |
| # Set the third series mame | |
| chart.n_series[2].name = "Fishes" | |
| # Set the Legend at the bottom of the chart area | |
| chart.legend.position = LegendPositionType.BOTTOM | |
| # Fill the PlotArea area with nothing | |
| chart.plot_area.area.fill_format.fill_type = FillType.NONE | |
| # Create XY (Scatter) Chart: X as Value Axis | |
| pieIdx = worksheet.charts.add(ChartType.SCATTER_CONNECTED_BY_LINES_WITH_DATA_MARKER, 6, 6, 20, 12) | |
| # Retrieve the Chart object | |
| chart = worksheet.charts[pieIdx] | |
| # Add Series | |
| chart.n_series.add("B2:D5", True) | |
| # Set X values for series | |
| chart.n_series[0].x_values = "{1,3,2.5,3.5}" | |
| chart.n_series[1].x_values = "{1,3,2.5,3.5}" | |
| chart.n_series[2].x_values = "{1,3,2.5,3.5}" | |
| # Set the first series mame | |
| chart.n_series[0].name = "Cats" | |
| # Set the second series mame | |
| chart.n_series[1].name = "Dogs" | |
| # Set the third series mame | |
| chart.n_series[2].name = "Fishes" | |
| # Set the Legend at the bottom of the chart area | |
| chart.legend.position = LegendPositionType.BOTTOM | |
| # Fill the PlotArea area with nothing | |
| chart.plot_area.area.fill_format.fill_type = FillType.NONE | |
| # Save the Excel file | |
| workbook.save("XAxis.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Workbook object | |
| sheetIndex = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[sheetIndex] | |
| # Adding sample values to cells | |
| worksheet.cells.get("A1").put_value("Series1") | |
| worksheet.cells.get("A2").put_value(50) | |
| worksheet.cells.get("A3").put_value(100) | |
| worksheet.cells.get("A4").put_value(150) | |
| worksheet.cells.get("B1").put_value("Series2") | |
| worksheet.cells.get("B2").put_value(60) | |
| worksheet.cells.get("B3").put_value(32) | |
| worksheet.cells.get("B4").put_value(50) | |
| # Adding a chart to the worksheet | |
| chartIndex = worksheet.charts.add(ChartType.COLUMN, 5, 0, 15, 5) | |
| # Accessing the instance of the newly added chart | |
| chart = worksheet.charts[chartIndex] | |
| # Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3" | |
| chart.set_chart_data_range("A1:B4", True) | |
| # hiding X axis | |
| chart.category_axis.is_visible = False | |
| # Setting max value of Y axis. | |
| chart.value_axis.max_value = 200 | |
| # Setting major unit. | |
| chart.value_axis.major_unit = 50.0 | |
| # Save the file | |
| workbook.save("chart_axes.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.charts import ChartType | |
| # Create an instance of Workbook | |
| workbook = Workbook() | |
| # Get the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Put values to cells for creating chart | |
| worksheet.cells.get("A1").put_value("A") | |
| worksheet.cells.get("B1").put_value("B") | |
| worksheet.cells.get("C1").put_value("C") | |
| worksheet.cells.get("A2").put_value(2) | |
| worksheet.cells.get("A3").put_value(1) | |
| worksheet.cells.get("B2").put_value(2) | |
| worksheet.cells.get("B3").put_value(3) | |
| worksheet.cells.get("C2").put_value(2) | |
| worksheet.cells.get("C3").put_value(3) | |
| # Add a chart to the worksheet | |
| chartIndex = worksheet.charts.add(ChartType.COLUMN_3D, 9, 6, 25, 16) | |
| # Access the instance of the newly added chart | |
| chart = worksheet.charts[chartIndex] | |
| # Calculate the hart | |
| chart.calculate() | |
| # Add SeriesCollection (chart data source) to the chart ranging from "A2" cell to "C3" | |
| chart.set_chart_data_range("A2:C3", True) | |
| # Hide the CategoryAxis axis | |
| chart.category_axis.is_visible = False | |
| # Hide the ValueAxis axis | |
| chart.value_axis.is_visible = False | |
| # Save the file | |
| workbook.save("ZAxis.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import aspose.cells | |
| from aspose.cells import Workbook, CellsHelper | |
| print("Assembly Version Info: " + str(CellsHelper.get_version())) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import SaveFormat, Workbook | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if not IsExists: | |
| os.makedirs(dataDir) | |
| # Instantiate a Workbook | |
| workbook = Workbook() | |
| # Get a reference of comments collection with the first sheet | |
| comments = workbook.worksheets[0].comments | |
| # Add a comment to cell A1 | |
| commentIndex = comments.add(0, 0) | |
| comment = comments[commentIndex] | |
| comment.note = "First note." | |
| comment.font.name = "Times New Roman" | |
| # Load an image into stream | |
| byte_array = bytearray() | |
| with open(dataDir + "logo.jpg", 'rb') as file: | |
| byte_array = bytearray(file.read()) | |
| # Set image data to the shape associated with the comment | |
| comment.comment_shape.fill.image_data = byte_array | |
| # Save the workbook | |
| workbook.save(dataDir + "book1.out.xlsx", SaveFormat.XLSX) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Workbook object | |
| sheetIndex = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[sheetIndex] | |
| # Adding a comment to "F5" cell | |
| commentIndex = worksheet.comments.add("F5") | |
| # Accessing the newly added comment | |
| comment = worksheet.comments[commentIndex] | |
| # Setting the comment note | |
| comment.note = "Hello Aspose!" | |
| # Saving the Excel file | |
| workbook.save(dataDir + "book1.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import SaveFormat, Workbook | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if not IsExists: | |
| os.makedirs(dataDir) | |
| # Instantiate a Workbook | |
| workbook = Workbook() | |
| # Get a reference of comments collection with the first sheet | |
| comments = workbook.worksheets[0].comments | |
| # Add a comment to cell A1 | |
| commentIndex = comments.add(0, 0) | |
| comment = comments[commentIndex] | |
| comment.note = "First note." | |
| comment.font.name = "Times New Roman" | |
| # Load an image into stream | |
| byte_array = bytearray() | |
| with open(dataDir + "image2.jpg", 'rb') as file: | |
| byte_array = bytearray(file.read()) | |
| # Set image data to the shape associated with the comment | |
| comment.comment_shape.fill.image_data = byte_array | |
| dataDir = dataDir + "commentwithpicture1.out.xlsx" | |
| # Save the workbook | |
| workbook.save(dataDir, SaveFormat.XLSX) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Source directory | |
| outDir = "./" | |
| workbook = Workbook() | |
| # Add Author | |
| authorIndex = workbook.worksheets.threaded_comment_authors.add("Aspose Test", "", "") | |
| author = workbook.worksheets.threaded_comment_authors[authorIndex] | |
| # Add Threaded Comment | |
| workbook.worksheets[0].comments.add_threaded_comment("A1", "Test Threaded Comment", author) | |
| workbook.save(outDir + "AddThreadedComments_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import StyleFlag, TextAlignmentType, Workbook | |
| from aspose.pydrawing import Color | |
| # Output directory | |
| outputDir = "" | |
| # Instantiate a new Workbook | |
| workbook = Workbook() | |
| # Get the first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Add some text in cell A1 | |
| worksheet.cells.get("A1").put_value("Here") | |
| # Add a comment to A1 cell | |
| commentIndex = worksheet.comments.add("A1") | |
| comment = worksheet.comments[commentIndex] | |
| # Set its vertical alignment setting | |
| comment.comment_shape.text_vertical_alignment = TextAlignmentType.CENTER | |
| # Set the Comment note | |
| comment.note = "This is my Comment Text. This is Test." | |
| shape = worksheet.comments.get(0, 0).comment_shape | |
| # worksheet.Comments["A1"].CommentShape; | |
| shape.fill.solid_fill.color = Color.black | |
| font = shape.font | |
| font.color = Color.white | |
| styleFlag = StyleFlag() | |
| styleFlag.font_color = True | |
| shape.text_body.format(0, len(shape.text), font, styleFlag) | |
| # Save the Excel file | |
| workbook.save(outputDir + "outputChangeCommentFontColor.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import TextAlignmentType, TextDirectionType, Workbook | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiate a new Workbook | |
| wb = Workbook() | |
| # Get the first worksheet | |
| sheet = wb.worksheets[0] | |
| # Add a comment to A1 cell | |
| comment = sheet.comments[sheet.comments.add("A1")] | |
| # Set its vertical alignment setting | |
| comment.comment_shape.text_vertical_alignment = TextAlignmentType.CENTER | |
| # Set its horizontal alignment setting | |
| comment.comment_shape.text_horizontal_alignment = TextAlignmentType.RIGHT | |
| # Set the Text Direction - Right-to-Left | |
| comment.comment_shape.text_direction = TextDirectionType.RIGHT_TO_LEFT | |
| # Set the Comment note | |
| comment.note = "This is my Comment Text. This is test" | |
| dataDir = dataDir + "OutCommentShape.out.xlsx" | |
| # Save the Excel file | |
| wb.save(dataDir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from os import os, path | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create directory if it is not already present. | |
| IsExists = path.isdir(dataDir) | |
| if notIsExists: | |
| os.makedirs(dataDir) | |
| # Instantiating a Workbook object | |
| workbook = Workbook() | |
| # Adding a new worksheet to the Workbook object | |
| sheetIndex = workbook.worksheets.add() | |
| # Obtaining the reference of the newly added worksheet by passing its sheet index | |
| worksheet = workbook.worksheets[sheetIndex] | |
| # Adding a comment to "F5" cell | |
| commentIndex = worksheet.comments.add("F5") | |
| # Accessing the newly added comment | |
| comment = worksheet.comments[commentIndex] | |
| # Setting the comment note | |
| comment.note = "Hello Aspose!" | |
| # Setting the font size of a comment to 14 | |
| comment.font.size = 14 | |
| # Setting the font of a comment to bold | |
| comment.font.is_bold = True | |
| # Setting the height of the font to 10 | |
| comment.height_cm = 10.0 | |
| # Setting the width of the font to 2 | |
| comment.width_cm = 2.0 | |
| # Saving the Excel file | |
| workbook.save(dataDir + "book1.out.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Source directory | |
| sourceDir = "./" | |
| outDir = "./" | |
| workbook = Workbook(sourceDir + "ThreadedCommentsSample.xlsx") | |
| # Access first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Get Threaded Comment | |
| comment = worksheet.comments.get_threaded_comments("A1")[0] | |
| comment.notes = "Updated Comment" | |
| workbook.save(outDir + "EditThreadedComments.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.pydrawing import Color | |
| # The path to the documents directory. | |
| path = "" | |
| # Initialize a new workbook. | |
| book = Workbook(path + "exmaple.xlsx") | |
| # Accessing the newly added comment | |
| comment = book.worksheets[0].comments[0] | |
| # change background color | |
| shape = comment.comment_shape | |
| shape.fill.solid_fill.color = Color.red | |
| # Save the Excel file | |
| book.save(path + "result.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Source directory | |
| sourceDir = "./" | |
| workbook = Workbook(sourceDir + "ThreadedCommentsSample.xlsx") | |
| # Access first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Get Threaded Comments | |
| threadedComments = worksheet.comments.get_threaded_comments("A1") | |
| for comment in threadedComments: | |
| print("Comment: " + comment.notes) | |
| print("Author: " + comment.author.name) | |
| print("Created Time: " + str(comment.created_time)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Source directory | |
| sourceDir = "./" | |
| workbook = Workbook(sourceDir + "ThreadedCommentsSample.xlsx") | |
| # Access first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Get Threaded Comments | |
| threadedComments = worksheet.comments.get_threaded_comments("A1") | |
| for comment in threadedComments: | |
| print("Comment: " + comment.notes) | |
| print("Author: " + comment.author.name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose import pycore | |
| from aspose.cells import Workbook | |
| from aspose.cells.externalconnections import WebQueryConnection | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| workbook = Workbook(dataDir + "WebQuerySample.xlsx") | |
| connection = workbook.data_connections[0] | |
| if connection is WebQueryConnection: | |
| webQuery = pycore.cast(WebQueryConnection, connection) | |
| print("Web Query URL: " + webQuery.url) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # source directory | |
| SourceDir = "./" | |
| workbook = Workbook(SourceDir + "ODataSample.xlsx") | |
| PQFcoll = workbook.data_mashup.power_query_formulas | |
| for PQF in PQFcoll: | |
| print("Connection Name: " + PQF.name) | |
| PQFIcoll = PQF.power_query_formula_items | |
| for PQFI in PQFIcoll: | |
| print("Name: " + PQFI.name) | |
| print("Value: " + PQFI.value) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose import pycore | |
| from aspose.cells import Workbook | |
| from aspose.cells.externalconnections import DBConnection, OLEDBCommandType | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create workbook object | |
| workbook = Workbook(dataDir + "DataConnection.xlsx") | |
| # Access first Data Connection | |
| conn = workbook.data_connections[0] | |
| # Change the Data Connection Name and Odc file | |
| conn.name = "MyConnectionName" | |
| conn.odc_file = "C:\\Users\\MyDefaulConnection.odc" | |
| # Change the Command Type, Command and Connection String | |
| dbConn = pycore.as_of(conn, DBConnection) if pycore.is_assignable(conn, DBConnection) else None | |
| dbConn.command_type = OLEDBCommandType.SQL_STATEMENT | |
| dbConn.command = "Select * from AdminTable" | |
| dbConn.connection_info = "Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=False" | |
| # Save the workbook | |
| workbook.save(dataDir + "output_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose import pycore | |
| from aspose.cells import Workbook | |
| from aspose.cells.externalconnections import DBConnection | |
| # Load the source Excel Xlsb file | |
| wb = Workbook("sampleExternalConnection_XLSB.xlsb") | |
| connection = wb.data_connections[0] | |
| # Read the first external connection which is actually a DB-Connection | |
| dbCon = pycore.as_of(connection, DBConnection) if pycore.is_assignable(connection, DBConnection) else None | |
| # Print the Name, Command and Connection Info of the DB-Connection | |
| print("Connection Name: " + dbCon.name) | |
| print("Command: " + dbCon.command) | |
| print("Connection Info: " + dbCon.connection_info) | |
| # Modify the Connection Name | |
| dbCon.name = "NewCust" | |
| # Save the Excel Xlsb file | |
| wb.save("outputExternalConnection_XLSB.xlsb") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Create workbook from source excel file | |
| wb = Workbook("Query TXT.xlsx") | |
| # Display the address(range) of result range of query table | |
| print(wb.worksheets[0].query_tables[0].result_range.address) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create workbook from source excel file | |
| workbook = Workbook(dataDir + "Sample.xlsx") | |
| # Access first worksheet | |
| worksheet = workbook.worksheets[0] | |
| # Access first Query Table | |
| qt = worksheet.query_tables[0] | |
| # Print Query Table Data | |
| print("Adjust Column Width: " + str(qt.adjust_column_width)) | |
| print("Preserve Formatting: " + str(qt.preserve_formatting)) | |
| # Now set Preserve Formatting to true | |
| qt.preserve_formatting = True | |
| # Save the workbook | |
| workbook.save(dataDir + "Output_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose import pycore | |
| from aspose.cells import Workbook | |
| from aspose.cells.externalconnections import DBConnection | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Create a workbook object from source file | |
| workbook = Workbook(dataDir + "connection.xlsx") | |
| # Access the external collections | |
| connections = workbook.data_connections | |
| connectionCount = len(connections) | |
| connection = None | |
| for i in range(connectionCount): | |
| connection = connections[i] | |
| # Check if the Connection is DBConnection, then retrieve its various properties | |
| if connection is DBConnection: | |
| dbConn = pycore.cast(DBConnection, connection) | |
| # Retrieve DB Connection Command | |
| print("Command: " + dbConn.command) | |
| # Retrieve DB Connection Command Type | |
| print("Command Type: " + str(dbConn.command_type)) | |
| # Retrieve DB Connection Description | |
| print("Description: " + dbConn.connection_description) | |
| # Retrieve DB Connection ID | |
| print("Id: " + str(dbConn.connection_id)) | |
| # Retrieve DB Connection Info | |
| print("Info: " + dbConn.connection_info) | |
| # Retrieve DB Connection Credentials | |
| print("Credentials: " + str(dbConn.credentials_method_type)) | |
| # Retrieve DB Connection Name | |
| print("Name: " + dbConn.name) | |
| # Retrieve DB Connection ODC File | |
| print("OdcFile: " + dbConn.odc_file) | |
| # Retrieve DB Connection Source File | |
| print("Source file: " + dbConn.source_file) | |
| # Retrieve DB Connection Type | |
| print("Type: " + str(dbConn.type)) | |
| # Retrieve DB Connection Parameters Collection | |
| paramCollection = dbConn.parameters | |
| paramCount = len(paramCollection) | |
| # Iterate the Parameter Collection | |
| for j in range(paramCount): | |
| param = paramCollection[j] | |
| # Retrieve Parameter Cell Reference | |
| print("Cell reference: " + param.cell_reference) | |
| # Retrieve Parameter Name | |
| print("Parameter name: " + param.name) | |
| # Retrieve Parameter Prompt | |
| print("Prompt: " + param.prompt) | |
| # Retrieve Parameter SQL Type | |
| print("SQL Type: " + str(param.sql_type)) | |
| # Retrieve Parameter Type | |
| print("Param Type: " + str(param.type)) | |
| # Retrieve Parameter Value | |
| print("Param Value: " + str(param.value)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Working directories | |
| SourceDir = "./" | |
| outputDir = "./" | |
| workbook = Workbook(SourceDir + "SamplePowerQueryFormula.xlsx") | |
| mashupData = workbook.data_mashup | |
| for formula in mashupData.power_query_formulas: | |
| for item in formula.power_query_formula_items: | |
| if item.name == "Source": | |
| item.value = "Excel.Workbook(File.Contents(\"" + SourceDir + "SamplePowerQueryFormulaSource.xlsx" + "\"), null, true)" | |
| # Save the output workbook. | |
| workbook.save(outputDir + "SamplePowerQueryFormula_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import aspose.cells | |
| from aspose.cells import Workbook, Worksheet, Range | |
| # Open the Excel workbook | |
| book = Workbook("sample_data.xlsx") | |
| # Get the first worksheet | |
| sheet1 = book.worksheets.get(0) | |
| cells = sheet1.cells | |
| # column to list | |
| max_row_index = sheet1.cells.max_row + 1 | |
| column_index = cells.max_data_column | |
| column_list = [] | |
| for row_index in range(0,max_row_index): | |
| curr_cell = sheet1.cells.check_cell(row_index, column_index) | |
| if curr_cell: | |
| column_list.append(curr_cell.value) | |
| else: | |
| column_list.append("") | |
| print(column_list) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import aspose.cells | |
| from aspose.cells import Workbook, Worksheet, Range | |
| # Open the Excel workbook | |
| book = Workbook("sample_data.xlsx") | |
| # Get the first worksheet | |
| sheet1 = book.worksheets.get(0) | |
| cells = sheet1.cells | |
| max_row_index = cells.max_row + 1 | |
| # column to ndarray | |
| column_index = cells.max_data_column | |
| column_list = [] | |
| for row_index in range(0,max_row_index): | |
| curr_cell = sheet1.cells.check_cell(row_index, column_index) | |
| if curr_cell: | |
| column_list.append(curr_cell.value) | |
| else: | |
| column_list.append("") | |
| column_ndarray = np.asarray(column_list) | |
| print(column_ndarray) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import SaveFormat, Workbook | |
| # Source directory | |
| sourceDir = "./" | |
| # Output directory | |
| outputDir = "./" | |
| # Open the template file | |
| workbook = Workbook(sourceDir + "Book1.xlsx") | |
| # Save as pptx | |
| workbook.save(outputDir + "Book1.pptx", SaveFormat.PPTX) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import SaveFormat, Workbook | |
| # Source directory | |
| sourceDir = "./" | |
| # Output directory | |
| outputDir = "./" | |
| # Open the template file | |
| workbook = Workbook(sourceDir + "Book1.xlsx") | |
| # Save as Markdown | |
| workbook.save(outputDir + "Book1.docx", SaveFormat.DOCX) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import HtmlSaveOptions, SaveFormat, Workbook | |
| from aspose.cells.drawing import ImageType | |
| from aspose.pydrawing.drawing2d import SmoothingMode | |
| from aspose.pydrawing.text import TextRenderingHint | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Specify the file path | |
| filePath = dataDir + "Book1.xlsx" | |
| # Load a spreadsheet to be converted | |
| book = Workbook(filePath) | |
| # Create an instance of HtmlSaveOptions | |
| saveOptions = HtmlSaveOptions(SaveFormat.HTML) | |
| # Set the ImageFormat to PNG | |
| saveOptions.image_options.image_type = ImageType.PNG | |
| # Set SmoothingMode to AntiAlias | |
| saveOptions.image_options.smoothing_mode = SmoothingMode.ANTI_ALIAS | |
| # Set TextRenderingHint to AntiAlias | |
| saveOptions.image_options.text_rendering_hint = TextRenderingHint.ANTI_ALIAS | |
| # Save spreadsheet to HTML while passing object of HtmlSaveOptions | |
| book.save(dataDir + "output.html", saveOptions) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import SaveFormat, Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Specify the file path | |
| filePath = dataDir + "sample.xlsx" | |
| # Load your sample excel file in a workbook object | |
| wb = Workbook(filePath) | |
| # Save it in HTML format | |
| wb.save(dataDir + "ConvertingToHTMLFiles_out.html", SaveFormat.HTML) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Open a template excel file | |
| book = Workbook("Book1.xlsx") | |
| # Convert workbook to BMP image. | |
| book.save("Image1.bmp") | |
| # Convert workbook to JPG image. | |
| book.save("Image1.jpg") | |
| # Convert workbook to Png image. | |
| book.save("Image1.png") | |
| # Convert workbook to EMF image. | |
| book.save("Image1.emf") | |
| # Convert workbook to GIF image. | |
| book.save("Image1.gif") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Open a template excel file | |
| book = Workbook("Book1.xlsx") | |
| # Convert workbook to JPG image. | |
| book.save("Image1.jpg") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Load your source workbook | |
| workbook = Workbook("sample.xlsx") | |
| # Convert the workbook to json file. | |
| workbook.save("sample_out.json") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import CellArea, JsonSaveOptions, Workbook | |
| # Create an options of saving the file. | |
| options = JsonSaveOptions() | |
| # Set the exporting range. | |
| options.export_area = CellArea.create_cell_area("B1", "C4") | |
| # Load your source workbook | |
| workbook = Workbook("sample.xlsx") | |
| # Convert the workbook to json file. | |
| workbook.save("sample_out.json", options) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Load your source workbook | |
| workbook = Workbook("Book1.xlsx") | |
| # convert the workbook to json file. | |
| workbook.save("book1.json") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import aspose.cells | |
| from aspose.cells import Workbook, SaveFormat, JsonSaveOptions, CellArea | |
| # Create an options of saving the file. | |
| options = JsonSaveOptions() | |
| # Set the exporting range. | |
| options.setExportArea(CellArea.createCellArea("B1", "C4")) | |
| # Load Source Excel file | |
| workbook = Workbook("sample.xlsx") | |
| # Save the workbook in JSON format | |
| workbook.save("sample_out.json", options) | |
| jpype.shutdownJVM() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import SaveFormat, Workbook | |
| # Source directory | |
| sourceDir = "./" | |
| # Output directory | |
| outputDir = "./" | |
| # Open the template file | |
| workbook = Workbook(sourceDir + "Book1.xlsx") | |
| # Save as Markdown | |
| workbook.save(outputDir + "Book1.md", SaveFormat.MARKDOWN) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import HtmlSaveOptions, SaveFormat, Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| # Specify the file path | |
| filePath = dataDir + "Book1.xlsx" | |
| # Specify the HTML Saving Options | |
| sv = HtmlSaveOptions(SaveFormat.M_HTML) | |
| # Instantiate a workbook and open the template XLSX file | |
| wb = Workbook(filePath) | |
| # Save the MHT file | |
| wb.save(filePath + ".out.mht", sv) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Load your source workbook | |
| workbook = Workbook("book1.xlsx") | |
| # Save as ods file | |
| workbook.save("Out.ods") | |
| # Save as sxc file | |
| workbook.save("Out.sxc") | |
| # Save as fods file | |
| workbook.save("Out.fods") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Instantiate the Workbook object | |
| # Open an Excel file | |
| workbook = Workbook("Book1.xlsx") | |
| # Save the document in PDF format | |
| workbook.save("output.pdf") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import aspose.cells | |
| from aspose.cells import Workbook, SaveFormat | |
| # Load Source Excel file | |
| workbook = Workbook("sample.xlsx") | |
| # Save the workbook as pptx format | |
| workbook.save("sample_out.pptx", SaveFormat.PPTX) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Open a template excel file | |
| book = Workbook("Book1.xlsx") | |
| # save file to tiff | |
| book.save("out.tiff") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import aspose.cells | |
| from aspose.cells import Workbook, SaveFormat | |
| # Load Source Excel file | |
| workbook = Workbook("sample.xlsx") | |
| # Save the workbook as Word format | |
| workbook.save("sample_out.docx", SaveFormat.DOCX) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook, XmlSaveOptions | |
| # Load your source workbook | |
| workbook = Workbook("Book1.xlsx") | |
| # Save as Excel 2003 Spreadsheet XML | |
| workbook.save("Spreadsheet.xml") | |
| # Save as plain XML data | |
| xmlSaveOptions = XmlSaveOptions() | |
| workbook.save("data.xml", xmlSaveOptions) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook, XpsSaveOptions | |
| # Open an Excel file | |
| workbook = Workbook("Book1.xls") | |
| options = XpsSaveOptions() | |
| # Export the whole workbook to XPS | |
| workbook.save("out.xps", options) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.utility import JsonLayoutOptions, JsonUtility | |
| inputJson = r"[ | |
| { BEFORE: 'before cell', TEST: 'asd1', AFTER: 'after cell' }, | |
| { BEFORE: 'before cell', TEST: 'asd2', AFTER: 'after cell' }, | |
| { BEFORE: 'before cell', TEST: 'asd3', AFTER: 'after cell' }, | |
| { BEFORE: 'before cell', TEST: 'asd4', AFTER: 'after cell' } | |
| ]" | |
| sheetName = "Sheet1" | |
| row = 3 | |
| column = 2 | |
| # create a Workbook object | |
| book = Workbook() | |
| worksheet = book.worksheets.get(sheetName) | |
| # set JsonLayoutOptions to treat Arrays as Table | |
| jsonLayoutOptions = JsonLayoutOptions() | |
| jsonLayoutOptions.array_as_table = True | |
| JsonUtility.import_data(inputJson, worksheet.cells, row, column, jsonLayoutOptions) | |
| # save file to xlsx format | |
| book.save("out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # create a Workbook object | |
| wb = Workbook("sample.json") | |
| # save file to xlsx format | |
| wb.save("sample_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import JsonLoadOptions, Workbook | |
| # Create an options of loading the file. | |
| options = JsonLoadOptions() | |
| # Indicates whether importing each attribute of JsonObject object as one worksheet when all child nodes are array nodes. | |
| options.multiple_worksheets = True | |
| book = Workbook("sample.json", options) | |
| # save file to xlsx format | |
| book.save("sample_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import aspose.cells | |
| from aspose.cells import Workbook | |
| # Load Source JSON file | |
| workbook = Workbook("sample.json") | |
| # Save file to xlsx format | |
| workbook.save("sample_out.xlsx") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import aspose.cells | |
| from aspose.cells import Workbook, JsonLoadOptions | |
| # Create an options of loading the file. | |
| options = JsonLoadOptions() | |
| # Indicates whether importing each attribute of JsonObject object as one worksheet when all child nodes are array nodes. | |
| options.multiple_worksheets = True | |
| book = Workbook("sample_out.json", options) | |
| # save file to xlsx format | |
| book.save("sample_out2.xlsx") | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import aspose.cells | |
| from aspose.cells import Workbook, Worksheet, Range | |
| # Open the Excel workbook | |
| book = Workbook("sample_data.xlsx") | |
| # Get the first worksheet | |
| sheet1 = book.worksheets.get(0) | |
| cells = sheet1.cells | |
| # listobject to list | |
| table_index = sheet1.list_objects.add("A1", "C4", True) | |
| table = sheet1.list_objects[table_index] | |
| table_list =[] | |
| for row_index in range(table.start_row , table.end_row + 1): | |
| row =[] | |
| for column_index in range(table.start_column, table.end_column + 1): | |
| curr_cell = cells.check_cell(row_index, column_index) | |
| if curr_cell: | |
| row.append(curr_cell.value) | |
| else: | |
| row.append("") | |
| table_list.append(row) | |
| print(table_list) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import aspose.cells | |
| from aspose.cells import Workbook, Worksheet, Range | |
| # Open the Excel workbook | |
| book = Workbook("sample_data.xlsx") | |
| # Get the first worksheet | |
| sheet1 = book.worksheets.get(0) | |
| cells = sheet1.cells | |
| # listobject to ndarray | |
| table_index = sheet1.list_objects.add("A1", "C4", True) | |
| table = sheet1.list_objects[table_index] | |
| table_list =[] | |
| for row_index in range(table.start_row , table.end_row + 1): | |
| row =[] | |
| for column_index in range(table.start_column, table.end_column + 1): | |
| curr_cell = cells.check_cell(row_index, column_index) | |
| if curr_cell: | |
| row.append(curr_cell.value) | |
| else: | |
| row.append("") | |
| table_list.append(row) | |
| table_ndarray = np.asarray(table_list) | |
| print(table_ndarray) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| # Load your source ods file | |
| workbook = Workbook("book1.ods") | |
| # Save as xlsx file | |
| workbook.save("ods_out.xlsx") | |
| # Load your source sxc file | |
| workbook = Workbook("book1.sxc") | |
| # Save as xls file | |
| workbook.save("sxc_out.xls") | |
| # Load your source fods file | |
| workbook = Workbook("book1.fods") | |
| # Save as xlsb file | |
| workbook.save("fods_out.xlsb") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import aspose.cells | |
| from aspose.cells import Workbook, Worksheet, Range | |
| # Open the Excel workbook | |
| book = Workbook("sample_data.xlsx") | |
| # Get the first worksheet | |
| sheet1 = book.worksheets.get(0) | |
| # range to list | |
| cells = sheet1.cells | |
| range_obj = cells.create_range("B1", "C3") | |
| range_list =[] | |
| for row_index in range(range_obj.first_row , range_obj.first_row + range_obj.row_count ): | |
| row =[] | |
| for column_index in range(range_obj.first_column, range_obj.first_column + range_obj.column_count): | |
| curr_cell = cells.check_cell(row_index, column_index) | |
| if curr_cell: | |
| row.append(curr_cell.value) | |
| else: | |
| row.append("") | |
| range_list.append(row) | |
| print(range_list) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import aspose.cells | |
| from aspose.cells import Workbook, Worksheet, Range | |
| # Open the Excel workbook | |
| book = Workbook("sample_data.xlsx") | |
| # Get the first worksheet | |
| sheet1 = book.worksheets.get(0) | |
| # range to ndarray | |
| cells = sheet1.cells | |
| range_obj = cells.create_range("B1", "C3") | |
| range_list =[] | |
| for row_index in range(range_obj.first_row , range_obj.first_row + range_obj.row_count ): | |
| row =[] | |
| for column_index in range(range_obj.first_column, range_obj.first_column + range_obj.column_count): | |
| curr_cell = cells.check_cell(row_index, column_index) | |
| if curr_cell: | |
| row.append(curr_cell.value) | |
| else: | |
| row.append("") | |
| range_list.append(row) | |
| range_ndarray = np.asarray(range_list) | |
| print(range_ndarray) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import aspose.cells | |
| from aspose.cells import Workbook, Worksheet, Range | |
| # Open the Excel workbook | |
| book = Workbook("sample_data.xlsx") | |
| # Get the first worksheet | |
| sheet1 = book.worksheets.get(0) | |
| cells = sheet1.cells | |
| # row to list | |
| max_column_index = sheet1.cells.max_column + 1 | |
| row_index = cells.max_data_row | |
| row_list = [] | |
| for column_index in range(0,max_column_index): | |
| curr_cell = cells.check_cell(row_index, column_index) | |
| if curr_cell: | |
| row_list.append(curr_cell.value) | |
| else: | |
| row_list.append("") | |
| print(row_list) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import aspose.cells | |
| from aspose.cells import Workbook, Worksheet, Range | |
| # Open the Excel workbook | |
| book = Workbook("sample_data.xlsx") | |
| # Get the first worksheet | |
| sheet1 = book.worksheets.get(0) | |
| cells = sheet1.cells | |
| max_column_index = cells.max_column + 1 | |
| # row to ndarray | |
| row_index = cells.max_data_row | |
| row_list = [] | |
| for column_index in range(0,max_column_index): | |
| curr_cell = cells.check_cell(row_index, column_index) | |
| if curr_cell: | |
| row_list.append(curr_cell.value) | |
| else: | |
| row_list.append("") | |
| row_ndarray = np.asarray(row_list) | |
| print(row_ndarray) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import aspose.cells | |
| from aspose.cells import Workbook, Worksheet, Range | |
| # Open the Excel workbook | |
| book = Workbook("sample_data.xlsx") | |
| # excel to Dictionary | |
| sheet_count = book.worksheets.capacity - 1 | |
| excel_dict = {} | |
| for sheet_index in range(0, sheet_count): | |
| worksheet_list =[] | |
| sheet = book.worksheets.get(sheet_index) | |
| cells = sheet.cells | |
| rows = cells.rows | |
| max_column_index = cells.max_column + 1 | |
| row_count = rows.count | |
| index = -1 | |
| for row_index in range(0, row_count): | |
| row = rows.get_row_by_index(row_index) | |
| if row_index != row.index: | |
| for blank_row_index in range(index+1, row.index): | |
| blank_row =[] | |
| for blank_column_index in range(0,max_column_index): | |
| blank_row.append("") | |
| worksheet_list.append(blank_row) | |
| data_row =[] | |
| for column_index in range(0,max_column_index): | |
| curr_cell = cells.check_cell(row.index, column_index) | |
| if curr_cell: | |
| data_row.append(curr_cell.value) | |
| else: | |
| data_row.append("") | |
| worksheet_list.append(data_row) | |
| index = row.index | |
| excel_dict[sheet.name] = worksheet_list | |
| print(excel_dict) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import aspose.cells | |
| from aspose.cells import Workbook, Worksheet, Range | |
| # Open the Excel workbook | |
| book = Workbook("sample_data.xlsx") | |
| # workbook to list | |
| sheet_count = book.worksheets.capacity - 1 | |
| workbook_list = [] | |
| for sheet_index in range(0, sheet_count): | |
| worksheet_list =[] | |
| sheet = book.worksheets.get(sheet_index) | |
| cells = sheet.cells | |
| rows = cells.rows | |
| max_column_index = cells.max_column + 1 | |
| row_count = rows.count | |
| index = -1 | |
| for row_index in range(0, row_count): | |
| row = rows.get_row_by_index(row_index) | |
| if row_index != row.index: | |
| for blank_row_index in range(index+1, row.index): | |
| blank_row =[] | |
| for blank_column_index in range(0,max_column_index): | |
| blank_row.append("") | |
| worksheet_list.append(blank_row) | |
| data_row =[] | |
| for column_index in range(0,max_column_index): | |
| curr_cell = cells.check_cell(row.index, column_index) | |
| if curr_cell: | |
| data_row.append(curr_cell.value) | |
| else: | |
| data_row.append("") | |
| worksheet_list.append(data_row) | |
| index = row.index | |
| workbook_list.append(worksheet_list) | |
| print(workbook_list) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import aspose.cells | |
| from aspose.cells import Workbook, Worksheet, Range | |
| # Open the Excel workbook | |
| book = Workbook("sample_data.xlsx") | |
| # workbook to ndarray | |
| excel_ndarray = np.array([], dtype= object) | |
| sheet_count = book.worksheets.capacity - 1 | |
| excel_list = [] | |
| for sheet_index in range(0, sheet_count): | |
| sheet_list =[] | |
| sheet = book.worksheets.get(sheet_index) | |
| cells = sheet.cells | |
| rows = cells.rows | |
| max_column_index = cells.max_column + 1 | |
| row_count = rows.count | |
| index = -1 | |
| for row_index in range(0, row_count): | |
| row = rows.get_row_by_index(row_index) | |
| if row_index != row.index: | |
| for blank_row_index in range(index+1, row.index): | |
| blank_row =[] | |
| for blank_column_index in range(0,max_column_index): | |
| blank_row.append("") | |
| sheet_list.append(blank_row) | |
| data_row =[] | |
| for column_index in range(0,max_column_index): | |
| curr_cell = cells.check_cell(row.index, column_index) | |
| if curr_cell: | |
| data_row.append(curr_cell.value) | |
| else: | |
| data_row.append("") | |
| sheet_list.append(data_row) | |
| index = row.index | |
| excel_list.append(sheet_list) | |
| excel_ndarray = np.asarray(excel_list) | |
| print(excel_ndarray) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import Workbook | |
| from aspose.cells.drawing import ImageType | |
| from aspose.cells.rendering import ImageOrPrintOptions, TiffCompression, WorkbookRender | |
| wb = Workbook("workbook-to-tiff-with-mulitiple-pages.xlsx") | |
| imgOptions = ImageOrPrintOptions() | |
| imgOptions.image_type = ImageType.TIFF | |
| # set Resolution to 200 | |
| imgOptions.horizontal_resolution = 200 | |
| imgOptions.vertical_resolution = 200 | |
| # set TIFF compression to Lzw. | |
| imgOptions.tiff_compression = TiffCompression.COMPRESSION_LZW | |
| workbookRender = WorkbookRender(wb, imgOptions) | |
| workbookRender.to_image("workbook-to-tiff-with-mulitiple-pages.tiff") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import aspose.cells | |
| from aspose.cells import Workbook, Worksheet, Range | |
| # Open the Excel workbook | |
| book = Workbook("sample_data.xlsx") | |
| # Get the first worksheet | |
| sheet1 = book.worksheets.get(0) | |
| cells = sheet1.cells | |
| rows = cells.rows | |
| max_column_index = sheet1.cells.max_column + 1 | |
| # worksheet to list | |
| worksheet_list =[] | |
| row_count = rows.count | |
| index = -1 | |
| for row_index in range(0, row_count): | |
| row = rows.get_row_by_index(row_index) | |
| if row_index != row.index: | |
| for blank_row_index in range(index+1, row.index): | |
| blank_row =[] | |
| for blank_column_index in range(0,max_column_index): | |
| blank_row.append("") | |
| worksheet_list.append(blank_row) | |
| data_row =[] | |
| for column_index in range(0,max_column_index): | |
| curr_cell = cells.check_cell(row.index, column_index) | |
| if curr_cell: | |
| data_row.append(curr_cell.value) | |
| else: | |
| data_row.append("") | |
| worksheet_list.append(data_row) | |
| index = row.index | |
| print(worksheet_list) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import aspose.cells | |
| from aspose.cells import Workbook, Worksheet, Range | |
| # Open the Excel workbook | |
| book = Workbook("sample_data.xlsx") | |
| # Get the first worksheet | |
| sheet1 = book.worksheets.get(0) | |
| cells = sheet1.cells | |
| rows = cells.rows | |
| max_column_index = sheet1.cells.max_column + 1 | |
| # worksheet to ndarray | |
| worksheet_list =[] | |
| row_count = rows.count | |
| index = -1 | |
| for row_index in range(0, row_count): | |
| row = rows.get_row_by_index(row_index) | |
| if row_index != row.index: | |
| for blank_row_index in range(index+1, row.index): | |
| blank_row =[] | |
| for blank_column_index in range(0,max_column_index): | |
| blank_row.append("") | |
| worksheet_list.append(blank_row) | |
| data_row =[] | |
| for column_index in range(0,max_column_index): | |
| curr_cell = cells.check_cell(row.index, column_index) | |
| if curr_cell: | |
| data_row.append(curr_cell.value) | |
| else: | |
| data_row.append("") | |
| worksheet_list.append(data_row) | |
| index = row.index | |
| worksheet_ndarray = np.asarray(worksheet_list) | |
| print(worksheet_ndarray) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import aspose.cells | |
| from aspose.cells import Workbook, PdfSaveOptions | |
| from aspose.cells.rendering import PdfCompliance | |
| workbook = Workbook("sample.xlsx") | |
| options = PdfSaveOptions() | |
| options.compliance = PdfCompliance.PDF_A1A | |
| workbook.save("out.pdf") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import aspose.cells | |
| from aspose.cells import Workbook | |
| # Create an instance of the Workbook class. | |
| workbook = Workbook() | |
| # Insert the words Hello World! into a cell accessed. | |
| workbook.worksheets.get(0).cells.get("A1").put_value("Hello World") | |
| # Save as XLS file | |
| workbook.save("output.xls") | |
| # Save as XLSX file | |
| workbook.save("output.xlsx") | |
| # Save as ods file | |
| workbook.save("output.ods") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import TxtSaveOptions, Workbook | |
| # The path to the documents directory. | |
| dataDir = "./" | |
| filePath = dataDir + "Book1.xlsx" | |
| # Create a Workbook object and opening the file from its path | |
| wb = Workbook(filePath) | |
| # Instantiate Text File's Save Options | |
| options = TxtSaveOptions() | |
| # Set KeepSeparatorsForBlankRow to true show separators in blank rows | |
| options.keep_separators_for_blank_row = True | |
| # Save the file with the options | |
| wb.save(dataDir + "output.csv", options) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aspose.cells import TxtSaveOptions, Workbook | |
| # Load your source workbook | |
| workbook = Workbook("book1.xls") | |
| # Text save options. You can use any type of separator | |
| opts = TxtSaveOptions() | |
| opts.separator = '\t' | |
| workbook.save("out.txt", opts) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment