PC Review


Reply
Thread Tools Rate Thread

How to assign value to Excel 2000 worksheet cell

 
 
=?Utf-8?B?RHVkaSBOaXNzYW4=?=
Guest
Posts: n/a
 
      15th Feb 2005
Hello,
I am writing c# web application with Excel 2000.
My code is:

Excel.Application EXL;
EXL = new Excel.Application();
Excel.Worksheet WSheet = new Excel.WorksheetClass();
string FileName = MapPath(".") + "\\..xls";
WSheet = (Excel.Worksheet)EXL.Workbooks.Open(FileName, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing).Worksheets.get_Item(1);
Excel.Range rng = WSheet.get_Range("H12", Type.Missing);
string H12 = "H12: " + rng.Value2.ToString(); // Works fine

How can I assign value to cell?
rng.Cells[6, 3] = "a"; --> return the following error:
error: cannot assign '"a"' into 'rng.Cells[6,3]'

Thank you.

 
Reply With Quote
 
 
 
 
Paul Clement
Guest
Posts: n/a
 
      15th Feb 2005
On Tue, 15 Feb 2005 04:27:07 -0800, "Dudi Nissan" <(E-Mail Removed)> wrote:

¤ Hello,
¤ I am writing c# web application with Excel 2000.
¤ My code is:
¤
¤ Excel.Application EXL;
¤ EXL = new Excel.Application();
¤ Excel.Worksheet WSheet = new Excel.WorksheetClass();
¤ string FileName = MapPath(".") + "\\..xls";
¤ WSheet = (Excel.Worksheet)EXL.Workbooks.Open(FileName, Type.Missing,
¤ Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
¤ Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
¤ Type.Missing).Worksheets.get_Item(1);
¤ Excel.Range rng = WSheet.get_Range("H12", Type.Missing);
¤ string H12 = "H12: " + rng.Value2.ToString(); // Works fine
¤
¤ How can I assign value to cell?
¤ rng.Cells[6, 3] = "a"; --> return the following error:
¤ error: cannot assign '"a"' into 'rng.Cells[6,3]'

See if the following helps:

http://support.microsoft.com/default...b;en-us;302084


Paul ~~~ (E-Mail Removed)
Microsoft MVP (Visual Basic)
 
Reply With Quote
 
=?Utf-8?B?RHVkaSBOaXNzYW4=?=
Guest
Posts: n/a
 
      15th Feb 2005
Hi Paul,
I read the article.
Still I get an error message.
According to my code, how can I assign value to the cell?
Thank you.

"Paul Clement" wrote:

> On Tue, 15 Feb 2005 04:27:07 -0800, "Dudi Nissan" <(E-Mail Removed)> wrote:
>
> ¤ Hello,
> ¤ I am writing c# web application with Excel 2000.
> ¤ My code is:
> ¤
> ¤ Excel.Application EXL;
> ¤ EXL = new Excel.Application();
> ¤ Excel.Worksheet WSheet = new Excel.WorksheetClass();
> ¤ string FileName = MapPath(".") + "\\..xls";
> ¤ WSheet = (Excel.Worksheet)EXL.Workbooks.Open(FileName, Type.Missing,
> ¤ Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
> ¤ Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
> ¤ Type.Missing).Worksheets.get_Item(1);
> ¤ Excel.Range rng = WSheet.get_Range("H12", Type.Missing);
> ¤ string H12 = "H12: " + rng.Value2.ToString(); // Works fine
> ¤
> ¤ How can I assign value to cell?
> ¤ rng.Cells[6, 3] = "a"; --> return the following error:
> ¤ error: cannot assign '"a"' into 'rng.Cells[6,3]'
>
> See if the following helps:
>
> http://support.microsoft.com/default...b;en-us;302084
>
>
> Paul ~~~ (E-Mail Removed)
> Microsoft MVP (Visual Basic)
>

 
Reply With Quote
 
Paul Clement
Guest
Posts: n/a
 
      15th Feb 2005
On Tue, 15 Feb 2005 06:51:04 -0800, "Dudi Nissan" <(E-Mail Removed)> wrote:

¤ Hi Paul,
¤ I read the article.
¤ Still I get an error message.
¤ According to my code, how can I assign value to the cell?
¤ Thank you.
¤

The example I've seen implements the value2 property in C#. Perhaps that is what is missing from
your assignment statement.


Paul ~~~ (E-Mail Removed)
Microsoft MVP (Visual Basic)
 
Reply With Quote
 
=?Utf-8?B?RHVkaSBOaXNzYW4=?=
Guest
Posts: n/a
 
      16th Feb 2005
Hello Paul,
As described in the example, I change the code and still get the following
error:
error: cannot assign 'saNames' into 'WSheet.get_Range("F4","F5".Value2'

Excel.Application EXL;
EXL = new Excel.Application();
Excel.Worksheet WSheet = new Excel.WorksheetClass();
string FileName = MapPath(".") + "\\..xls";
WSheet = (Excel.Worksheet)EXL.Workbooks.Open(FileName, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing).Worksheets.get_Item(1);
Excel.Range rng = WSheet.get_Range("H12", Type.Missing);
string H12 = "H12: " + rng.Value2.ToString();

string[,] saNames = new string[1,2];
saNames[0, 0] = "John";
saNames[0, 1] = "Smith";

WSheet.get_Range("F4", "F5").Value2 = saNames;

Thank you.


"Paul Clement" wrote:

> On Tue, 15 Feb 2005 06:51:04 -0800, "Dudi Nissan" <(E-Mail Removed)> wrote:
>
> ¤ Hi Paul,
> ¤ I read the article.
> ¤ Still I get an error message.
> ¤ According to my code, how can I assign value to the cell?
> ¤ Thank you.
> ¤
>
> The example I've seen implements the value2 property in C#. Perhaps that is what is missing from
> your assignment statement.
>
>
> Paul ~~~ (E-Mail Removed)
> Microsoft MVP (Visual Basic)
>

 
Reply With Quote
 
=?Utf-8?B?RHVkaSBOaXNzYW4=?=
Guest
Posts: n/a
 
      16th Feb 2005
Hello Paul,
I found what was the problem.
When I run this code at windows form application and assign value to
worksheet cell, I get "Do you want to save changes..." dialog box.
At my web application this dialog box doesn’t appear!
I should run my application at web!
So, my new question is how can I prevent from Excel to ask me to "... save
changes..." after assign value to worksheet cell?
Thank you.


"Dudi Nissan" wrote:

> Hello Paul,
> As described in the example, I change the code and still get the following
> error:
> error: cannot assign 'saNames' into 'WSheet.get_Range("F4","F5".Value2'
>
> Excel.Application EXL;
> EXL = new Excel.Application();
> Excel.Worksheet WSheet = new Excel.WorksheetClass();
> string FileName = MapPath(".") + "\\..xls";
> WSheet = (Excel.Worksheet)EXL.Workbooks.Open(FileName, Type.Missing,
> Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
> Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
> Type.Missing).Worksheets.get_Item(1);
> Excel.Range rng = WSheet.get_Range("H12", Type.Missing);
> string H12 = "H12: " + rng.Value2.ToString();
>
> string[,] saNames = new string[1,2];
> saNames[0, 0] = "John";
> saNames[0, 1] = "Smith";
>
> WSheet.get_Range("F4", "F5").Value2 = saNames;
>
> Thank you.
>
>
> "Paul Clement" wrote:
>
> > On Tue, 15 Feb 2005 06:51:04 -0800, "Dudi Nissan" <(E-Mail Removed)> wrote:
> >
> > ¤ Hi Paul,
> > ¤ I read the article.
> > ¤ Still I get an error message.
> > ¤ According to my code, how can I assign value to the cell?
> > ¤ Thank you.
> > ¤
> >
> > The example I've seen implements the value2 property in C#. Perhaps that is what is missing from
> > your assignment statement.
> >
> >
> > Paul ~~~ (E-Mail Removed)
> > Microsoft MVP (Visual Basic)
> >

 
Reply With Quote
 
Alvin Bruney [MVP]
Guest
Posts: n/a
 
      16th Feb 2005
Dudi:
For web applications you should not automate excel. Instead, you should use
the Office Web Components for that kind of functionality. Microsoft
specifically warns about this in their docs because of performance and
scalability issues. The Office Web Components are available free on the
office download site.

--
Regards,
Alvin Bruney [Microsoft MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ http://www.lulu.com/owc
----------------------------------------------------------


"Dudi Nissan" <(E-Mail Removed)> wrote in message
news:532567BF-83E7-45F1-A123-(E-Mail Removed)...
> Hello Paul,
> I found what was the problem.
> When I run this code at windows form application and assign value to
> worksheet cell, I get "Do you want to save changes..." dialog box.
> At my web application this dialog box doesn't appear!
> I should run my application at web!
> So, my new question is how can I prevent from Excel to ask me to "... save
> changes..." after assign value to worksheet cell?
> Thank you.
>
>
> "Dudi Nissan" wrote:
>
>> Hello Paul,
>> As described in the example, I change the code and still get the
>> following
>> error:
>> error: cannot assign 'saNames' into 'WSheet.get_Range("F4","F5".Value2'
>>
>> Excel.Application EXL;
>> EXL = new Excel.Application();
>> Excel.Worksheet WSheet = new Excel.WorksheetClass();
>> string FileName = MapPath(".") + "\\..xls";
>> WSheet = (Excel.Worksheet)EXL.Workbooks.Open(FileName, Type.Missing,
>> Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
>> Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
>> Type.Missing).Worksheets.get_Item(1);
>> Excel.Range rng = WSheet.get_Range("H12", Type.Missing);
>> string H12 = "H12: " + rng.Value2.ToString();
>>
>> string[,] saNames = new string[1,2];
>> saNames[0, 0] = "John";
>> saNames[0, 1] = "Smith";
>>
>> WSheet.get_Range("F4", "F5").Value2 = saNames;
>>
>> Thank you.
>>
>>
>> "Paul Clement" wrote:
>>
>> > On Tue, 15 Feb 2005 06:51:04 -0800, "Dudi Nissan"
>> > <(E-Mail Removed)> wrote:
>> >
>> > ¤ Hi Paul,
>> > ¤ I read the article.
>> > ¤ Still I get an error message.
>> > ¤ According to my code, how can I assign value to the cell?
>> > ¤ Thank you.
>> > ¤
>> >
>> > The example I've seen implements the value2 property in C#. Perhaps
>> > that is what is missing from
>> > your assignment statement.
>> >
>> >
>> > Paul ~~~ (E-Mail Removed)
>> > Microsoft MVP (Visual Basic)
>> >



 
Reply With Quote
 
Paul Clement
Guest
Posts: n/a
 
      16th Feb 2005
On Wed, 16 Feb 2005 02:47:03 -0800, "Dudi Nissan" <(E-Mail Removed)> wrote:

¤ Hello Paul,
¤ I found what was the problem.
¤ When I run this code at windows form application and assign value to
¤ worksheet cell, I get "Do you want to save changes..." dialog box.
¤ At my web application this dialog box doesn’t appear!
¤ I should run my application at web!
¤ So, my new question is how can I prevent from Excel to ask me to "... save
¤ changes..." after assign value to worksheet cell?
¤ Thank you.
¤

If you set the DisplayAlerts property of the Application object to False this will prevent the
dialog from displaying and will simply execute the default behavior of the dialog. Just remember to
set DisplayAlerts back to True before terminating Excel.

In addition, Alvin makes a good point. Because of the limited threading model of Office applications
and their UI, Microsoft does not support automation from unattended processes such as web apps,
services and windows services.


Paul ~~~ (E-Mail Removed)
Microsoft MVP (Visual Basic)
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
i want to assign a cell to save a worksheet John Petranek Microsoft Excel Worksheet Functions 2 14th Mar 2009 05:06 AM
How do i assign cell A1 to show the current cursor cell in Excel? =?Utf-8?B?T0I=?= Microsoft Excel Misc 2 11th Oct 2006 04:02 PM
assign cell selection order in protected Excel worksheet =?Utf-8?B?dG9tOTI=?= Microsoft Excel Misc 1 4th Apr 2005 05:57 PM
assign value to cell in another worksheet tango Microsoft Excel Programming 2 15th Oct 2004 06:18 AM
assign value to cell in other worksheet =?Utf-8?B?bWFuZ28=?= Microsoft Excel Worksheet Functions 1 15th Oct 2004 06:07 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:55 PM.