# 輸出txt轉輸出excel 因為比起txt文字檔excel表格更容易看,我嘗試換成excel ```c= #ifndef HIREPERSON_H_INCLUDED #define HIREPERSON_H_INCLUDED #include <stdio.h> #include <string.h> #include "functions.h" void hirePerson(Member members[]) { int id; char name[80]; printf("Enter the number of the person you want to hire: "); scanf("%d", &id); getchar(); printf("Enter the name of the person you want to hire: "); fgets(name, sizeof(name), stdin); name[strcspn(name, "\n")] = 0; for (int i = 0; i < MAX_MEMBERS; i++) { if (members[i].id == id) { members[i].hired = 1; strcpy(members[i].name, name); break; } } FILE *fp; if ((fp = fopen ("hirelist.xls", "w")) == NULL) { printf("Open File ERROR!\n"); } else{ fprintf(fp, "編號\t是否已招募\t姓名\n"); for (int i = 0; i < MAX_MEMBERS; i++) { fprintf(fp, "%d\t%d\t%s\n", members[i].id, members[i].hired, members[i].name); } fclose(fp); } } #endif ``` ![](https://hackmd.io/_uploads/S1YGt3FDh.png) ## 失敗過程 新版(xlsx)檔案無法使用 ```c= #ifndef HIREPERSON_H_INCLUDED #define HIREPERSON_H_INCLUDED #include <stdio.h> #include <string.h> #include "functions.h" void hirePerson(Member members[]) { int id; char name[80]; printf("Enter the number of the person you want to hire: "); scanf("%d", &id); getchar(); printf("Enter the name of the person you want to hire: "); fgets(name, sizeof(name), stdin); name[strcspn(name, "\n")] = 0; for (int i = 0; i < MAX_MEMBERS; i++) { if (members[i].id == id) { members[i].hired = 1; strcpy(members[i].name, name); break; } } FILE *fp; if ((fp = fopen ("hirelist.xlsx", "w")) == NULL) { printf("Open File ERROR!\n"); } else{ fprintf(fp, "編號\t是否已招募\t姓名\n"); for (int i = 0; i < MAX_MEMBERS; i++) { fprintf(fp, "%d\t%d\t%s\n", members[i].id, members[i].hired, members[i].name); } fclose(fp); } } #endif ``` ![](https://hackmd.io/_uploads/HJf6j2KD3.png) 所以換成舊版(xls) ## 問題 ![](https://hackmd.io/_uploads/S1R3hhKP2.png) 會報錯但可以正常使用