Problem making a spreadsheet writable

G

Guest

I'm using C# to open a spreadsheet invisibly, read some data from it, then
write back to it. The problem is that it it is not coming up editable - it
errors when I try to write to a cell. However, if I open the spreadsheet
visibly, after a number of seconds a dialog pops up "File xxx is now
available for editing. Choose Read-Write to open it for editing", and if you
click the Read-Write button, it works OK.

Here's my code for opening the spreadsheet. The comment is something I found
for the parameters C# needs (since it doesn't handle optional parameters like
VB).
So I'm setting ReadOnly = false, IgnoreReadOnlyRecommended = true, and
Editable = true.

What is wrong? Why does it take the user interaction to open it as
editable/writable? And since it takes about 12-14 seconds for that Read-Write
dialog to pop up, it's unacceptable.


/*
* Workbooks.Open(
[In] string Filename,
[In, Optional] object UpdateLinks,
[In, Optional] object ReadOnly,
[In, Optional] object Format,
[In, Optional] object Password,
[In, Optional] object WriteResPassword,
[In, Optional] object IgnoreReadOnlyRecommended,
[In, Optional] object Origin,
[In, Optional] object Delimiter,
[In, Optional] object Editable,
[In, Optional] object Notify,
[In, Optional] object Converter,
[In, Optional] object AddToMru,
[In, Optional] object Local,
[In, Optional] object CorruptLoad)
*/

Excel.Workbook obWb = obWorkBooks.Open(
filePath,
System.Type.Missing,
bReadOnly,
System.Type.Missing,
System.Type.Missing,
System.Type.Missing,
true,
System.Type.Missing,
System.Type.Missing,
!bReadOnly,
System.Type.Missing,
System.Type.Missing,
System.Type.Missing,
System.Type.Missing,
System.Type.Missing);
 
G

Guest

Never mind - dumb mistake on my part. There's nothing wrong with my code to
open the spreadsheet; I had used a filestream along with the OpenFileDialog
and tried to open the spreadsheet before closing the stream - so the stream
already had the file opened. Actually, in this case I didn't need the stream
at all (I had copied from some other code where I did).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top