Search code examples
c#farpoint-spreadfarpoint

Adding some text in FarPoint while Export To Excel


I am having FarPoint Web Spread and a Panel with a text box [T1] in my webpage. I am using SaveExcel method of FpSpread to write the contents into Excel.

Is there any way by which i can write the contents of text box [T1] into the excel.

Below is the code I am using for export to excel -

        Response.Clear();
        Response.ContentType = "application/vnd.ms-excel";
        Response.AppendHeader("Content-Disposition", "Attachment; filename=Export.xls;");
        Response.Charset = "";
        using (MemoryStream ms = new MemoryStream())
        {
          FpSpread1.ActiveSheetView.Protect = false;
          FpSpread1.SaveExcel(ms, FarPoint.Excel.ExcelSaveFlags.SaveCustomColumnHeaders);
          ms.WriteTo(Response.OutputStream);
        }
        Response.End();

Solution

    1. What I would suggest is to create a proxy FpSpread and copy the contents of your Orignal data into proxy object.
    2. create new column in Proxy FPSpread and then let the Farpoint.SaveExcel() take care of export.

          FpSpread fpproxy = new FpSpread();
          fpproxy = OriginalFPspread;
      
          fpproxy .ActiveSheetView.AddColumns(0, 2);// add new column
      
          fpproxy .Cells[0, 1].Column.Label = "your data";
          fpproxy .Cells[0, 1].Value = "your value";
      

    After adding this data, call your SaveExcel() on fpproxy