ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Problem making a spreadsheet writable (https://www.excelbanter.com/excel-programming/375247-problem-making-spreadsheet-writable.html)

Scott B[_2_]

Problem making a spreadsheet writable
 
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);



--
Scott B

Scott B[_2_]

Problem making a spreadsheet writable
 
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).
--
Scott B


"Scott B" wrote:

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);



--
Scott B



All times are GMT +1. The time now is 11:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com