in2xl package — in2xl 0.1.0 documentation

# in2xl package

## Subpackages

- in2xl.src package
  - Module contents

## Submodules

## in2xl.setup module

## Module contents

class in2xl.Workbook

  Bases: `object`

  The Workbook class represents an Excel workbook.

  Attributes:

    xmain (str): A string representing the main namespace. xrel (str): A string representing the relationship namespace. xchart (str): A string representing the chart namespace. xdsgn (str): A string representing the drawing namespace. temp (str): A string representing the temporary path where the Excel workbook is copied. wb (Element): An Element object representing the workbook.xml file. wb_dict (dict): A dictionary of worksheet names and their corresponding filenames. wb_id_dict (dict): A dictionary of worksheet names and their corresponding sheet Ids. content (list): A list of all files and directories in the zip archive. chart_dict (dict): A dictionary of worksheet names and the corresponding chart filenames. wb_state (dict): A dictionary of worksheet names and their corresponding states (visible, hidden, etc.).

  Methods:

    __init__(self): Initializes a new instance of the Workbook class. __worksheets(self): Extracts worksheet information from a given Excel file. read_xlsx(self, path: str = None) -> Worksheets: Reads an Excel workbook from the specified file path and returns an instance of Worksheets.

  read_xlsx(path: str | None = None) → Worksheets

    Reads an Excel workbook from the specified file path and returns an instance of Worksheets.

    Args:

      path (str): The file path of the Excel workbook to read.

    Returns:

      Worksheets: An instance of the Worksheets class that contains the data extracted from the workbook.

    Raises:

      ValueError: If the path argument is None.

class in2xl.Worksheets(parent=None, key=None)

  Bases: `object`

  Represents a collection of worksheets extracted from an Excel workbook.

  Args:

    parent (object): The parent object. key (str): The key for the current worksheet.

  Attributes:

    temp (str): The path of the temporary file created to hold the Excel workbook data. xmain (str): The XML namespace for main XML elements. xdsgn (str): The XML namespace for design XML elements. wb_dict (dict): A dictionary mapping worksheet names to their corresponding XML file names. wb_id_dict (dict): A dictionary mapping worksheet names to their corresponding IDs. wb (etree._Element): The XML tree representing the workbook. wb_state (dict): A dictionary mapping worksheet names to their corresponding visibility states. content (list): A list of the names of all files in the Excel workbook. stree (None): A reference to the worksheet XML tree. key (str): The name of the current worksheet. _state (str): The visibility state of the current worksheet. sheet (str): The name of the XML file that represents the current worksheet. tree (None): A reference to the XML tree for the current worksheet. never (bool): A flag that indicates whether the current worksheet has never been accessed. check (tuple): A tuple of numeric types to check against for float values.

  Methods:

    __init__(self, parent=None, key=None): Initializes a new instance of the Worksheets class. __getitem__(self, key): Retrieves a worksheet by name from the Excel workbook. state(self) -> str: Returns/Sets the state of the worksheets object. __change_dim(self, xml, row, column): Changes the dimensions of the specified cell range. __change_xml(self, xml, row, column, value): Insert data into an XML sheet. __change_strxml(self, value): Find, add or changes the value of a specified XML tag within the string table element __create_SubEl(self, main, tag, attrib={}, text=None): Creates a new sub-element with the given tag and attributes under the specified main element. __clean_formula(self): Removes any child elements with tag ‘v’ under each ‘f’ element in the XML tree of the class instance. __get_strxml(self): Retrieves and parses the XML content from the ‘xl/sharedStrings.xml’ file in the Excel workbook. __get_xml(self): Reads the XML data for the current worksheet from the temporary file and stores it in self.tree. __write_state(self, value): Update the state attribute of a sheet in the workbook. __write_xml(self): This method writes the current XML tree to the corresponding worksheet file within the Excel workbook file. __write_strxml(self): Write the shared strings XML to the temporary zip file. close(self) -> None: Close the workbook by removing the temporary file. insert(self, data: Union(str, int, float, pd.DataFrame), row: int = 1, column: int = 1, axis: int = 0, header: bool = True, index: bool = False ) -> None: Insert data into the worksheet. Convert the input data into an array and pass it to the XML converter. save(self, path: str = None) -> None: Saves the converted Excel file to the specified path

  close() → None

    Close the workbook by removing the temporary file.

  insert(data: Union(str, int, float, pd.DataFrame), row: int = 1, column: int = 1, axis: int = 0, header: bool = True, index: bool = False) → None

    Insert data into the worksheet. Convert the input data into an array and pass it to the XML converter.

    Args:

      data (Union[str, int, float, pd.DataFrame]): Data to be inserted. row (int, optional): Row number where the data is to be inserted. Defaults to 1. column (int, optional): Column number where the data is to be inserted. Defaults to 1. axis (int, optional): 0 to insert data row-wise and 1 to insert data column-wise. Defaults to 0. header (bool, optional): True to include headers in the data, False otherwise. Defaults to True. index (bool, optional): True to include index in the data, False otherwise. Defaults to False.

  save(path: str | None = None) → None

    Saves the converted Excel file to the specified path

    Args:

      path (str): The file path of the Excel workbook to read.

    Raises:

      ValueError: If the path argument is None.

  property state: str

    Returns the current state of the worksheets object.

    Returns:

      str: The current state of the worksheets object.