|
Where did you get stuck? Seems pretty straight forward...
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using Excel = Microsoft.Office.Interop.Excel;
I am learning to use c# at the moment .. i have this code to read an excel file ... its incomplete now asi am yet to define the other varibles but as of now i want to have a user input in textbox1 and then that is to be the file name of the excel file to open ... can ne one help me
namespace WindowsFormsApplication7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
try
{
// open the users excel workbook.
Excel.Application ExcelApp = new Excel.ApplicationClass();
ExcelApp.Visible = true;
String WorkbookPath = "c:/Users/Guchu/Desktop/a.xls";
Excel.Workbook ExcelWorkbook = ExcelApp.Workbooks.Open(WorkbookPath, 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true,false,0,true,false,false);
Excel.Sheets excelSheets = ExcelWorkbook.Worksheets;
string CurrentSheet = "CurrentSheet";
excelSheets = (Excel.Sheets) excelSheets.get_Item(CurrentSheet);
}
catch (Exception theException)
{
String errorMessage;
errorMessage = "Error: ";
errorMessage = String.Concat(errorMessage, theException.Message);
errorMessage = String.Concat(errorMessage, " Line: ");
errorMessage = String.Concat(errorMessage, theException.Source);
MessageBox.Show(errorMessage, "Error");
}
}
private void button2_Click(object sender, EventArgs e)
{
}
}
}
|
|
|
|
|
Why not just use the process class with the start method to instantiate excel.exe to open with your workbook in question?
|
|
|
|
|
as i have told u that i am new to c# hence i might have done it the harder way ... but it will be easy for me to understand if u can give me the code ...
what i did was ...
for the text box i wrote...
this.textbox1 = new system.windows.forms.textbox();
string a = textbox1.text,
then in the button 1 part for opening the code i want to insert this string a as the file name in the file path
string workbookpath = @ "c:\.....\" + a ;
but this doesnt works ... can u tell me the correct way
|
|
|
|
|
guchu wrote: this.textbox1 = new system.windows.forms.textbox();
string a = textbox1.text,
A new textbox would be blank, so string a would be "", debug through your code.
I will not give you the code but go to the documentation[^] and check out the process class, specifically the start method, and search the forums a bit, you'll find your answer. You just have to research for it.
Also, I would look into the OpenFileDialog to pick your file, that way you have no restriction on the residual location of your excel files.
|
|
|
|
|
i understand that u want me to learn the easier method but even using this one i am able to open the file if i specify the file name as "C:\....\a.xls" ... all i want to know is if i want to take this last part(a.xls) from the user since the file neways has to be on the desktop then how do i accomodate it in the code ... i have tried doing it using the + operator but it is not done this way as it seems as the compiler doesnt reads the remaining thing written outside "" ... i would be obliged if u can help ... i need it desperately
|
|
|
|
|
You reset your textbox by doing Textbox1 = new System.Windows.Forms.Textbox();
if you take that out, you should be fine provided the file exists but your design is horrible, inefficient and there is a faster, prettier way of doing it.
|
|
|
|
|
I will go through the documentation and redesign the program .... i will get back to u if i have any quaries regarding this ... as of now thank you very much for helping me out ....
|
|
|
|
|
Hi,
I'm trying to download a MP3 off the internet programatically. Using the method below, my MP3 player recognizes the ID3 tag, however it won't play. Anyone know how to properly download a MP3 file that will play?
StreamReader sr = new StreamReader(WebRequest.Create(strURL).GetResponse().GetResponseStream());
FileInfo fi = new FileInfo(@"c:\news.mp3");
BinaryWriter bw = new BinaryWriter(fi.OpenWrite());
while (sr.Peek() != -1)
{
btMP3 = (byte) sr.Read( );
bw.Write(btMP3);
}
bw.Close();
Thank you,
Glenn
|
|
|
|
|
Hi,
there is a WebClient.DownloadFile() method that downloads a file much easier and more efficient than your code would.
BTW: what would happen when for some reason the data isn't arriving in time so sr.Peek() can't see the next byte?
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
i made a chat program in c# and connect it to a local access database,
can i put this database on a server on the internet so can people connect to it by the program , if i can what is the connection string?
i used this connection string to connect to access database:
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=FileName"
|
|
|
|
|
|
You will find all the possible connection stringd herehere
You will find in visual studio in the server explorer panel a property wich define your connection string...
regards
|
|
|
|
|
|
And what everybody isn't telling you is that Access is a FILE BASED, desktop database. The only way to get at that database, directly, is to expose your server's file share directly to the Internet. This is about the dumbest thing you can do. Your server will be a smoldering pile of scrap in less than 24 hours.
To insultate the server as much as possible so the idiot on the web won't destroy your server, you need to expose the methods that your chat app needs in a web service and have it do all the database work needed.
|
|
|
|
|
Hi all,
I am making use of Data block of the Enterprise Library 4.1, the problem is that each time I rebuild my application, Visual Studio overwrites the config file.
The application cannot function without these settings. How can I avoid this annoying issue?
The configuration line in question:
configSections
section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data....
configSections
dataConfiguration defaultDatabase="OraConnectionStr"
Thanks in advance.
Kind regards,
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
I create a windows service where I implement the onStart() method, there i create i thread that opens a ServiceHost communication and write onto the base registery but it doesn't take effect, Idon't know how to give the thread the permission to write into it !
|
|
|
|
|
Open your "Control Panel", and look for the "Administrative Tools". This has an applet called "Services". Find your service in the list (should be there if it's properly installed) and double-click on it. Go to the tabpage called "Log On".
Here you can specify the account that the service should run under, and whether or not it's allowed to interact with the desktop (for, say, displaying a notification icon)
Hope this helps
I are troll
|
|
|
|
|
What account is the service running under??
|
|
|
|
|
My service runs under the "LocalSystem" accont, and I follow the quoted instructions (check the flag to give the permission to interact with the desktop ), but Regrettably the service could not write into the registery.
|
|
|
|
|
I found it !
Simply I wanted to wrote into "H_Key_Current_user" at it was impossible because the service was running under the "LocalSystem" account (not a "user" account) therefore I changed the location into "H_Key_Local_Machine" and it works very well
Thank you to all who wanted to help me
|
|
|
|
|
Dear friend
I want to make a website related to tree structure means if I generate a mail id example like rahul and ssponsored to other it means create other shyam the second id will come under my id . I want to see all it under a tree structure please advice to me how it possible.
Thanks ®ards
Akhilesh kumar
lucknow
|
|
|
|
|
www.rentacoder.com
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
The OP downvoted you and me for not doing his work. What BS that is.
|
|
|
|
|
They dont consider it as a help until you provide them with complete code which can be copy pasted
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|