LabWindowsCVI : 将table控件中的数据保存到excel出现卡顿问题解决(转)
Posted xihong2014
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 ", table_title[j]);
}
fprintf(fps, "
");
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 ", value);
}
else fprintf(fps," ");
}
fprintf(fps, "
");
j = 1;
}
fclose(fps);
————————————————
版权声明:本文为CSDN博主「碎念HK」的原创文章,遵循CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_26682769/article/details/92978639
以上是关于LabWindowsCVI : 将table控件中的数据保存到excel出现卡顿问题解决(转)的主要内容,如果未能解决你的问题,请参考以下文章