Read in data from excel file in C

user4142890 picture user4142890 · Jan 22, 2015 · Viewed 20.3k times · Source

I need to write a program that can read the relevant information from a file and output the maintenance needs as shown in the sample output on the following slides.

I have completed the code to read from the .txt file as seen in this screen shot:

read from .txt

This is the code I have completed for the above(with an alternate method in comments):

#include <stdio.h>
#include <stdlib.h>

#include <stdio.h>
#include <stdlib.h>

int main() {

FILE *cfPtr = fopen("C:\\Users\\David O'Dea\\Desktop\\Test\\MaintenanceSchedule.txt","r");

int line = 0;

char input[255];
while (fgets(input, 255, cfPtr))
{
    //line++;
    printf("%s", input);
}
printf("\n\nEnd of program\n");

fclose(cfPtr);

return 0;
}

//int main() {
//    FILE *cfPtr = fopen("C:\\Users\\David O'Dea\\Desktop\\Test\\MaintenanceSchedule.txt","r");
//C:\\Users\\David O'Dea\\Desktop\\Test\\MaintenanceSchedule.txt

//char c;
//f = fopen("C:\\Users\\David O'Dea\\Desktop\\Test\\MaintenanceSchedule.txt", "rt");

//while ((c = fgetc(f)) != EOF){
//  printf("%c", c);
//}

//fclose(f);
//return 0;
//}

I am not sure how to complete the second task of reading in from the .xlsx file so that the result is as below:

read from .xlsx

Answer

Mohit Jain picture Mohit Jain · Jan 22, 2015
  • Solution 1: Search for a library that can enable you reading .xlsx file.
  • Solution 2: Write your own parser for .xlsx format. .xlsx is an open format. .xlsx is an ooxml format, so it is essentially a zip formatted compressed file. You can inflate the file and check the releavant section (document.xml if I remember correctly) and parse the ``.xml` file.