Hi SAGAR PATIL,
Fortunately, I just have this relevant experience.
If you want to create the .xlsx file, you can create the .csv file, then use the office excel, you can open it in the excel mode.
Now, give you the main code how to open and write the .csv file.
int main (void)
{
uint16 i,j;
FATFS fs;
FRESULT fr;
FIL fil;
UINT bw;
char file_name1[12]="Test.csv";
char file_name2[12]="Test.txt";
System_init();
spiInit(SPI0_BASE_PTR , Master);
fr= f_mount(&fs,file_name1,0);
if(fr)
{
printf("\nError mounting file system\r\n");
for(;;){}
}
fr = f_open(&fil, file_name1, FA_WRITE | FA_OPEN_ALWAYS);
if(fr)
{
printf("\nError opening text file\r\n");
for(;;){}
}
fr = f_write(&fil, "Test1 ,Test2 ,Test3 ,Test4 \r\n", 29, &bw);
if(fr)
{
printf("\nError write text file\r\n");
for(;;){}
}
fr = f_close(&fil);
if(fr)
{
printf("\nError close text file\r\n");
for(;;){}
}
while(1)
{
for(i=0;i<10;i++) for(j=0;j<65535;j++);
printf("\ntest_sd\n");
}
}
Take care, change row, you just need to use ","
Just linke write:Test1 ,Test2 ,Test3 ,Test4 , it will have 4 rows.
Then, after you run it, you will get the excel file:

If you want to write the new line data in the excel, use these functions in the fatfs:
fr = f_open(&fil, file_name, FA_WRITE | FA_OPEN_ALWAYS);
new_line = f_size(&fil);
fr = f_lseek(&fil, new_line);
fr = f_write(&fil, sd_sensor_str[i], strlen(sd_sensor_str[i]), &bw);
if(fr)
{
}
fr = f_sync(&fil);
if(fr)
{
}
Wish my old experience for fatfs will help you!
If you still have question, just let me know!
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------