Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
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
Posted
Comments
bonjot 23-Jun-14 5:31am    
can anybody help me?
Rob Branaghan 23-Jun-14 17:03pm    
At which part of your code triggers error.
Also, if this is COM, are you marshaling the COM object when you finish using it?
bonjot 7-Jul-14 13:19pm    
yes sir, i did it. marshaling workbook and excel apps.
i change my question to this
http://www.codeproject.com/Questions/794140/Write-to-active-excel-using-epplus-csharp
:D
gggustafson 23-Jun-14 20:13pm    
Attempting to open Excel when another application is using it may easily cause the behavior you observe.

Are you able to write to the Excel sheet (your code does not contain the serial port code).

Do you repeatedly call the code you supplied?
bonjot 7-Jul-14 13:21pm    
that is just sample sir, not my complete code.
but i have changed my question here
http://www.codeproject.com/Questions/794140/Write-to-active-excel-using-epplus-csharp
too tired using interop excel -_-
but still welcome for answer of this question :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900