How To Create ".xlsx File" from periph_sdmmc Example for LPC43s67

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How To Create ".xlsx File" from periph_sdmmc Example for LPC43s67

2,476件の閲覧回数
sagarpatil
Contributor II

Hi All,

Can anybody suggest how to create ".xlsx" file format file from periph_sdmmc Example code.

Actually as per my project requirement i need to put sensor data into Excel Format.

Any Leads will be Helpful.

Thanks and regards,

sagar,

0 件の賞賛
返信
2 返答(返信)

1,998件の閲覧回数
converse
Senior Contributor V

Do you REALLY want .xlsx format file, or just the ability to load your values (easily) into a spreadsheet? Microsofts .xlsx format is very complex and difficult to produce on a small MCU - it is a compressed (zipped, actually) XML file. If you want to load easiyl into a spreadsheet, the easiest is just to produce a CSV (comma separated values) text file. See Comma-separated values - Wikipedia 

0 件の賞賛
返信

1,998件の閲覧回数
kerryzhou
NXP TechSupport
NXP TechSupport

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); //SPI driver

     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);//create csv file
     if(fr)
     {
          printf("\nError opening text file\r\n");
          for(;;){}
     }
     fr = f_write(&fil, "Test1 ,Test2 ,Test3 ,Test4 \r\n", 29, &bw); //create the item in the excel
     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:

42.jpg

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);//FA_OPEN_ALWAYS

        new_line = f_size(&fil);
      fr = f_lseek(&fil, new_line);// change pointer to new line
  
        fr = f_write(&fil, sd_sensor_str[i], strlen(sd_sensor_str[i]), &bw); //write new line
      if(fr)
      {
      //    printf("\nError write text file\r\n");
        //  NoneSDflag = 0;
      }    

      fr = f_sync(&fil);// do synchronization, then you don't need to close the file.
      if(fr)
      {
      //    printf("\nError close text file\r\n");
        //  NoneSDflag = 0;
      }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

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!
-----------------------------------------------------------------------------------------------------------------------

0 件の賞賛
返信