Load Spread for Web with existing Excel saved file

Posted by: pgollnic on 6 May 2018, 6:24 am EST

    • Post Options:
    • Link

    Posted 6 May 2018, 6:24 am EST

    How to I select an existing Excel (xlsx) file and have it load and bind in this control.

    I tried FpSpread.DataSource = “c:\playarea\parenting.xlsx”

    Fpspread.DataBind()

    but had no resulting data on form.

    Help?? Or a working example/sample/demo for this?

    gollnick

  • Posted 6 May 2018, 10:53 pm EST

    You need to use the SheetView’s OpenExcel method to load it in Spread - http://help.grapecity.com/spread/SpreadNet11/ASP2/webframe.html#spweb-fileopenexcel.html

    I have attached a small example of this. Please take a look.

    Spread_Web_LoadExcel.zip

  • Posted 7 May 2018, 1:30 am EST

    Hey … thanks for the quick response. I have been so used to doing a datasource and databind using a dataset I never thought of the openexcel.

    One more quick question. Is there a sample of reading the rows and processing the cell data? Is it the same as with regular microsoft excel handling?

    thanks

    gollnick

  • Posted 7 May 2018, 6:52 am EST

    I have been looking at this code

    Dim ss as FarPoint.Web.Spread.SheetView

    Fpspread1.OpenExcel(“c:\playarea\parenting_Short.xlsx”)

    ss=FpSpread1.Sheets(0).GetChildView(n,m) 'n is the parent row, and m is the relation index you are querying

    For i as Integer = 0 to ss.RowCount - 1

    msgbox(ss.GetValue(i,0))

    Next

    But I can’t get it past invalid index. Attached is the file sample I’m trying to work with. I need all the rows and all of their column data to build a dataset.

    Help please… Sample ??

    Thank you very much

    gollnick

  • Posted 7 May 2018, 6:54 am EST

  • Posted 7 May 2018, 7:09 am EST

    And while I’m asking this … is there a way to save this set as a DATASET or a DATATABLE ??

    gollnick

  • Posted 7 May 2018, 9:04 pm EST

    Is there a specific reason for using the GetChildView() method, since the excel file you’ve attached doesn’t have any hierarchical rows. You should instead just get the sheet and loop through it to get the values:

    FpSpread1.OpenExcel(Server.MapPath("~/parenting_Short.xlsx"));
    
    FarPoint.Web.Spread.SheetView sv;
    sv = FpSpread1.Sheets[0];          
    
    for (int i = 1; i < sv.RowCount; i++)
    {
        Debug.WriteLine(sv.GetValue(i, 0));
    }
    

    To build a DataSet from this, you’ll need to manually add columns and rows to the DataTable by looping through the rows of the Sheet.

    Alternatively, you could even directly create a DataSet from the Excel file. Here’s a link that may be of help - https://stackoverflow.com/questions/18006318/how-to-import-all-the-excel-sheets-to-dataset-in-c-sharp

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels