### Create a New Workbook and Add Text Source: https://docs.aspose.com/cells/python-net/your-first-aspose-cells-application-hello-world This example shows how to create a new Excel workbook from scratch, insert 'Hello World!' into cell A1 of the first worksheet, and save the file. No prior setup is needed. ```python from Aspose.Cells import Workbook # Create a workbook object workbook = Workbook() # Access the first worksheet worksheet = workbook.Worksheets[0] # Access the cells collection and add a value to a cell cell = worksheet.Cells["A1"] cell.Value = "Hello World!" # Save the workbook workbook.Save("HelloWorld.xlsx") ``` -------------------------------- ### Python - Setup and Basic Above Average Formatting Source: https://docs.aspose.com/cells/python-net/how-to-add-above-average-conditional-formatting Initializes a workbook, adds data to cells, and applies a basic 'Above Average' conditional formatting rule with a specified background color. This is the foundational example for applying the formatting. ```python from aspose.cells import Workbook from aspose.cells import Workbook, Worksheet, CellArea, FormatConditionType, IconSetType, FormatConditionValueType, BackgroundType, TimePeriodType from aspose.pydrawing import Color from datetime import datetime import aspose.cells import os import pytest class ConditionalFormatting: def __init__(self): self._sheet = None @staticmethod def run(): # The path to the documents directory current_dir = os.path.dirname(os.path.abspath(__file__)) data_dir = os.path.join(current_dir, "data") obj = ConditionalFormatting() obj.do_test(data_dir) def do_test(self, data_dir): book = Workbook() sheet1 = book.worksheets[0] self._sheet = sheet1 self.add_above_average() self.add_above_average2() self.add_above_average3() self._sheet.auto_fit_column(12) output_dir = os.path.join(data_dir, "output") if not os.path.exists(output_dir): os.makedirs(output_dir) out_fn = os.path.join(output_dir, "Testoutput.out.xlsx") book.save(out_fn, SaveFormat.XLSX) def get_format_condition(self, cell_area_name, color): index = self._sheet.conditional_formattings.add() format_conditions = self._sheet.conditional_formattings[index] area = self.get_cell_area_by_name(cell_area_name) format_conditions.add_area(area) self.fill_cell(cell_area_name, color) return format_conditions def fill_cell(self, cell_area_name, color): area = self.get_cell_area_by_name(cell_area_name) k = 0 for i in range(area.start_column, area.end_column + 1): for j in range(area.start_row, area.end_row + 1): c = self._sheet.cells.get(j, i) if color != Color.empty: s = c.get_style() s.foreground_color = color s.pattern = BackgroundType.SOLID c.set_style(s) value = j + i + k c.put_value(value) k += 1 @staticmethod def get_cell_area_by_name(s): area = CellArea() str_cell_range = s.replace("$", "").split(':') start_row, start_col = CellsHelper.cell_name_to_index(str_cell_range[0]) area.start_row = start_row area.start_column = start_col if len(str_cell_range) == 1: area.end_row = start_row area.end_column = start_col else: end_row, end_col = CellsHelper.cell_name_to_index(str_cell_range[1]) area.end_row = end_row area.end_column = end_col return area def add_above_average(self): conds = self.get_format_condition("A11:C12", Color.tomato) idx = conds.add_condition(FormatConditionType.ABOVE_AVERAGE) cond = conds[idx] cond.style.background_color = Color.pink cond.style.pattern = BackgroundType.SOLID def add_above_average2(self): conds = self.get_format_condition("A13:C14", Color.empty) idx = conds.add_condition(FormatConditionType.ABOVE_AVERAGE) cond = conds[idx] cond.above_average.is_above_average = False cond.above_average.is_equal_average = True cond.style.background_color = Color.pink cond.style.pattern = BackgroundType.SOLID def add_above_average3(self): conds = self.get_format_condition("A15:C16", Color.empty) idx = conds.add_condition(FormatConditionType.ABOVE_AVERAGE) cond = conds[idx] cond.above_average.is_above_average = False cond.above_average.is_equal_average = True cond.above_average.std_dev = 3 cond.style.background_color = Color.pink cond.style.pattern = BackgroundType.SOLID ``` -------------------------------- ### Install Aspose.Cells for Python via .NET Source: https://docs.aspose.com/cells/python-net/getting-started Use this command to install the library from PyPI. This command is applicable for Windows, Linux, and macOS. ```bash pip install aspose-cells-python ``` -------------------------------- ### Set Up Virtual Environment and Install Dependencies Source: https://docs.aspose.com/cells/python-net/using-aspose-as-pandas-engine Create an isolated Python environment and install the necessary packages, including Aspose.Cells for Python and pandas development dependencies. ```bash # Set up virtual environment python -m venv .venv .ackslash.venv\backslash.Scripts\backslash.activate # on Windows # source .venv/bin/activate # on Linux/macOS # Install aspose-cells-python pip install aspose-cells-python # Install the build dependencies python -m pip install -r requirements-dev.txt ``` -------------------------------- ### Install libgdiplus on CentOS/RHEL/Fedora Source: https://docs.aspose.com/cells/python-net/getting-started Required for Aspose.Cells for Python via .NET on CentOS/RHEL/Fedora systems before installation. ```bash yum install libgdiplus ``` -------------------------------- ### Install SkiaSharp on macOS Source: https://docs.aspose.com/cells/python-net/getting-started Install SkiaSharp using Homebrew and nuget, then copy the dylib to /usr/local/lib to resolve 'libSkiaSharp' loading errors. ```bash brew install nuget nuget install SkiaSharp.NativeAssets.macOS -Version 2.88.6 cp ./SkiaSharp.NativeAssets.macOS.2.88.6/runtimes/osx/native/libSkiaSharp.dylib /usr/local/lib/. ``` -------------------------------- ### Install Aspose.Cells for Python Source: https://docs.aspose.com/cells/python-net/convert-an-excel-chart-to-image Install the Aspose.Cells for Python library from PyPI using pip. This is a prerequisite for using the library's functionalities. ```bash $ pip install aspose-cells-python ``` -------------------------------- ### Install MarkItDown Plugin Source: https://docs.aspose.com/cells/python-net/ai-plugin-integration Install the MarkItDown plugin from the current directory using pip. This command installs the plugin in editable mode. ```bash pip install -e . ``` -------------------------------- ### Install libgdiplus on Ubuntu/Debian Source: https://docs.aspose.com/cells/python-net/getting-started Required for Aspose.Cells for Python via .NET on Ubuntu/Debian systems before installation. ```bash apt-get install libgdiplus ``` -------------------------------- ### Install Marker PDF Plugin Source: https://docs.aspose.com/cells/python-net/ai-plugin-integration Install the Marker PDF plugin for Python. Ensure you have Python 3.10+ and PyTorch installed. ```bash pip install marker-pdf ``` -------------------------------- ### Install iisexpress-proxy Source: https://docs.aspose.com/cells/python-net/aspose-cells-gridjs/mobile Install the iisexpress-proxy tool globally using npm. This tool helps in proxying traffic to your local development server. ```bash npm install -g iisexpress-proxy ``` -------------------------------- ### Install Dependencies Source: https://docs.aspose.com/cells/python-net/aspose-cells-gridjs/load-spreadsheet Installs the necessary Python packages for the Flask application, including Aspose.Cells GridJs, Flask, and requests. ```bash pip install aspose-cells-gridjs-net-python flask requests ``` -------------------------------- ### Verify MarkItDown Plugin Installation Source: https://docs.aspose.com/cells/python-net/ai-plugin-integration Verify that the MarkItDown plugin has been successfully installed by listing available plugins. This command checks if the plugin is recognized by the MarkItDown tool. ```bash markitdown --list-plugins ``` -------------------------------- ### Complete Search Modal Styling Example Source: https://docs.aspose.com/cells/python-net/aspose-cells-gridjs/how-to-customize-ui-window Provides a comprehensive set of CSS rules for styling the search modal, including layout, typography, input fields, buttons, and responsiveness for mobile devices. This example demonstrates a modern UI makeover. ```css Copy/* Complete styling for search modal */ .x-spreadsheet-modal-search { border-radius: 16px; overflow: hidden; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15); border: none; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto; } .x-spreadsheet-modal-search .x-spreadsheet-modal-header { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 24px; font-size: 18px; font-weight: 600; } .x-spreadsheet-modal-search .x-spreadsheet-modal-content { padding: 24px; background: #f8f9fa; } .x-spreadsheet-modal-search .x-spreadsheet-form-fields { background: white; padding: 20px; border-radius: 12px; margin-bottom: 16px; } .x-spreadsheet-modal-search label { color: #4b5563; font-size: 13px; font-weight: 500; margin-bottom: 8px; display: block; } .x-spreadsheet-modal-search input[type="text"] { width: 100%; border: 2px solid #e5e7eb; border-radius: 8px; padding: 10px 14px; font-size: 14px; transition: all 0.2s ease; } .x-spreadsheet-modal-search input[type="text"]:focus { border-color: #667eea; box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1); outline: none; } .x-spreadsheet-modal-search .x-spreadsheet-buttons { display: flex; justify-content: flex-end; gap: 12px; padding-top: 20px; } .x-spreadsheet-modal-search .x-spreadsheet-buttons button { padding: 10px 20px; border-radius: 8px; font-weight: 500; font-size: 14px; border: none; cursor: pointer; transition: all 0.2s ease; } .x-spreadsheet-modal-search .x-spreadsheet-buttons button.primary { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; } .x-spreadsheet-modal-search .x-spreadsheet-buttons button.primary:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4); } .x-spreadsheet-modal-search .x-spreadsheet-buttons button:not(.primary) { background: white; color: #667eea; border: 2px solid #667eea; } .x-spreadsheet-modal-search .x-spreadsheet-buttons button:not(.primary):hover { background: #f3f4f6; } /* Mobile responsive */ @media (max-width: 768px) { .x-spreadsheet-modal-search { width: 95% !important; } .x-spreadsheet-modal-search .x-spreadsheet-buttons { flex-direction: column; } .x-spreadsheet-modal-search .x-spreadsheet-buttons button { width: 100%; } } ``` -------------------------------- ### Convert Excel Column to NumPy ndarray Source: https://docs.aspose.com/cells/python-net/convert-excel-to-numpy Export data from an Excel column to a NumPy ndarray using this example. Load the workbook, select the worksheet, and get the column by its index. ```python Copy['Store' '3055' '3036' '3074'] ``` -------------------------------- ### Get Ole Object Class Identifier Source: https://docs.aspose.com/cells/python-net/get-or-set-the-class-identifier-of-the-embedded-ole-object Retrieves the GUID of an embedded OLE object from an Excel file. This is useful for understanding how the host application identifies and handles embedded resources. ```python print(oleObject.class_identifier) ``` -------------------------------- ### Set up a clean virtual environment on Windows Source: https://docs.aspose.com/cells/python-net/getting-started Create and activate a virtual environment to ensure a clean installation of Aspose.Cells for Python via .NET on Windows, resolving potential version conflicts. ```bash # Set up virtual environment python -m venv .venv .\.venv\Scripts\activate ``` -------------------------------- ### Apply License from Disk in Python Source: https://docs.aspose.com/cells/python-net/licensing Instantiate the License class and set the license file path. This example shows how to specify a license file located on disk for Windows. ```python license = License() # For Windows license.set_license("D:\\Aspose.Cells.lic") ``` -------------------------------- ### Helper Function to Get Cell Area by Name Source: https://docs.aspose.com/cells/python-net/how-to-add-icon-sets-conditional-formatting Converts a cell range string (e.g., "A1:B2") into a CellArea object, which defines the start and end rows and columns. This is essential for applying formatting to specific ranges. ```python @staticmethod def get_cell_area_by_name(s): area = CellArea() str_cell_range = s.replace("$", "").split(':') start_row, start_col = CellsHelper.cell_name_to_index(str_cell_range[0]) area.start_row = start_row area.start_column = start_col if len(str_cell_range) == 1: area.end_row = start_row area.end_column = start_col else: end_row, end_col = CellsHelper.cell_name_to_index(str_cell_range[1]) area.end_row = end_row area.end_column = end_col return area ``` -------------------------------- ### Run Flask Server Source: https://docs.aspose.com/cells/python-net/aspose-cells-gridjs/load-spreadsheet This command starts the Flask development server for the Grid.js demo application. Ensure you have a sample Excel file in the data directory and the cache directory exists. ```bash python app.py ``` -------------------------------- ### Python Data Bars Conditional Formatting Example Source: https://docs.aspose.com/cells/python-net/how-to-add-databars-conditional-formatting This code demonstrates how to add data bars conditional formatting to Excel worksheets using Aspose.Cells for Python. It includes setup, applying different data bar styles, and saving the output file. ```python from aspose.cells import Workbook, Worksheet, CellArea, FormatConditionType, IconSetType, FormatConditionValueType, BackgroundType, TimePeriodType from aspose.pydrawing import Color from datetime import datetime import aspose.cells import os import pytest class ConditionalFormatting: def __init__(self): self._sheet = None @staticmethod def run(): # The path to the documents directory current_dir = os.path.dirname(os.path.abspath(__file__)) data_dir = os.path.join(current_dir, "data") obj = ConditionalFormatting() obj.do_test(data_dir) def do_test(self, data_dir): book = Workbook() sheet1 = book.worksheets[0] self._sheet = sheet1 self.add_data_bar1() self.add_data_bar2() self._sheet.auto_fit_column(12) output_dir = os.path.join(data_dir, "output") if not os.path.exists(output_dir): os.makedirs(output_dir) out_fn = os.path.join(output_dir, "TestOutput.out.xlsx") book.save(out_fn, SaveFormat.XLSX) def add_data_bar2(self): conds = self.get_format_condition("E3:G4", Color.light_green) idx = conds.add_condition(FormatConditionType.DATA_BAR) cond = conds[idx] cond.data_bar.color = Color.orange cond.data_bar.min_cfvo.type = FormatConditionValueType.PERCENTILE cond.data_bar.min_cfvo.value = 30.78 cond.data_bar.show_value = False def add_data_bar1(self): conds = self.get_format_condition("E1:G2", Color.yellow_green) idx = conds.add_condition(FormatConditionType.DATA_BAR) cond = conds[idx] def get_format_condition(self, cell_area_name, color): index = self._sheet.conditional_formattings.add() format_conditions = self._sheet.conditional_formattings[index] area = self.get_cell_area_by_name(cell_area_name) format_conditions.add_area(area) self.fill_cell(cell_area_name, color) return format_conditions def fill_cell(self, cell_area_name, color): area = self.get_cell_area_by_name(cell_area_name) k = 0 for i in range(area.start_column, area.end_column + 1): for j in range(area.start_row, area.end_row + 1): c = self._sheet.cells.get(j, i) if color != Color.empty: s = c.get_style() s.foreground_color = color s.pattern = BackgroundType.SOLID c.set_style(s) value = j + i + k c.put_value(value) k += 1 @staticmethod def get_cell_area_by_name(s): area = CellArea() str_cell_range = s.replace("$", "").split(':') start_row, start_col = CellsHelper.cell_name_to_index(str_cell_range[0]) area.start_row = start_row area.start_column = start_col if len(str_cell_range) == 1: area.end_row = start_row area.end_column = start_col else: end_row, end_col = CellsHelper.cell_name_to_index(str_cell_range[1]) area.end_row = end_row area.end_column = end_col return area ``` -------------------------------- ### Menubar Initialization Source: https://docs.aspose.com/cells/python-net/aspose-cells-gridjs/user-guide/download-export-from-file-menu Adds download options (Original, XLSX, PDF, HTML) to the File menu. Cloud storage options (Google Drive, Dropbox) are conditionally added based on the locale. ```APIDOC ## Menubar(data, widthFn, isHide, showPartToolbar, local) ### Description Adds `Download("Original")`, `Download("XLSX")`, `Download("PDF")`, and `Download("HTML")` to the File menu, and conditionally adds cloud entries when `local !== 'ru' && local !== 'zh'`. ### Parameters * **data** - The data for the menubar. * **widthFn** (function) - A function to determine the width. * **isHide** (boolean) - Whether to hide the menubar. * **showPartToolbar** (boolean) - Whether to show a part of the toolbar. * **local** (string) - The locale string (e.g., 'en', 'ru', 'zh'). ### Returns * Menubar instance ``` -------------------------------- ### Get Range Properties: Address, Cell Count, Offset, Entire Column, and Entire Row Source: https://docs.aspose.com/cells/python-net/get-address-cell-count-offset-entire-column-and-entire-row-of-the-range This code snippet demonstrates how to obtain the address, cell count, offset, entire column, and entire row of a specified range using Aspose.Cells for Python via .NET. It requires the Aspose.Cells library to be installed. ```python from Aspose.Cells import Workbook, Range # Create a workbook workbook = Workbook() # Access the first worksheet worksheet = workbook.worksheets[0] # Create a range A1:B3 range1 = worksheet.cells.create_range("A1:B3") # Get and print the address of the range print(f"Range Address: {range1.address}") # Get and print the cell count of the range print(f"Cell Count: {range1.cell_count}") # Create a range A1 range2 = worksheet.cells.create_range("A1") # Get and print the offset range (C3) print(f"Offset: {range2.get_offset(2, 2).address}") # Get and print the entire column of the range (A:A) print(f"Entire Column: {range2.entire_column.address}") # Get and print the entire row of the range (1:1) print(f"Entire Row: {range2.entire_row.address}") ``` -------------------------------- ### Create Workbook and Set Calculation Mode to Manual Source: https://docs.aspose.com/cells/python-net/setting-formula-calculation-mode-of-workbook Creates a new workbook, sets the formula calculation mode to Manual, and saves the workbook. This example demonstrates initializing a workbook and configuring its calculation settings from scratch. ```python import os from aspose.cells import Workbook, CalcModeType, SaveFormat # For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET # The path to the documents directory. current_dir = os.path.dirname(os.path.abspath(__file__)) data_dir = os.path.join(current_dir, "data") # Create a workbook workbook = Workbook() # Set the Formula Calculation Mode to Manual workbook.settings.formula_settings.calculation_mode = CalcModeType.MANUAL # Save the workbook output_path = os.path.join(data_dir, "output_out.xlsx") workbook.save(output_path, SaveFormat.XLSX) ``` -------------------------------- ### Build and Install pandas Source: https://docs.aspose.com/cells/python-net/using-aspose-as-pandas-engine Install the modified pandas package in editable mode. This command ensures that your changes are reflected in the installed package. ```bash # build and install pandas python -m pip install -ve . --no-build-isolation ``` -------------------------------- ### Initialize Workbook and Add Icon Sets Source: https://docs.aspose.com/cells/python-net/how-to-add-icon-sets-conditional-formatting Sets up a new Excel workbook, accesses the first worksheet, and calls methods to add various icon set conditional formatting. Finally, it saves the workbook to a specified output directory. ```python from aspose.cells import Workbook from aspose.cells import Workbook, Worksheet, CellArea, FormatConditionType, IconSetType, FormatConditionValueType, BackgroundType, TimePeriodType from aspose.pydrawing import Color from datetime import datetime import aspose.cells import os import pytest class ConditionalFormatting: def __init__(self): self._sheet = None @staticmethod def run(): # The path to the documents directory current_dir = os.path.dirname(os.path.abspath(__file__)) data_dir = os.path.join(current_dir, "data") obj = ConditionalFormatting() obj.do_test(data_dir) def do_test(self, data_dir): book = Workbook() sheet1 = book.worksheets[0] self._sheet = sheet1 self.add_default_icon_set() self.add_icon_set2() self.add_icon_set3() self.add_icon_set4() self.add_icon_set5() self.add_icon_set6() self.add_icon_set7() self.add_icon_set8() self.add_icon_set9() self.add_icon_set10() self.add_icon_set11() self.add_icon_set12() self.add_icon_set13() self.add_icon_set14() self.add_icon_set15() self.add_icon_set16() self.add_icon_set17() self.add_icon_set18() self._sheet.auto_fit_column(12) output_dir = os.path.join(data_dir, "output") if not os.path.exists(output_dir): os.makedirs(output_dir) out_fn = os.path.join(output_dir, "Testoutput.out.xlsx") book.save(out_fn, SaveFormat.XLSX) ``` -------------------------------- ### Install Marker PDF Plugin with Full Dependencies Source: https://docs.aspose.com/cells/python-net/ai-plugin-integration Install the Marker PDF plugin with all dependencies for non-PDF documents. Ensure you have Python 3.10+ and PyTorch installed. ```bash pip install marker-pdf[full] ``` -------------------------------- ### Initialize Grid.js Spreadsheet Source: https://docs.aspose.com/cells/python-net/aspose-cells-gridjs/user-guide/how-to-enable-and-disable-keyboard-events Create a Grid.js spreadsheet instance in edit mode. This is the initial setup before configuring keyboard events. ```javascript const xs = x_spreadsheet('#gridjs-demo-uid', { mode: 'edit', }); ``` -------------------------------- ### Get File Endpoint (GET) Source: https://docs.aspose.com/cells/python-net/aspose-cells-gridjs/load-spreadsheet Handles GET requests to retrieve a file by its ID. It uses the gridjs_service to fetch file bytes and returns the file for download. ```python import os from flask import Flask, request, send_file, jsonify from werkzeug.utils import secure_filename from mimetypes import guess_type # Assuming gridjs_service and guess_mime_type_from_filename are defined elsewhere # For demonstration purposes, let's mock them: class MockGridJsService: def get_file(self, file_id): # Simulate returning file bytes return b'file content' def download(self, p, uid, file_name): # Simulate download response return {"success": True} gridjs_service = MockGridJsService() def guess_mime_type_from_filename(filename): return guess_type(filename)[0] or 'application/octet-stream' app = Flask(__name__) @app.route("/GridJs/GetFile", methods=["GET"]) def get_file(): file_id = request.args.get("id") file_bytes = gridjs_service.get_file(file_id) return send_file( file_bytes, as_attachment=True, download_name=file_id, mimetype=guess_mime_type_from_filename(file_id), ) ``` -------------------------------- ### Show Menubar at Startup Source: https://docs.aspose.com/cells/python-net/aspose-cells-gridjs/user-guide/how-to-show-and-hide-menubar To display the menubar when the spreadsheet initializes, set showToolbar to true or omit it as true is the default. ```javascript const xs = x_spreadsheet('#gridjs-demo-uid', { showToolbar: true, }); ``` -------------------------------- ### Configuring Custom Context Menus on Initialization Source: https://docs.aspose.com/cells/python-net/aspose-cells-gridjs/custommenu Demonstrates how to set up custom context menu items when initializing the spreadsheet using load options. This involves setting `usedefault` to `false` and providing an array of custom items with keys, text, and callback functions. ```APIDOC ## Configuring Custom Context Menus on Initialization ### Description This section shows how to define custom context menu items when the spreadsheet is initialized. You need to set `usedefault` to `false` within the `contextMenuItems` configuration and then provide an array of `customItems`, each with a unique `key`, display `text`, and a `callback` function. ### Configuration Example ```javascript xs = x_spreadsheet('#gridjs-demo', { updateMode: 'server', updateUrl: '/GridJs2/UpdateCell', showToolbar: true, mode: 'edit', local: 'en', showContextmenu: true, contextMenuItems: { usedefault: false, customItems: [ { 'key': 'key1', 'text': 'c title 11111', 'callback': onMyActionClick1 }, { 'key': 'key2', 'text': 'c title 22222', 'callback': onMyActionClick2 } ] } }) const onMyActionClick1 = (sheet) => { console.log('my action clicked1' + sheet.data.name) }; const onMyActionClick2 = (sheet) => { console.log('my action clicked2' + sheet.data.name) }; ``` ``` -------------------------------- ### Custom Toast Function Example Source: https://docs.aspose.com/cells/python-net/aspose-cells-gridjs/how-to-customize-toast This example demonstrates how to create a mobile-optimized toast notification function that can be used with Aspose.Cells GridJs. ```APIDOC ## `mobileToast(title, content, callback)` ### Description Creates a mobile-optimized toast notification with bottom positioning, percentage-based width, and a short duration. ### Parameters - **title** (string): The title of the toast message. - **content** (string): The main content of the toast message. - **callback** (Function | undefined): A function to be called after the toast is dismissed. ### Code ```javascript function mobileToast(title, content, callback) { const toast = document.createElement('div'); Object.assign(toast.style, { position: 'fixed', bottom: '20px', left: '50%', transform: 'translateX(-50%)', background: '#323232', color: 'white', padding: '12px 24px', borderRadius: '24px', fontSize: '14px', zIndex: 10000, maxWidth: '80%', textAlign: 'center', boxShadow: '0 4px 12px rgba(0,0,0,0.3)' }); toast.textContent = `${title}: ${content}`; document.body.appendChild(toast); setTimeout(() => { document.body.removeChild(toast); if (callback) callback(); }, 2000); } // Usage with GridJs xs.customToast(mobileToast); ``` ``` -------------------------------- ### Console Output Example Source: https://docs.aspose.com/cells/python-net/find-the-root-element-name-of-xml-map This is the expected output when the sample code is executed successfully, showing the root element name of the XML Map. ```text CopyRoot Element Name of XML Map: MiscData ``` -------------------------------- ### Initialize Spreadsheet with Token Source: https://docs.aspose.com/cells/python-net/aspose-cells-gridjs/user-guide/how-to-configure-token-authentication Create a new spreadsheet instance and configure it with an access token for authentication. ```APIDOC ## Initialize Spreadsheet with Token ### Description Pass the `token` option in the constructor to set the initial authentication token. This token will be stored internally as `authToken` and used for subsequent API requests. ### Method `x_spreadsheet(selector, options)` ### Parameters #### Options Object - **token** (string) - Required - The access token to be used for authentication. ### Request Example ```javascript const xs = x_spreadsheet('#gridjs-demo-uid', { token: accessToken, }); ``` ``` -------------------------------- ### Delete Columns in GridJS Source: https://docs.aspose.com/cells/python-net/aspose-cells-gridjs/client Delete a specified number of columns starting from a given column index. Ensure `start` and `n` are valid integers. ```javascript xs.sheet.deleteColumns(start, n) ``` -------------------------------- ### Create and Format a Table with Default Styles Source: https://docs.aspose.com/cells/python-net/create-and-format-table This snippet demonstrates how to add sample data to an Excel worksheet, create a ListObject (table) from this data, and apply default table styles using Aspose.Cells. Ensure the Aspose.Cells library is installed and imported. ```python from aspose.cells import Workbook from aspose.cells.tables import TableStyleType, TotalsCalculation 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) # Create a workbook. workbook = Workbook() # Obtaining the reference of the default(first) worksheet sheet = workbook.worksheets[0] # Obtaining Worksheet's cells collection cells = sheet.cells # Setting the value 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("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(2) 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("Geitost") 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") # Add a ListObject to the worksheet list_object = sheet.list_objects.add("A1:F15") # Apply a table style list_object.table_style_type = TableStyleType.MEDIUM_2 # Save the workbook workbook.save(dataDir + "ListObject.xlsx") ``` -------------------------------- ### Delete Rows in GridJS Source: https://docs.aspose.com/cells/python-net/aspose-cells-gridjs/client Delete a specified number of rows starting from a given row index. Ensure `start` and `n` are valid integers. ```javascript xs.sheet.deleteRows(start, n) ``` -------------------------------- ### Initialize Grid.js with Custom Context Menus Source: https://docs.aspose.com/cells/python-net/aspose-cells-gridjs/custommenu Configure Grid.js to use custom context menus by setting `usedefault` to `false` and providing an array of `customItems` with keys, display text, and callback functions. ```javascript const onMyActionClick1 = (sheet) => { console.log('my action clicked1' + sheet.data.name) }; const onMyActionClick2 = (sheet) => { console.log('my action clicked2' + sheet.data.name) }; xs = x_spreadsheet('#gridjs-demo', { updateMode: 'server', updateUrl: '/GridJs2/UpdateCell', showToolbar: true, mode: 'edit', local: 'en', showContextmenu: true, // This option is for context menus; we need to set usedefault to false to load custom context menus contextMenuItems: { usedefault: false, customItems: [{ 'key': 'key1', 'text': 'c title 11111', 'callback': onMyActionClick1 }, { 'key': 'key2', 'text': 'c title 22222', 'callback': onMyActionClick2 }] } }) ``` -------------------------------- ### Insert Columns in GridJS Source: https://docs.aspose.com/cells/python-net/aspose-cells-gridjs/client Insert a specified number of columns starting from a given column index. Ensure `start` and `n` are valid integers. ```javascript xs.sheet.insertColumns(start, n) ``` -------------------------------- ### Open Existing File and Add Text Source: https://docs.aspose.com/cells/python-net/your-first-aspose-cells-application-hello-world This example demonstrates how to open an existing Excel file named 'book1.xls', write 'Hello World!' into cell A1 of the first worksheet, and save the modified workbook as a new file. Ensure 'book1.xls' exists in the same directory. ```python from Aspose.Cells import Workbook # Open an existing workbook workbook = Workbook("book1.xls") # Access the first worksheet worksheet = workbook.Worksheets[0] # Access the cells collection and add a value to a cell cell = worksheet.Cells["A1"] cell.Value = "Hello World!" # Save the workbook to a new file workbook.Save("Output.xlsx") ``` -------------------------------- ### Application Entry Point Source: https://docs.aspose.com/cells/python-net/aspose-cells-gridjs/load-spreadsheet Configures and runs the Flask application, listening on all interfaces (0.0.0.0) on port 5000 with debug mode enabled. ```python if __name__ == "__main__": # Listen on all interfaces as required app.run(host="0.0.0.0", port=5000, debug=True) ``` -------------------------------- ### Insert Rows in GridJS Source: https://docs.aspose.com/cells/python-net/aspose-cells-gridjs/client Insert a specified number of rows starting from a given row index. Ensure `start` and `n` are valid integers. ```javascript xs.sheet.insertRows(start, n) ``` -------------------------------- ### Applying and Reading Border Settings Source: https://docs.aspose.com/cells/python-net/aspose-cells-gridjs/user-guide/how-to-use-border-settings Demonstrates how to apply different border modes (outside, inside) with specified styles and colors to the current selection, and how to read the border style of a cell. ```APIDOC ## JavaScript API ```javascript const xs = x_spreadsheet('#gridjs-demo-uid', options); // Apply an outside border to the current selection. xs.sheet.data.setSelectedCellAttr('border', { mode: 'outside', style: 'thin', color: '#000000', }); // Add inside borders to the current selection. xs.sheet.data.setSelectedCellAttr('border', { mode: 'inside', style: 'dashed', color: '#ff0000', }); // Read the resulting border object from a cell. const border = xs.cellStyle(0, 0, 0).border; ``` ### Relevant functions Function | Description | Parameters | Returns ---|---|---|--- `sheet.data.setSelectedCellAttr(property, value)` | Applies a border action to the current selection immediately. | `property`: `'border'`; `value`: `{ mode, style, color }` | `void` `sheet.data.setRangeAttr(range, property, value)` | Applies a border action to a specific range. The **Format Cells** dialog uses this path when you click **Ok**. | `range`: selected range; `property`: `'border'`; `value`: `{ mode, style, color }` | `void` `cellStyle(rowIndex, colIndex, sheetIndex)` | Returns the cell style object for a cell. | `rowIndex`, `colIndex`, `sheetIndex` | `CellStyle` For border actions, the code handles these modes: `none`, `all`, `inside`, `outside`, `horizontal`, `vertical`, `top`, `bottom`, `left`, and `right`. The Border tab exposes these line styles in the UI: `thin`, `medium`, `thick`, `dashed`, and `dotted`. The resulting border data is stored in `CellStyle.border`, where each side uses the shape `top?: [style, color]`, `right?: [style, color]`, `bottom?: [style, color]`, and `left?: [style, color]`. ``` -------------------------------- ### Autofill Functionality Source: https://docs.aspose.com/cells/python-net/aspose-cells-gridjs/user-guide/autofill-options Demonstrates how to initiate the autofill process using the `data.autofill` method and re-render the table. ```APIDOC ## JavaScript API ```javascript import { CellRange } from './core/cell_range'; const xs = x_spreadsheet('#gridjs-demo-uid', options); const data = xs.sheet.data; const targetRange = new CellRange(0, 1, 4, 1); const ok = data.autofill(targetRange, 'all', msg => { console.log(msg); }); if (ok) { xs.sheet.table.render(); } // Internal option values used by the Autofill Options popup: const autofillTypes = ['copyCell', 'series', 'format', 'withoutFormat']; ``` ### Relevant functions `sheet.data.autofill(cellRange, what, error)` * Description: Validates the target range, runs the autofill copy path, and records `history` and `series` data for later option changes. * Parameters: * `cellRange`: destination `CellRange` * `what`: paste mode such as `'all'` * `error`: callback for validation errors * Returns: `boolean` `autofillOption.change(autofillType)` * Description: Rewrites the autofilled cells according to the selected Autofill Options menu item. * Parameters: * `autofillType`: `'copyCell'`, `'series'`, `'format'`, or `'withoutFormat'` * Returns: `void` In the inspected UI flow, the sheet always starts autofill with `what === 'all'`. The option popup then changes the written cells by reading `data.autofillCellInfo.history`, `data.autofillCellInfo.series`, and `data.autofillCellInfo.srcCellRange`. ``` -------------------------------- ### SVG viewBox Attribute Example Source: https://docs.aspose.com/cells/python-net/export-chart-to-svg-with-viewbox-attribute This snippet shows an example of the viewBox attribute within an SVG file generated by Aspose.Cells. It demonstrates how the attribute is structured and its typical values. ```xml ``` -------------------------------- ### Initialize Spreadsheet with Token Source: https://docs.aspose.com/cells/python-net/aspose-cells-gridjs/user-guide/how-to-configure-token-authentication Create a new spreadsheet instance and provide an access token using the `token` option. This token will be stored internally and used for authentication. ```javascript const xs = x_spreadsheet('#gridjs-demo-uid', { token: accessToken, }); ``` -------------------------------- ### Get DateTime Value from Aspose.Cells Source: https://docs.aspose.com/cells/python-net/how-to-manage-dates-and-times Demonstrates how to retrieve and display DateTime values from Excel cells using Aspose.Cells. It shows how to get the DateTime object and its formatted string representation. ```python from Aspose.Cells import Workbook, Style, CellValueType workbook = Workbook() worksheet = workbook.worksheets[0] # Set DateTime value in A1 with custom format cell_a1 = worksheet.cells["A1"] cell_a1.value = "11/23/2023 5:59:09 PM" style_a1 = cell_a1.get_style() style_a1.number = "yy-mm-dd hh:mm:ss" cell_a1.set_style(style_a1) # Set DateTime value in A2 with number format cell_a2 = worksheet.cells["A2"] cell_a2.value = "11/23/2023 5:59:09 PM" style_a2 = cell_a2.get_style() style_a2.number = "m/d/yyyy h:mm" cell_a2.set_style(style_a2) print(f"A1 is Numeric Value: {cell_a1.type == CellValueType.IS_DATE}") print("Cell A1 contains a DateTime value.") print(f"A1 DateTime Value: {cell_a1.date_time_value}") print(f"A1 DateTime String Value: {cell_a1.string_value}") print(f"A2 is Numeric Value: {cell_a2.type == CellValueType.IS_DATE}") print("Cell A2 contains a DateTime value.") print(f"A2 DateTime Value: {cell_a2.date_time_value}") print(f"A2 DateTime String Value: {cell_a2.string_value}") ``` -------------------------------- ### Get Excel Document Creation Application Version Source: https://docs.aspose.com/cells/python-net/get-the-version-number-of-the-application-that-created-the-excel-document Use the `Workbook.built_in_document_properties.version` property to get the version of the application that created the Excel document. This property is useful for identifying the compatibility or origin of a spreadsheet. ```python import jpype import aspose.cells from aspose.cells import Workbook # Establish a JVM session jpype.startJVM() # Load an Excel file workbook = Workbook("Sample.xlsx") # Get the version number of the application that created the Excel document version = workbook.built_in_document_properties.version # Print the version number print("The version of the application that created the Excel document is: " + version) # Shutdown the JVM jpype.shutdownJVM() ``` -------------------------------- ### Set Aspose License on Windows (CMD) Source: https://docs.aspose.com/cells/python-net/ai-plugin-integration Set the ASPOSE_LICENSE_PATH environment variable on Windows using the Command Prompt. ```cmd set ASPOSE_LICENSE_PATH=C:\path\to\license ``` -------------------------------- ### Get Validation Applied on a Cell using Worksheet.validations.get_validation_in_cell() Source: https://docs.aspose.com/cells/python-net/get-validation-applied-on-a-cell Use the `Worksheet.validations.get_validation_in_cell()` method by providing the row and column indices to get the data validation applied to a specific cell. This method is an alternative to `Cell.get_validation()`. ```python from Aspose.Cells import Workbook # Load a workbook workbook = Workbook("sample.xlsx") # Get the first worksheet worksheet = workbook.worksheets[0] # Get the validation applied on cell A1 (row 0, column 0) validation = worksheet.validations.get_validation_in_cell(0, 0) if validation is not None: print("Validation applied on the cell.") else: print("No validation applied on the cell.") ``` -------------------------------- ### Create Workbook and Add Data for Pie Chart Source: https://docs.aspose.com/cells/python-net/creating-pie-chart-with-leader-lines Initializes a new Workbook and populates it with data to be used as a source for a pie chart. This is the first step in creating any chart with Aspose.Cells. ```python from aspose.cells import Workbook, ChartType # Create a new workbook workbook = Workbook() # Get the first worksheet worksheet = workbook.worksheets[0] # Add sample data worksheet.cells["A1"].value = "Category" worksheet.cells["B1"].value = "Value" worksheet.cells["A2"].value = "Apples" worksheet.cells["B2"].value = 20 worksheet.cells["A3"].value = "Bananas" worksheet.cells["B3"].value = 30 worksheet.cells["A4"].value = "Cherries" worksheet.cells["B4"].value = 15 worksheet.cells["A5"].value = "Dates" worksheet.cells["B5"].value = 25 worksheet.cells["A6"].value = "Elderberries" worksheet.cells["B6"].value = 10 ``` -------------------------------- ### Flask App Initialization Source: https://docs.aspose.com/cells/python-net/aspose-cells-gridjs/load-spreadsheet Sets up the Flask application and initializes the Aspose.Cells GridJs service with specified options, including the file cache directory and base route name. ```python # app.py # ------------------------------------------------------------- # Flask application that hosts Aspose.Cells GridJs services. # ------------------------------------------------------------- from flask import ( Flask, render_template, request, jsonify, Response, send_file, abort, ) import io import gzip import mimetypes import os # Aspose.Cells GridJs imports from aspose.cellsgridjs import GridJsOptions, GridJsService app = Flask(__name__) # ------------------------------------------------------------- # GridJs service initialization # ------------------------------------------------------------- options = GridJsOptions() options.file_cache_directory = "./cache" # Cache folder (must exist) options.base_route_name = "/GridJs" # Base route used by the client gridjs_service = GridJsService(options) # Ensure cache folder exists os.makedirs(options.file_cache_directory, exist_ok=True) # ------------------------------------------------------------- # Helper: Guess MIME type from a filename ```