程序将数据写入excel时等待open excel [英] Waiting for open excel while program is writing data to excel

查看:134
本文介绍了程序将数据写入excel时等待open excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在创建从串口读取数据的应用程序,然后将其写入excel(连续)。



如果在写入串行数据后打开当前的excel文件,或者写入了串行数据,那么打开当前文件就没有问题。



问题是收到序列数据后,程序正在将数据写入excel,同时我尝试打开当前文件或从程序外打开另一个excel应用程序(手动)。



>错误消息:错误:文件扩展名不正确(例外情况来自

> HRESULT:0x800401E6(MK_E_INVALIDEXTENSION)行:mscorlib



收到的串行数据>>打开Excel文件>>将数据写入Excel>>保存为>>>收到的串行数据>>打开Excel文件>>将数据写入Excel>>保存as>>>

将数据写入excel后,我没有关闭工作簿,只是让它不可见。





这是我的示例代码



I have been making application that read data from serial port then write it to excel(continuous).

There is no problem if i open current excel file after that the serial data is written, or the serial data was written then i open the current file.

The problem is after data of serial received, then program is writing data to excel and at the same time i try to open the current file or open another excel application from out of program (manually).

> error message: error: Bad extension for file(Exception from
> HRESULT:0x800401E6(MK_E_INVALIDEXTENSION) Line: mscorlib

Serial data received >> Open excel file >> Write data to excel >> Save as >>> Serial data received >> Open excel file >> Write data to excel >> Save as >>>
After data is written to excel, i didn't closed the workbook, i just make it invisible.


This is my sample code

Excel.Application oXL;
 Excel._Workbook oWB;
 Excel._Worksheet oSheet;
 .....
 oXL = new Excel.Application();
 oWB = oXL.Workbooks.Open("C:\\Folder\\SerialData" + filenumber + ".xlsx", 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
 oSheet = (Excel._Worksheet)oWB.Worksheets["Sheet" + sheetnumber];
 .....
 oWB.SaveAs("C:\\Folder\\SerialData" + filenumber + ".xlsx",Excel.XlFileFormat.xlWorkbookDefault, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);





解决方案是什么?你能给我一些示例代码吗?

谢谢



What is the solution? Can you provide me some sample code?
Thank you

推荐答案

这篇关于程序将数据写入excel时等待open excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆