{"id":18535204,"url":"https://github.com/maximlevchenko/cpp-custom-excel","last_synced_at":"2025-05-15T00:17:02.447Z","repository":{"id":249990189,"uuid":"833159831","full_name":"MaximLevchenko/CPP-Custom-Excel","owner":"MaximLevchenko","description":"This C++ project provides a robust implementation of a spreadsheet processor, simulating functionality typical of software like Microsoft Excel or Google Sheets.","archived":false,"fork":false,"pushed_at":"2024-09-01T10:50:51.000Z","size":3133,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-26T03:12:57.588Z","etag":null,"topics":["abstraction","cpp","incapsulation","inheritance","makefile","oop","polymorphism"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MaximLevchenko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-24T13:21:41.000Z","updated_at":"2024-09-01T10:50:54.000Z","dependencies_parsed_at":"2024-08-20T23:45:47.907Z","dependency_job_id":null,"html_url":"https://github.com/MaximLevchenko/CPP-Custom-Excel","commit_stats":null,"previous_names":["maximlevchenko/excel","maximlevchenko/cpp-custom-excel"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaximLevchenko%2FCPP-Custom-Excel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaximLevchenko%2FCPP-Custom-Excel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaximLevchenko%2FCPP-Custom-Excel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaximLevchenko%2FCPP-Custom-Excel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MaximLevchenko","download_url":"https://codeload.github.com/MaximLevchenko/CPP-Custom-Excel/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239249123,"owners_count":19607160,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abstraction","cpp","incapsulation","inheritance","makefile","oop","polymorphism"],"created_at":"2024-11-06T19:20:48.682Z","updated_at":"2025-02-17T07:21:55.943Z","avatar_url":"https://github.com/MaximLevchenko.png","language":"C++","readme":"# **Spreadsheet Processor Project** \n\n## **Overview**\n\nThis project is a comprehensive C++ implementation of a spreadsheet processor, similar to widely-used software like Microsoft Excel or Google Sheets. It supports a range of functionalities including arithmetic operations, cell referencing (both absolute and relative), text handling, and complex expression evaluation. The project is designed to be modular and maintainable, allowing easy extension and modification.\n\n## **Key Features**\n\n- **Arithmetic Operations**: Perform addition, subtraction, multiplication, division, and exponentiation directly within cells.\n- **Cell Referencing**: Supports both absolute (`$A$1`) and relative (`A1`) references, allowing for dynamic updates and formula recalculations.\n- **Text Handling**: Cells can store and manage text, including special characters and quotes.\n- **Expression Evaluation**: Evaluate complex expressions that reference other cells, enabling dynamic and powerful data manipulation.\n- **Cyclic Dependency Detection**: Automatically detects and handles cyclic dependencies in cell references to prevent infinite loops.\n- **Persistence**: Save and load the entire spreadsheet state, ensuring that data is preserved between sessions.\n\n## **Core Classes**\n\n### **`CSpreadsheet`**\nThe central class that manages the spreadsheet's state, processes cell operations, and handles the evaluation of expressions.\n\n### **`CPos`**\nRepresents the position of a cell in the spreadsheet using a row and column index, supporting operations necessary for cell referencing and manipulation.\n\n### **`ExprElement`**\nAn abstract base class representing elements that can be part of an expression, such as constants, operations, or references.\n\n### **Derived Classes of `ExprElement`**:\n- **`Constant`**: Represents a numeric constant.\n- **`StringVariable`**: Handles string values in cells.\n- **`Reference`**: Manages references to other cells.\n- **`BinaryOperation`**: Represents binary operations like addition or multiplication.\n- **`UnaryOperation`**: Represents unary operations like negation.\n- **`Range`**: Handles ranges of cells.\n- **`FunctionCall`**: Supports function calls within expressions.\n\n\n## **Usage**\n\n- **Setting Cell Values**: Cells can be assigned numbers, strings, or expressions.\n- **Evaluating Expressions**: Expressions are evaluated based on the spreadsheet's current state.\n- **Loading and Saving**: The spreadsheet's state can be saved to a file and loaded back to continue where you left off.\n\n## Examples of Usage\n\nBelow are some examples demonstrating how to use the spreadsheet processor to perform various operations.\n\n### 1. Basic Cell Operations\n\nSet cell values to numbers, text, or formulas and retrieve the evaluated results:\n\n```cpp\nCSpreadsheet sheet;\nsheet.setCell(CPos(\"A1\"), \"10\");\nsheet.setCell(CPos(\"A2\"), \"20.5\");\nsheet.setCell(CPos(\"A3\"), \"3e1\");  // Scientific notation for 30\nsheet.setCell(CPos(\"A4\"), \"=40\");  // Formula assigning value 40\nsheet.setCell(CPos(\"A5\"), \"=5e+1\"); // Formula with scientific notation\nsheet.setCell(CPos(\"A6\"), \"raw text with any characters, including a quote \\\" or a newline\\n\");\nsheet.setCell(CPos(\"A7\"), \"=\\\"quoted string, quotes must be doubled: \\\"\\\". Moreover, backslashes are needed for C++.\\\"\");\n\n// Retrieve cell values\nassert(valueMatch(sheet.getValue(CPos(\"A1\")), CValue(10.0)));\nassert(valueMatch(sheet.getValue(CPos(\"A2\")), CValue(20.5)));\nassert(valueMatch(sheet.getValue(CPos(\"A3\")), CValue(30.0)));\nassert(valueMatch(sheet.getValue(CPos(\"A4\")), CValue(40.0)));\nassert(valueMatch(sheet.getValue(CPos(\"A5\")), CValue(50.0)));\nassert(valueMatch(sheet.getValue(CPos(\"A6\")), CValue(\"raw text with any characters, including a quote \\\" or a newline\\n\")));\nassert(valueMatch(sheet.getValue(CPos(\"A7\")), CValue(\"quoted string, quotes must be doubled: \\\". Moreover, backslashes are needed for C++.\")));\n```\n### 2. Arithmetic and Formula Calculations\nSet formulas and perform calculations:\n```cpp\nCSpreadsheet sheet;\nsheet.setCell(CPos(\"A1\"), \"10\");\nsheet.setCell(CPos(\"A2\"), \"20\");\nsheet.setCell(CPos(\"B1\"), \"=A1+A2*2\");  // B1 = 10 + 20*2 = 50\nsheet.setCell(CPos(\"B2\"), \"= -A1 ^ 2 - A2 / 2\");  // B2 = -(10^2) - 20/2 = -110\nsheet.setCell(CPos(\"B3\"), \"= 2 ^ $A$1\");  // B3 = 2^10 = 1024\n\n// Retrieve and validate the results\nassert(valueMatch(sheet.getValue(CPos(\"B1\")), CValue(50.0)));\nassert(valueMatch(sheet.getValue(CPos(\"B2\")), CValue(-110.0)));\nassert(valueMatch(sheet.getValue(CPos(\"B3\")), CValue(1024.0)));\n```\n### 3. Handling Cyclic Dependencies\nDetect and handle cyclic dependencies between cells:\n```cpp\nCSpreadsheet sheet;\nassert(sheet.setCell(CPos(\"A1\"), \"=A2\")); // Sets A1 to reference A2\nassert(sheet.setCell(CPos(\"A2\"), \"=A1\")); // Sets A2 to reference A1\n\n// Attempting to get the value should detect a cyclic dependency\ntry {\n    sheet.getValue(CPos(\"A1\"));\n} catch (const std::logic_error \u0026e) {\n    std::cout \u003c\u003c \"Detected cyclic dependency: \" \u003c\u003c e.what() \u003c\u003c std::endl;\n}\n```\n### 4. Copying Ranges of Cells\nCopy a range of cells and paste it into another location:\n```cpp\nCSpreadsheet sheet;\nsheet.setCell(CPos(\"D0\"), \"10\");\nsheet.setCell(CPos(\"D1\"), \"20\");\nsheet.setCell(CPos(\"F0\"), \"=D0+5\");  // F0 = 10 + 5 = 15\nsheet.copyRect(CPos(\"G0\"), CPos(\"F0\"), 1, 1);  // Copy F0 to G0\n\n// Validate copied values\nassert(valueMatch(sheet.getValue(CPos(\"G0\")), CValue(15.0)));\n```\n### 5. Saving and Loading Spreadsheets\nPersist the spreadsheet to a stream and restore it from the stream:\n```cpp\nCSpreadsheet sheet;\nsheet.setCell(CPos(\"A1\"), \"10\");\nstd::ostringstream savedState;\nsheet.save(savedState);  // Save the state\n\nstd::istringstream toLoad(savedState.str());\nsheet.load(toLoad);  // Load the saved state\n\nassert(valueMatch(sheet.getValue(CPos(\"A1\")), CValue(10.0)));  // Validate restored value\n```\n## **Building and Running**\n\nThe project is organized into separate source files for clarity and maintainability. You can build and run the project using the provided Makefile.\n\n### **Using Makefile**\n\n1. **Build the project**:\n   ```bash\n   make\n   ```\n2. **Run the executable**:\n```bash\n./excel\n```\nThe Makefile handles all necessary dependencies and compilation flags.\n\n3. **Clean the build:**\n```bash\nmake clean\n```\n\n## Conclusion\nThis spreadsheet processor project demonstrates the power of C++ in building complex, maintainable, and efficient software applications.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaximlevchenko%2Fcpp-custom-excel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaximlevchenko%2Fcpp-custom-excel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaximlevchenko%2Fcpp-custom-excel/lists"}