|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to assign value to Excel 2000 worksheet cellI 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. On Tue, 15 Feb 2005 04:27:07 -0800, "Dudi Nissan" <DudiNis***@discussions.microsoft.com> 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.aspx?scid=kb;en-us;302084 Paul ~~~ pclem***@ameritech.net Microsoft MVP (Visual Basic) 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. Show quoteHide quote "Paul Clement" wrote: > On Tue, 15 Feb 2005 04:27:07 -0800, "Dudi Nissan" <DudiNis***@discussions.microsoft.com> 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.aspx?scid=kb;en-us;302084 > > > Paul ~~~ pclem***@ameritech.net > Microsoft MVP (Visual Basic) > On Tue, 15 Feb 2005 06:51:04 -0800, "Dudi Nissan" <DudiNis***@discussions.microsoft.com> 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 ~~~ pclem***@ameritech.net Microsoft MVP (Visual Basic) 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. Show quoteHide quote "Paul Clement" wrote: > On Tue, 15 Feb 2005 06:51:04 -0800, "Dudi Nissan" <DudiNis***@discussions.microsoft.com> 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 ~~~ pclem***@ameritech.net > Microsoft MVP (Visual Basic) > 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. Show quoteHide quote "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" <DudiNis***@discussions.microsoft.com> 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 ~~~ pclem***@ameritech.net > > Microsoft MVP (Visual Basic) > > 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. -- Show quoteHide quoteRegards, 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" <DudiNis***@discussions.microsoft.com> wrote in message news:532567BF-83E7-45F1-A123-153ACCC429DE@microsoft.com... > 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" >> > <DudiNis***@discussions.microsoft.com> 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 ~~~ pclem***@ameritech.net >> > Microsoft MVP (Visual Basic) >> > On Wed, 16 Feb 2005 02:47:03 -0800, "Dudi Nissan" <DudiNis***@discussions.microsoft.com> 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 ~~~ pclem***@ameritech.net Microsoft MVP (Visual Basic)
Other interesting topics
Simple: Excel Jet 4.0 Link vb 2005
RE: For vs. For Each Windows service & Web service Interprocess Communication How to make an assembly search for its dependent DLLs in a specific path (other than the installed d .net and mysql join ENTER and forms Method for finding dotnet version How does IIS or Framework set the Content-Length header ? Excel process doesn't shut down Record my webcam |
|||||||||||||||||||||||