码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2020-02-23 09:48:36      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:card   hand   ane   fps   协议   dir   pps   文章   windows   

将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出现卡顿问题解决(转)

标签:card   hand   ane   fps   协议   dir   pps   文章   windows   

原文地址:https://www.cnblogs.com/xihong2014/p/12348512.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!