tags:

views:

1545

answers:

6

Hi guys,
My application using excel file in order to read data from web (using excel web query and reading the data from the excel file)
The excel file I'm using called webGate.
my problem is that I don't want webGate to be presented to the user.
if the user opens excel file (any other file) while my application is reading the webGate file the webGate file is presented with the user file
(i.e. user opens excel file and two files are being presented one of them is the webGate)
Any idea about how can I use the file but it will never be presented to the user?
Thanks
Eran

+1  A: 

What do you want to achieve? Its is unclear. Any idea about how can I use the file but it will never be presented to the user?

If you want to open/modify the file in C# code: http://www.codeproject.com/KB/office/csharp_excel.aspx

PoweRoy
A: 

I don't know if this would be too much trouble or not, but it might be worth it to export the excel file as an xml (if this is possible, I don't know what your excel file looks like) and read the data in that way.

W_P
A: 

I use the Infragistics toolset for this purpose, and it works great (supports all excel versions, and is very feature rich)

It may not suit your needs because it's not free, but it's largely worth its cost if you ask me

Brann
A: 

Thank you guys for your quick answers

To make my self clear, the bottom line of my problem is that the webGate file that I'm using from my program will not be available to the user and will be in the program use only.
I need free solution since this application is for my training as student and money is not available at the moment :-)
As for exporting data to XML isn’t it require opening the file from the program and I will be in the same problem again?

Eran

A: 

If the project will take less than 30 days, you can use the free evaluation of SpreadsheetGear for .NET to embed an Excel workbook in a .NET application without it being presented to the user. Just follow these steps:

  • Create a new C# Windows Forms application and put a WorkbookView control on your form (see the SpreadsheetGear Tutorial for Windows Forms app if your not sure how to do this).
  • Right click on the WorkbookView and chose "Workbook Designer...".
  • In the Workbook Designer, close the default workbook and use File Open... to open your workbook. This will embed your workbook in the application as a resource.
  • Close the Workbook Designer.
  • You can hide the WorkbookView if you don't want the user to see it, or you can use the WorkbookView.DisplayReference property to limit what parts of the workbook they can see.

You can download the free evaluation here.

Disclaimer: I own SpreadsheetGear LLC

Joe Erickson
A: 

You can use an .xls as a OLEDB data source. You use the Microsoft.Jet.OLEDB.4.0 data provider.

This means you are reading the data out of the excel sheet, rather than opening the .xls as a document in the Excel application.

It is not automation. It does not start Excel.exe. It does not require Excel.exe. There is no third-party component required. There's no additional cost (beyond the cost of Windows). It works in server-side apps.

Full source code here.

Snippets:

void CreateExcelDocThroughAdoNet()
{
    const string Filename= "adonet-excel.xls";

    const string strConnect = 
      "Provider=Microsoft.Jet.OLEDB.4.0;" + 
      "Data Source=" + Filename + ";" + 
      "Extended Properties=\"Excel 8.0;HDR=yes;\""; 

    try
    {
      conn = new System.Data.OleDb.OleDbConnection(strConnect);
      CreateTable();
      for(int i=0; i < 4; i++) Insert(i);
    }
    catch (System.Exception ex)
    {
      System.Console.WriteLine("Exception: " + ex.Message+ "\n  " + ex.StackTrace); 
    }
}


private void CreateTable()
{

    string strSql = "CREATE TABLE SampleTable ( Ix NUMBER, CustName char(255), Stamp datetime )";

    System.Data.OleDb.OleDbCommand cmd= new System.Data.OleDb.OleDbCommand(strSql, conn);
    conn.Open();
    cmd.ExecuteNonQuery();
    conn.Close();
}

private void Insert(int ix)
{
    string strSql = "insert into [SampleTable] ([ix],[CustName],[Stamp]) value(@p1,@p2,@p3)";

    System.Data.OleDb.OleDbCommand cmd= new System.Data.OleDb.OleDbCommand(strSql, conn);

    cmd.Parameters.Add("@p1", System.Data.OleDb.OleDbType.Numeric).Value = ix;
    cmd.Parameters.Add("@p2", System.Data.OleDb.OleDbType.VarChar).Value = "Some text";
    cmd.Parameters.Add("@p3", System.Data.OleDb.OleDbType.Date).Value = System.DateTime.Now;

    conn.Open();
    cmd.ExecuteNonQuery();
    conn.Close();
  }
Cheeso