LabWindowsCVI : 将table控件中的数据保存到excel出现卡顿问题解决(转)

将table控件中的数据保存到excel中时,要是数据太多(table控件最大行数100万多一点儿,具体记不清),会出现保存卡顿、未响应的问题;后来使用文件操作的方式保存table中的数据为xls或者txt,发现很快,根本不会出现以上问题:
1)直接保存到excel中,代码如下:
 reverse(strs,mydata,row);   // //A1:ZZ行数  
 Excel_NewApp (NULL, 1, LOCALE_NEUTRAL, 0, &ExcelAppHandle);   //create a new Application object, and obtain a handle to the object.
 Excel_GetProperty (ExcelAppHandle, NULL, Excel_AppWorkbooks, CAVT_OBJHANDLE, &ExcelWorkbooksHandle);
 Excel_WorkbooksAdd (ExcelWorkbooksHandle, NULL, CA_DEFAULT_VAL,&ExcelWorkbookHandle);
 Excel_GetProperty (ExcelAppHandle, NULL, Excel_AppSheets,CAVT_OBJHANDLE, &ExcelSheetsHandle);
 Excel_SheetsItem (ExcelSheetsHandle, NULL, CA_VariantInt(1),&ExcelWorksheetHandle);
 Excel_WorksheetActivate (ExcelWorksheetHandle, NULL);  //strs  =>>A1:列数(列标识ZZ)行数  
 ExcelRpt_WriteDataFromTableControl (ExcelWorksheetHandle, strs, hTablePanel, TABLE_DISTABLE); //write data from table control
 ExcelRpt_WorkbookSave (ExcelWorkbookHandle, sheetSavePath,ExRConst_DefaultFileFormat );   //ExRConst_Excel2       ExRConst_DefaultFileFormat
 Excel_AppQuit (ExcelAppHandle, NULL);
 CA_DiscardObjHandle(ExcelAppHandle);
 CA_DiscardObjHandle(ExcelWorkbooksHandle);
 CA_DiscardObjHandle(ExcelWorkbookHandle);
 CA_DiscardObjHandle(ExcelSheetsHandle);
 CA_DiscardObjHandle(ExcelWorksheetHandle);
123456789101112131415
2)使用文件读写的方式保存:
 int numberOfColumns;
 int Rows;
 double value;
 int i, j;
 int attributeValue;
12345
 GetProjectDir(ExcelFileName);//得到Project当前目录名
 MakePathname(ExcelFileName, "DataCache.xls", ExcelFileName);//设置保存的exce文件名
 
 FILE *fps = NULL;
 fps = fopen(ExcelFileName, "w");
 GetNumTableColumns (panelHandle, controlID, &numberOfColumns);   // 列数
 GetNumTableRows (panelHandle, controlID, &Rows);      // 行数
 for(j =1; j<=numberOfColumns; j++)
 {
  GetTableCellVal (panelHandle, controlID, MakePoint(j,1), table_title[j]);  //获取table_title名称
  fprintf(fps, "%s\t", table_title[j]);
 }
 fprintf(fps, "\n");
 for(i = 2; i<= Rows; i++)
 {
  for(j =1; j<=numberOfColumns; j++)
  {
   GetTableCellAttribute (panelHandle, controlID, MakePoint(j,i),ATTR_CELL_TYPE , &attributeValue);
   if(attributeValue == 0)
   {
    GetTableCellVal (panelHandle, controlID, MakePoint(j,i), &value); //获取数据
    fprintf(fps, "%le\t", value);
   }
   else  fprintf(fps,"\t");
  }
  fprintf(fps, "\n");
  j = 1;
 }
 fclose(fps);
————————————————
版权声明:本文为CSDN博主「碎念HK」的原创文章,遵循CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_26682769/article/details/92978639

LabWindowsCVI : 将table控件中的数据保存到excel出现卡顿问题解决(转)

上一篇:Qt 条件编译 arm windows linux 判断 跨平台


下一篇:C# 最简单的链式调用例子