Tuesday, 15 July 2014

c# - Waiting open excel when program is writing data to excel -



c# - Waiting open excel when program is writing data to excel -

i have been making application read info serial port write excel(continuous).

there no problem if open current excel file after serial info written, or serial info written open current file.

the problem after info of serial received, programme writing info excel , @ same time seek open current file or open excel application out of programme (manually).

error message: error: bad extension file(exception hresult:0x800401e6(mk_e_invalidextension) line: mscorlib

serial info received >> open excel file >> write info excel >> save >>> serial info received >> open excel file >> write info excel >> save >>> after info written excel, didn't closed workbook, create invisible.

this 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 solution? can provide me sample code?

edit: master @vasi, , error.

i remember in past time did that, after write excel, close workbook , excel application. in past error when close workbook, , excel process stuck in ram, process doesn't disappear in task manager.

so, seek not close excel application , workbook, , hope process of programme faster when write info excel. , suggestion, tried close excel app, workbook , worksheet in site http://goo.gl/szwhcf

but process in task manager maintain doesn't disappear after windows form closed , error message object reference not set instance of object. sample code http://postimg.org/image/w6614hbq3/

is wrong code?

thank you

due openxml standard 1 time opened file in excel application, there no possibility open other applications/coding.

prefer comma(or semicolon) separated (we can import in excel) text file or database.

c# excel com interop

No comments:

Post a Comment