We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Pivot on WebGRid asp page issue

hi,

I want to show following excel file with 2 tab using aspose.WebGrid on asp.net page .i have attached excel and C3 Code. but i do not want to Save excel anywhere once excel workbook is created in memory i want to pass it to webGrid. is it possible ? somwthing like this

GridWeb1.WebWorksheets.ImportExcelFile(wb.SaveToStream());
form1.Controls.Add(GridWeb1);

I have attched excel and c# code for reference.

Hi,


I have tested your scenario/ case using the following sample code (please refer to the project in the reply of your other thread on how to dynamically add GridWeb to the web form: https://forum.aspose.com/t/80534 ), it works fine.

I will paste the complete updated code segment pasted in the Web form. I simply create pivot table using Aspose.Cells APIs and then save workbook to streams and import the workbook to GridWeb matrix from streams:
e.g
Sample code:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Aspose.Cells;
using Aspose.Cells.Pivot;


public partial class DynamicGridWeb : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Aspose.Cells.GridWeb.GridWeb GridWeb1 = new Aspose.Cells.GridWeb.GridWeb();

GridWeb1.EditMode = true;
//Setting the height of GridWeb control
GridWeb1.Height = new Unit(500, UnitType.Point);

//Setting the width of GridWeb control
GridWeb1.Width = new Unit(750, UnitType.Point);


////Setting the height of header bar
GridWeb1.HeaderBarHeight = new Unit(110, UnitType.Point);

////Setting the width of header bar
GridWeb1.HeaderBarWidth = new Unit(550, UnitType.Point);


var wb = new Workbook();
var ws = wb.Worksheets[wb.Worksheets.Add()];
ws.Name = “Sheet”;

ws.Cells[0, 0].PutValue(“X”);
ws.Cells[0, 1].PutValue(“Y”);
ws.Cells[0, 2].PutValue(“Data”);

ws.Cells[1, 0].PutValue(“A”);
ws.Cells[1, 1].PutValue(“C”);
ws.Cells[1, 2].PutValue(10);

ws.Cells[2, 0].PutValue(“A”);
ws.Cells[2, 1].PutValue(“D”);
ws.Cells[2, 2].PutValue(25);

ws.Cells[3, 0].PutValue(“B”);
ws.Cells[3, 1].PutValue(“C”);
ws.Cells[3, 2].PutValue(30);

ws.Cells[4, 0].PutValue(“B”);
ws.Cells[4, 1].PutValue(“D”);
ws.Cells[4, 2].PutValue(45);

PivotTableCollection ptc = ws.PivotTables;
int index = ptc.Add("=Sheet!A1:C5", “A7”, “PivotTable1”);
PivotTable pt = ptc[index];

int fp; PivotField pf;

fp = pt.AddFieldToArea(PivotFieldType.Row, “X”);
pf = pt.Fields(PivotFieldType.Row)[fp];

fp = pt.AddFieldToArea(PivotFieldType.Column, “Y”);
pf = pt.Fields(PivotFieldType.Column)[fp];

fp = pt.AddFieldToArea(PivotFieldType.Data, “Data”);
pf = pt.Fields(PivotFieldType.Data)[fp];

fp = pt.AddFieldToArea(PivotFieldType.Data, “Data”);
pf = pt.Fields(PivotFieldType.Data)[fp];
pf.DataDisplayFormat = PivotFieldDataDisplayFormat.PercentageOfColumn;

pt.AddFieldToArea(PivotFieldType.Column, pt.DataField);
pt.RefreshData();
pt.CalculateData();

// GridWeb1.WebWorksheets.ImportDataView(dv, null, null);

GridWeb1.WebWorksheets.ImportExcelFile(wb.SaveToStream());
form1.Controls.Add(GridWeb1);



}
}


Hope, this helps a bit.

Thank you.