This is a migrated thread and some comments may be shown as answers.

How can I get cell values ?

12 Answers 744 Views
Spreadsheet
This is a migrated thread and some comments may be shown as answers.
aykut
Top achievements
Rank 1
aykut asked on 15 Dec 2015, 08:42 AM

Hi,

I cannot get any kind of information out of spreadsheet. sheet count is zero, I could not figured out how to access cells...

I load demo xlsx files but I cannot access any information. also there's not much in help section.

 

Does this control serves just lo load and show xls files ? what I'm missing ?

12 Answers, 1 is accepted

Sort by
0
Bozhidar
Telerik team
answered on 15 Dec 2015, 09:20 AM
Hello,

You have to call the DataBind() method in order to access the Sheets and Cells in the code behind.

Regards,
Bozhidar
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
aykut
Top achievements
Rank 1
answered on 15 Dec 2015, 07:19 PM

okay my friend but problem is I cannot even run simple commands like:

        Dim workbook As New Workbook()
        Dim worksheet As Worksheet = workbook.Worksheets.Add()
        worksheet.Name = "Expense Report 2014"

I tried page_load event, page_init event. I read blogpost "SpreadProcessing - Complete Solution.....". obviously I'm doing something wrong. can you please provide a simple sample to add a new worksheet and set a cell's value please ? so I can understand which namespaces should I use because I believe I have problem with importing correct ones. and all the demos are for winforms, I need aspnet solution. I really tried hard but I'm stuck.

best.

0
Bozhidar
Telerik team
answered on 17 Dec 2015, 08:20 AM
Hello,

The Spreadsheet Control doesn't implement the same interface as the SpreadProcessing library, so there are some differences to be expected. Here's some sample code that populates the Spreadsheet with data from the Products table of the Northwind database, which should point you in the right track:
protected void Page_Load(object sender, EventArgs e)
{
    RadSpreadSheet1.Sheets.Clear();
 
    foreach (var sheet in GetSheets())
    {
        RadSpreadSheet1.Sheets.Add(sheet);
    }
}
public List<Worksheet> GetSheets()
{
    var result = new List<Worksheet>();
 
    DataTable data = GetData();
 
    var sheet = new Worksheet();
 
    int rowIndex = 0;
    foreach (DataRow dataRow in data.Rows)
    {
        var row = new Row() { Index = rowIndex++ };
 
        int columnIndex = 0;
        foreach (DataColumn dataColumn in data.Columns)
        {
            if (dataColumn.ColumnName == "ID") continue; // Skip the ID column
 
            string cellValue = dataRow[dataColumn.ColumnName].ToString();
 
            var cell = new Cell() { Index = columnIndex++, Value = cellValue };
 
            row.AddCell(cell);
        }
 
        sheet.AddRow(row);
    }
 
    result.Add(sheet);
 
    return result;
}
 
public DataTable GetData()
{
    using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString))
    {
        conn.Open();
        string query = "SELECT * FROM [Products]";
        SqlCommand cmd = new SqlCommand(query, conn);
 
        DataTable dt = new DataTable();
        dt.Load(cmd.ExecuteReader());
        return dt;
    }
}


Regards,
Bozhidar
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
aykut
Top achievements
Rank 1
answered on 17 Dec 2015, 12:47 PM

okay, not I can add sheets, thats fine but then I cannot access them. sheetcount is zero so I cannot access its content although my sheets are visible on the page. I will try to get cell values that user will enter. that's my goal :)

 some more help please...

 

  Protected Sub Page_Init(sender As Object, e As EventArgs) Handles Me.Init
      If Not IsPostBack Then
          Dim w As New Telerik.Web.Spreadsheet.Worksheet
          w.Name = "test 1"
          RadSpreadsheet1.Sheets.Add(w)
          Dim w2 As New Telerik.Web.Spreadsheet.Worksheet
          w2.Name = "test 2"
          RadSpreadsheet1.Sheets.Add(w2)
      End If
  End Sub
 
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
 
      Dim s As Integer = RadSpreadsheet1.Sheets.Count
 
      Response.Write(s.ToString)
 
  End Sub

0
aykut
Top achievements
Rank 1
answered on 17 Dec 2015, 01:02 PM

hmmm, looks like on every postback RadSpreadsheet looses its sheets I added before. I tried Page_load or page_init events but nothing changes.

Is there a possibility that this component designed just to show data ?

Because I want to create a blank sheet on page and user will fill it in then when he clicks a button I'll read the values he entered.

I wont work database or anything.

0
Accepted
Bozhidar
Telerik team
answered on 18 Dec 2015, 07:17 AM
Hi,

The Spreadsheet control doesn't use ViewState in order to make it more lightweight, and therefore cannot automatically preserve its state across postbacks. If you want to be able to read and write to a custom datasource, you will have to implement a custom provider, which the control will be bound to. Using the provider you can use the "Save" button of the Spreadsheet toolbar to save the state at any time.

I've attached a sample page where a custom provider is implemented. It should be able to point you in the right direction while implementing your requirements.

Regards,
Bozhidar
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
aykut
Top achievements
Rank 1
answered on 18 Dec 2015, 07:24 PM

aha... that's exactly what I need. thank you. I could never think custom data provider.

 you are the best.

0
Prashanti
Top achievements
Rank 1
answered on 29 Dec 2015, 11:20 PM

Hi,

How can i bind the toolbar Save to a handler method?

 

thanks,

0
Konstantin Dikov
Telerik team
answered on 01 Jan 2016, 08:56 AM
Hello Prashanti,

The control is still in beta version and it does not provide functionality for handling such events.

Nevertheless, you could try to get reference to the "Save" button in the toolbar and attach handler for the "onmousedown" event.


Best Regards,
Konstantin Dikov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Kalyanakumar
Top achievements
Rank 1
answered on 11 Nov 2016, 06:46 AM

Hi,

I have a webpage using RadSpreadsheet control. Now i have to write the event to set the range values to validate only numbers. and i need to get the cell edit event to change the cell forecolore based on the values. like 0-3 red others green and maximum 10 else error messge.

Can anybody give the details for me.

0
Bozhidar
Telerik team
answered on 11 Nov 2016, 07:11 AM
Hello,

The issue that was the topic of this forum thread has been answered and resolved. Since your question is not related to the current topic, I would advise you to open a separate forum thread, where the specific case can be investigated.

Regards,
Bozhidar
Telerik by Progress
Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
0
Fay
Top achievements
Rank 1
answered on 16 Aug 2017, 01:20 PM

Hello Bozidar's ,

Can you please help me with sample code to save file on Shared location .Its an export functionality that I am working on.

 

 

Regards,

farheen

Tags
Spreadsheet
Asked by
aykut
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
aykut
Top achievements
Rank 1
Prashanti
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Kalyanakumar
Top achievements
Rank 1
Fay
Top achievements
Rank 1
Share this question
or