read data from excel using c

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cs21sd
    New Member
    • Mar 2006
    • 3

    #1

    read data from excel using c

    Hi,

    I am trying to read data from an excel file, using C. I have been advised that I must use arrays, but I am completely stuck onto how to do this.

    Any help would be very much appreciated!

    Thanks,

    S
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    What is the basic approach you are using?

    Do you have the format for an excel file?

    Comment

    • cs21sd
      New Member
      • Mar 2006
      • 3

      #3
      Ummm,

      I just need to extract data from an excel file from random. There will be a table with n columns and n rows, but i need to extract the data within this one table somehow, using arrays.

      I've been lookin around the net, but havent got anywhere :(

      Comment

      • BugHunter
        New Member
        • Mar 2006
        • 8

        #4
        cs21sd,

        Excel tables can be redeclared as ODBC data sources in Windows 2000 and newer. Perhaps you could connect your excel sheet as ODBC source and then access the data via ODBC headers (expect that all newer/commercial compilers should have them, Borland Builder and MSVC do).

        You can't access excel sheets directly (read the file itself), it's MS Office format which is not open. Afaik MS Office documents consit of objects/modules to support OLE and embed other office documents. So it's pretty unlikely you will access MS documents with yur own programm.

        One more option (and the most simple one): write your application in VBA (visual basic for applications). This VB Version is embedded in MS Office and supports VERY many different options to manipulate Office Documents programmaticall y. I guess, this is the most adviceable choice.

        Comment

        • BugHunter
          New Member
          • Mar 2006
          • 8

          #5
          Oh, uh,

          Just a thought: if your excel sheet is defined as ODBC data source you can access it for read and write with virtually any programmatic option. I would write into and read from with PHP for example.

          One more thought: if you maintain the tables not in MS-only XLS format but use CSV sheets, you can access them with everything you want, since they are text only.

          Comment

          • Banfa
            Recognized Expert Expert
            • Feb 2006
            • 9067

            #6
            Originally posted by BugHunter
            One more thought: if you maintain the tables not in MS-only XLS format but use CSV sheets, you can access them with everything you want, since they are text only.
            Going on from this since a CSV value file is text it can easily be read into a program.

            You have to read a table, the reason that you are being advised to use arrays is that a 2 dimensional array is very like a table in that you access it using 2 indexes which, in this case can be thought of as your row and column.

            Do you understand what an array is?

            You could easily read the file into an 2 dimensional array of strings. Of course in C a string is a 1 dimensional array of characters so what you need is a 3 dimensional array of characters delared something like

            Code:
            #define MAX_ROWS       10
            #define MAX_COLUMNS    10
            #define MAX_CELL_TEXT  20
            
            char Table[MAX_COLUMNS][MAX_ROWS][MAX_CELL_TEXT+1];
            Note the plus 1 is to take account of the zero terminator that c uses in strings.

            Then all you have to do is read the lines of the CSV file, parse each line into it's separate cells and plonk the contents of each cell into the correctentry in the array.

            Comment

            • cs21sd
              New Member
              • Mar 2006
              • 3

              #7
              Thanks alot guys, I will try these now.

              :)

              Comment

              Working...