Thread: C: Spreadsheet Excel-like table implementation

  1. #1
    Registered User
    Join Date
    Nov 2019
    Posts
    7

    C: Spreadsheet Excel-like table implementation

    Hello, I have one theoretical question.

    I have a project (C language) where I implement multiple operations over a spreadsheet, that looks like this (and will be given in a .txt file):

    EXAMPLE:

    Exercise : Points : Project
    First programs: 0:
    Loops, types: 0:
    Arrays: 0:
    Function 1: 0:
    Structures: 2:
    Indicators: 2:
    Function 2: 1:
    Malloc, dbg: 2:
    : 0:
    : 0:
    Iteration, recursion: 2:
    Dynamic structures: 2:


    ":" will separate individual cells.
    Operations that I have to implement will be, for example, to delete specific row, add new column, change value of cell and so on...

    What would be the best data structure to use for this kind of spreadsheet?

    I tried to do it with an array, but in case of, for example, resizing table or adding new cells, I have to move all elements and that is not really efficient. I'm sure there's a better way.
    Thanks for any help.
    Last edited by VasilP; 09-27-2020 at 02:08 PM.

  2. #2
    Registered User
    Join Date
    Sep 2020
    Posts
    162
    This might give you ideas:

    Sparse Matrix and its representations | Set 1 (Using Arrays and Linked Lists) - GeeksforGeeks

    A structures that have a "row", "column" and "contents" attribute is most likely the simplest, allowing for fast resizing and inserting of cells, rows and columns.

    However it can make efficiently displaying a small view of a large spreadsheet a harder problem.

  3. #3
    Registered User
    Join Date
    Oct 2020
    Posts
    3
    It would work hamster , if we done it code through the doubly linked lists . ! Sam Zous

  4. #4
    Registered User
    Join Date
    May 2012
    Posts
    467
    Quote Originally Posted by VasilP View Post
    Hello, I have one theoretical question.

    I have a project (C language) where I implement multiple operations over a spreadsheet, that looks like this (and will be given in a .txt file):

    EXAMPLE:

    Exercise : Points : Project
    First programs: 0:
    Loops, types: 0:
    Arrays: 0:
    Function 1: 0:
    Structures: 2:
    Indicators: 2:
    Function 2: 1:
    Malloc, dbg: 2:
    : 0:
    : 0:
    Iteration, recursion: 2:
    Dynamic structures: 2:


    ":" will separate individual cells.
    Operations that I have to implement will be, for example, to delete specific row, add new column, change value of cell and so on...

    What would be the best data structure to use for this kind of spreadsheet?

    I tried to do it with an array, but in case of, for example, resizing table or adding new cells, I have to move all elements and that is not really efficient. I'm sure there's a better way.
    Thanks for any help.

    Make a "cell" structure which consists of a character pointer and a double. When the character pointer is null, the double data is valid, unless it is NaN, when the cell is empty. This approach won't scale up (you'll need a union if you want to support lots of data types) but it will work for a 2-type cell. Then have an array of cells which is flat but you treat as 2D.

    Wrap it in a structure which contains width, height, and, maybe, column headers (or you could treat the first row of cells as the headers, I'll leave that up to you).

    Write the insert / delete functions so that they return entire new structures. Don't worry about efficiency. The spreadsheets have to be far larger than any human could mange before this becomes an issue.
    I'm the author of MiniBasic: How to write a script interpreter and Basic Algorithms
    Visit my website for lots of associated C programming resources.
    https://github.com/MalcolmMcLean


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need to use C to create/edit excel spreadsheet
    By jjd228 in forum Windows Programming
    Replies: 7
    Last Post: 01-12-2011, 10:51 AM
  2. Dissecting an Excel XML spreadsheet
    By desmond5 in forum C++ Programming
    Replies: 1
    Last Post: 05-22-2008, 04:32 PM
  3. Replies: 2
    Last Post: 11-30-2006, 08:04 AM
  4. Exporting to spreadsheet (excel or other)
    By jpiepgrass in forum C Programming
    Replies: 3
    Last Post: 07-30-2004, 05:44 PM
  5. Is it possible to write into an Excel spreadsheet?
    By rtsc17 in forum C++ Programming
    Replies: 6
    Last Post: 09-18-2003, 10:15 AM

Tags for this Thread