|
Hi,All
I want to access Microsoft Excel Sheet in Visual C#.In one button click i am writting following code:
Excel.Application ExcelApp = new Excel.ApplicationClass ();
Excel.Worksheet sheet ;
sheet = (Excel.Worksheet) ExcelApp.Workbooks.Open("D:\\AccessExcelInVB\\Data.xls",1,1,1,1,1,1,1,1,1,1,1,1).Sheets.get_Item("Data");
MessageBox.Show( sheet.Cells.get_Item(12,12));
I want to access the data in (12,12)'th cell and show it in MessageBox,i need to compare it with string in further code.
But it gives error that object can not be converted to string.
Can anybody tell me how should i convert object to string?
Thanx and Regards
Tushar
|
|
|
|
|
Tushar mahajan wrote:
MessageBox.Show( sheet.Cells.get_Item(12,12));
You need to manually call ToString() on it, but there is probably some Excel method you need to call to get the string out of it.
James
Simplicity Rules!
|
|
|
|
|
Hi,
When i use :
MessageBox.Show(sheet.Cells.get_Item(12,12).ToString);
it gives me string System.__ComObject
But i want value of that cell.
Also it does'nt have Value property to give me value of that cell.
Tushar
|
|
|
|
|
According to a quick look at MSDN there should be a Value property on the Range object that refers to that cell.
ie, Range("L12").Value , I think you create the range object from the worksheet.
James
Simplicity Rules!
|
|
|
|
|
Hi,
Sorry to trouble you again but i am confused.
Excel.Application ExcelApp = new Excel.ApplicationClass ();
Excel.Worksheet sheet ;
sheet = (Excel.Worksheet) ExcelApp.Workbooks.Open("D:\\AccessExcelInVB\\EquipmentData.xls",0,1,1,1,0,0,1,0,0,0,0,0).Sheets.get_Item("Data");
now when i use sheet.Cells(12,12) and gives the Dot it does'nt show me anything,and it gives me error("Excel._Worksheet.Cells denotes a property where a method was expected").(DotNet does'nt support Default).
so i should use sheet.Cells.get_Item(12,12),but it does'nt show me Value property.
I am using Office2000 is it due to that?.
Thanx
Tushar
|
|
|
|
|
This code works for me with OfficeXP
Excel.Application app = new Excel.ApplicationClass();
Excel.Workbook wb = app.Workbooks.Open(@"C:\test.xls", 0,0,1,1,0,0,1,0,0,0,0,0, 0, 0);
Excel.Worksheet ws = (Excel.Worksheet) wb.Worksheets[1];
Excel.Range range = (Excel.Range) ws.Cells[12, 12];
textBox1.Text = (string) range.Text;
wb.Close(false, Type.Missing, Type.Missing);
app.Quit(); HTH,
James
Simplicity Rules!
|
|
|
|
|
Hi,
Thank you very much,now it works here too.
Actually i am new to C#.
Thanx again
Tushar
|
|
|
|
|
I think you might want to try sheet.Cells(12,12).Value (and then maybe .ToString() )
--
David Wengier
Sonork ID: 100.14177 - Ch00k
|
|
|
|
|
Hello Everybody,
I am developing a windows application using c#. I want access some .DBF
file without ODBC.
Can anybody help me out.
Thanks in advance.
|
|
|
|
|
cn0574 wrote:
I want access some .DBF
file without ODBC.
Without ODBC? I think, even ADO internally makes ODBC calls.
Do you mean to say you want to directly open the dbf file and parse it on your own? It might not be an elementary process at all. I suggest that you use OLE DB .NET [underlying technology used by ADO .NET]
Regards
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
I hope that a control can direct access .dbf file.
|
|
|
|
|
Does anyone know if it's possible to use assembly blocks in C#? Or any ideas on how to go about this?
andypat
|
|
|
|
|
Andy Patterson wrote:
Does anyone know if it's possible to use assembly blocks in C#? Or any ideas on how to go about this?
I don't think C# allows you asm blocks, but you can have asm blocks in your MC++ program and then access those classes from C#
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
Yeah, thats what I thought. Thanks for your input.
andypat
|
|
|
|
|
I try to accomplish the simple task of writing an ASCII text file in C#/.NET
string str = "This\nIs\nA\nTest";
byte[] b = new byte[str.Length];
System.Text.Encoding.ASCII.GetBytes(str.ToCharArray(),
0, str.Length, b, 0);
FileStream TextFileStream = File.OpenWrite(FileName);
TextFileStream.Write(b, 0, str.Length);
I tried all kind of things like this.
or like that
FileStream TextFileStream = File.OpenWrite(FileName);
BinaryWriter BinaryASCII = new BinaryWriter(TextFileStream, System.Text.Encoding.ASCII);
BinaryASCII.Write(strText);
TextFileStream.Close();
But the newlines in my string never show up correctly in notepad.
What do I need to do do just simply write ASCII to a text file in C#/.NET ?
Tim
|
|
|
|
|
A newline is \n\r, or \r\n, I always forget which.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
if you just want to write text use the StremReader class it is meant for that
|
|
|
|
|
sorry for writing tex you need StreamWriter
|
|
|
|
|
or even TextWriter
James
Simplicity Rules!
|
|
|
|
|
See :-
http://www.codeproject.com/useritems/csfilestuff01.asp
[Shows how to read/write files using the reader/writer classes and also shows how to use the File class to get info regarding a file]
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
ok, thanks !
I'm a bit confused. Why do I need to write \r\n in C# but \n does fine it C++ ? Does fprintf etc automatically do this conversion since it knows that I'm writing ASCII ?
greetings,
Tim
|
|
|
|
|
Hi!
Has anyone an idea how i can get the cpu temperature with c#? I am going to develop a kind of hardware monitor.
Thx.
--== BINARY VICTORY ==--
|
|
|
|
|
There is a Win32_TemperatureProbe class in the WMI hierarchy that looks interesting, you can get to it via the System.Management namespace. I have never played with tracking down the CPU temp, so I could be off the mark here.
Regards
|
|
|
|
|
Scenario:
I have an object that has 2 overloads of a constructor. For some reason, overload1 in turn calls overload2.
i.e. I want to defer object creation until overload2 is eventually called.
I'm not sure of the syntax, as constructors don't seem to be treated as normal functions.
Can someone provide me with code for this?
Cheers,
Simon
"Every good work of software starts by scratching a developer's personal itch.", Eric S. Raymond
|
|
|
|
|
class Foo
{
int value;
public Foo()
: this(0)
{
}
public Foo(int i)
{
value = i;
}
}
|
|
|
|
|