Problem With OWC Spreadsheet

G

gauri

hi,
im a new member of the group...
im wrking on a project in asp.net web application. i have to populate
an owc spreadsheet from an sql database. i have installed the owc11
tool kit and hav this spreadsheet control in my tool bar... i have
dragged and dropped it into a web form. but the problem is tat, i am
not being able to populate the spreadsheet from the code behind(C#).

here is the code that i've written.... plz help me soon.......

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using System.Configuration;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
using mscomctl;
using System.Diagnostics;
using OWC10;
using System.IO;

amespace test
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>

public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;



private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here

}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion


SqlConnection oConnection;
SqlCommand oCmd;
SqlDataReader oDataR;


private void Button1_Click(object sender, System.EventArgs e)
{
try
{
oConnection = new SqlConnection("Persist Security Info=False;User
ID=sa;Pwd=sa;Initial Catalog=testdb;Data Source=172.25.26.216");
oConnection.Open();
oCmd=new SqlCommand();
oCmd.Connection=oConnection;
oCmd.CommandText="Select * from tb1";
oDataR = oCmd.ExecuteReader();


SpreadsheetClass sprSht = new SpreadsheetClass();
sprSht.GetType();
int rowCount = 0;
rowCount++;
for(int colCount = 0;colCount < oDataR.FieldCount;
colCount++)
{
sprSht.ActiveSheet.Cells[rowCount,colCount + 1]
=oDataR.GetName(colCount).ToString();

}
while (oDataR.Read())
{
string data=oDataR.GetValue(0).ToString();
rowCount++;
for(int colCount = 0;colCount < oDataR.FieldCount;colCount++)
{
sprSht.ActiveSheet.Cells[rowCount,colCount + 1] =
oDataR.GetValue(colCount).ToString();
}
}
}


catch(Exception ex)
{
string error=ex.Message;
}
finally
{
oConnection.Close();
}


}


}
}
 
A

Alvin Bruney - ASP.NET MVP

You will need a suitable resource to get you started. The Spreadsheet is an
ActiveX control which runs on the client. It is not available on the
server. There are books available to help you get started. If you are
looking for something free, you can download the OWC toolpack from the
Office web site. It doesn't contain any server code, but it gives you ideas
on how to manipulate the components from javascript.

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

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------



gauri said:
hi,
im a new member of the group...
im wrking on a project in asp.net web application. i have to populate
an owc spreadsheet from an sql database. i have installed the owc11
tool kit and hav this spreadsheet control in my tool bar... i have
dragged and dropped it into a web form. but the problem is tat, i am
not being able to populate the spreadsheet from the code behind(C#).

here is the code that i've written.... plz help me soon.......

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using System.Configuration;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
using mscomctl;
using System.Diagnostics;
using OWC10;
using System.IO;

amespace test
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>

public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;



private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here

}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion


SqlConnection oConnection;
SqlCommand oCmd;
SqlDataReader oDataR;


private void Button1_Click(object sender, System.EventArgs e)
{
try
{
oConnection = new SqlConnection("Persist Security Info=False;User
ID=sa;Pwd=sa;Initial Catalog=testdb;Data Source=172.25.26.216");
oConnection.Open();
oCmd=new SqlCommand();
oCmd.Connection=oConnection;
oCmd.CommandText="Select * from tb1";
oDataR = oCmd.ExecuteReader();


SpreadsheetClass sprSht = new SpreadsheetClass();
sprSht.GetType();
int rowCount = 0;
rowCount++;
for(int colCount = 0;colCount < oDataR.FieldCount;
colCount++)
{
sprSht.ActiveSheet.Cells[rowCount,colCount + 1]
=oDataR.GetName(colCount).ToString();

}
while (oDataR.Read())
{
string data=oDataR.GetValue(0).ToString();
rowCount++;
for(int colCount = 0;colCount < oDataR.FieldCount;colCount++)
{
sprSht.ActiveSheet.Cells[rowCount,colCount + 1] =
oDataR.GetValue(colCount).ToString();
}
}
}


catch(Exception ex)
{
string error=ex.Message;
}
finally
{
oConnection.Close();
}


}


}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top