473,387 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Writing to file and Excel

I am designing a data acquisition program that peridically collects
data from a panel and writes to a file. The way I am doing it right
now, every time I have data from the panel, I open the file, write my
data, and then close the file. The generated file itself is a text file
that is formatted either comma separated or tab separeted.

My problem is that the file my app generates can and probably will be
opened by the user in MS Excel. When MS Excel opens the file, it
somehow has exclusive access to it and when I try to open the file for
writing in my program, I get a file exception. I have tried keeping the
file open (instead of opening, writing and closing) during the duration
of the program but the result is the same.

My question is: Is there a way to open the file with my application so
that MS Excel cannot have exclusive access to it and opens it as read
only (sort of what happens when you try to open the same file with two
instances of MS Excel - the 2nd one would give you a message saying
that the file can only be opened as read-only because it is locked by
another user). That way, my application can continue logging data
regardless of what program the user opens the data file with. I have
tried messing around with FileShare enumeration but so far haven't had
much success.

Thanks in advance.

Jul 3 '06 #1
1 2103
Anybody with any idea on how to do this? Surprised not to find a single
response in about 24 hours.

RahimAsif wrote:
I am designing a data acquisition program that peridically collects
data from a panel and writes to a file. The way I am doing it right
now, every time I have data from the panel, I open the file, write my
data, and then close the file. The generated file itself is a text file
that is formatted either comma separated or tab separeted.

My problem is that the file my app generates can and probably will be
opened by the user in MS Excel. When MS Excel opens the file, it
somehow has exclusive access to it and when I try to open the file for
writing in my program, I get a file exception. I have tried keeping the
file open (instead of opening, writing and closing) during the duration
of the program but the result is the same.

My question is: Is there a way to open the file with my application so
that MS Excel cannot have exclusive access to it and opens it as read
only (sort of what happens when you try to open the same file with two
instances of MS Excel - the 2nd one would give you a message saying
that the file can only be opened as read-only because it is locked by
another user). That way, my application can continue logging data
regardless of what program the user opens the data file with. I have
tried messing around with FileShare enumeration but so far haven't had
much success.

Thanks in advance.
Jul 4 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Deepa | last post by:
I am writing a console app in c# wherein am converting a dataset into a CSV file. It works fine. But I have some values in the dataset which have a comma within(eg. A,B,C). When I view the CSV file...
6
by: Paul | last post by:
I was wondering if anyone has had an issue where using vba code to read an excel file and import the data into an access table some records are not imported from the excel file. It seems looking at...
1
by: Tomas Vera | last post by:
Hello All, I'm having trouble writing some special characters to an XML file. I need to output a XMLSS formatted file to be read by Excel. In some cells there will be some text that contains...
3
by: RJN | last post by:
Hi I've a template excel file which has all the calculations defined. There are certain input values to be entered which gives a lot of output to the user. I don't want to expose the excel sheet...
2
by: arvind1083 | last post by:
I need help for writing a excel file. As in one excel file there could be more than one sheets so I want to know how can I give name to different sheets and select a particular sheet for writing or...
0
by: shintu | last post by:
Hallo, I am trying to write french accented characters é è ê in Excel worksheet using my perl script , But I am stuck here as I couldnt find a way of writing it !: My code: use strict;...
3
by: thanawala27 | last post by:
Hi, I had problems writing in an existing Excel File. There is an excel file with a worksheet. I would like to open this existing Excel file and add another worksheet and write data into it....
1
by: =?Utf-8?B?ZmhpbGxpcG8=?= | last post by:
We have a code snippet that downloads data to Excel. it is writing row by row. This causes a performance issue. Any ideas on how to speed this up will be appreciated. Please find below an...
20
by: Marin Brkic | last post by:
Hello all, please, let me apologize in advance. English is not my first language (not even my second one), so excuse any errors with which I'm about to embarass myself in front of the general...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.