How can I get cell values ?

12 posts, 1 answers
  1. aykut
    aykut avatar
    64 posts
    Member since:
    Oct 2007

    Posted 15 Dec 2015 Link to this post

    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 ?
  2. Bozhidar
    Admin
    Bozhidar avatar
    1102 posts

    Posted 15 Dec 2015 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. aykut
    aykut avatar
    64 posts
    Member since:
    Oct 2007

    Posted 15 Dec 2015 in reply to Bozhidar Link to this post

    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.

  5. Bozhidar
    Admin
    Bozhidar avatar
    1102 posts

    Posted 17 Dec 2015 Link to this post

    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
  6. aykut
    aykut avatar
    64 posts
    Member since:
    Oct 2007

    Posted 17 Dec 2015 in reply to Bozhidar Link to this post

    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

  7. aykut
    aykut avatar
    64 posts
    Member since:
    Oct 2007

    Posted 17 Dec 2015 in reply to aykut Link to this post

    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.

  8. Answer
    Bozhidar
    Admin
    Bozhidar avatar
    1102 posts

    Posted 18 Dec 2015 Link to this post

    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
  9. aykut
    aykut avatar
    64 posts
    Member since:
    Oct 2007

    Posted 18 Dec 2015 in reply to Bozhidar Link to this post

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

     you are the best.

  10. Prashanti
    Prashanti avatar
    1 posts
    Member since:
    Nov 2013

    Posted 29 Dec 2015 in reply to Bozhidar Link to this post

    Hi,

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

     

    thanks,

  11. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1800 posts

    Posted 01 Jan Link to this post

    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
  12. Kalyanakumar
    Kalyanakumar avatar
    1 posts
    Member since:
    May 2012

    Posted 11 Nov Link to this post

    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.

  13. Bozhidar
    Admin
    Bozhidar avatar
    1102 posts

    Posted 11 Nov Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017