Error when import file excel .xlsx to spread

Posted by: duchoapnpd on 17 December 2020, 12:34 am EST

    • Post Options:
    • Link

    Posted 17 December 2020, 12:34 am EST

    Hi,

    I have a issue when I import file excel .xlsx to spread. The problem at function sheet.OpenExcel(ms, 0) it can’t Open MemoryStream, also the MemoryStream have data. Please help me. My code like.

    void Import_Click(object sender, EventArgs e){

    byte data = Convert.FromBase64String(fileData.Value);

    MemoryStream ms = new MemoryStream(data);

                FarPoint.Web.Spread.SheetView sheet = new FarPoint.Web.Spread.SheetView();
                sheet.SheetName = "sheet1";
                sheet.OpenExcel(ms, 0);
    



    var a = sheet.Cells[0, 0].Value.ToString(), 0;

    // Error in this because sheet not have a value.

    }

    this is my function download excel using flag like

    void btnExcel_Click(object sender, EventArgs e){

    FarPoint.Web.Spread.FpSpread temp = new FarPoint.Web.Spread.FpSpread();

    FarPoint.Web.Spread.SheetView sht = new FarPoint.Web.Spread.SheetView();

    CopySheet(FpSpread1.ActiveSheetView, sht);



    var flags = FarPoint.Excel.ExcelSaveFlags.UseOOXMLFormat | FarPoint.Excel.ExcelSaveFlags.SaveCustomColumnHeaders;

    var data = ExportExcelData(temp, flags);



    }

  • Posted 17 December 2020, 2:24 am EST

    The function OpenExcel can read file Excel 2007 XML format (xlsx)?

  • Posted 18 December 2020, 7:08 am EST

    Hi,

    The Excel file can be loaded into FarPoint Spread using the following code snippet:

     using (MemoryStream ms = new MemoryStream())
                using (FileStream file = new FileStream(Server.MapPath("~/Files/Reports.xlsx"), FileMode.Open, FileAccess.Read))
                {
                    byte[] bytes = new byte[file.Length];
                    file.Read(bytes, 0, (int)file.Length);
                    ms.Write(bytes, 0, (int)file.Length);
                    ms.Position = 0;
                    FpSpread1.OpenExcel(ms);
                }
    

    Regards,

    Manish Gupta

Need extra support?

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

Learn More

Forum Channels