Free Support Forum - aspose.com

Problems in Savaing to Excel File and delecting columns

i used Grid.WebWorksheets.SaveToExcelFile to save the sheets in a Excel file, but there are not all the styles that i defined in the WebGrid, for example, the background color of cell, the border color and border width, etc,

and i want to use the function DeleteColumn, when the columns are delected, the new formulas in the columns left are still not changed, for example, before i deleted column B, the formula in cell C1 was “=C2+C3”, after i delected column B, the cell C1 became cell B1, and the formula in B1 must be change to “=B2+B3”, i think ? like in Excel ?

what’s your idea ?

Hi,

1. Please post your code files and the saved excel files here to help us locate the problem.

2. This control is using an intepreted formula engine. It has some difference from the Excel. It doesn't support update the cells' formula automatically after inserting/deleting rows/columns by far. We are still working to improve this engine.

this is the code to save the excel file from the WebGrid :
// Generates a temporary file name.
string filename = System.IO.Path.GetTempPath() + Session.SessionID + “.xls”;

// Saves to the file.
this.Grid.WebWorksheets.SaveToExcelFile(filename);

// Sents the file to browser.
Response.ContentType = “application/vnd.ms-excel”;

//Adds header.
Response.AddHeader(“content-disposition”, “attachment; filename=book1.xls”);

// Writes file content to the response stream.
Response.WriteFile(filename);

// OK.
Response.Flush();

and in the WebGrid, there is a vertical line in Brown color (in the attachment).

and after saving to Excel file, there is not the border line in Brown any more.

Hi,

How did you set this brown border line by coding? Would you please post your code here?

Aspose.Grid.Web.WebBorderStyle borderStyle = new Aspose.Grid.Web.WebBorderStyle();
borderStyle.BorderStyle = BorderStyle.Solid;
borderStyle.BorderWidth = new Unit(3, UnitType.Pixel);
borderStyle.BorderColor = Color.Brown;
sheet.Cells.SetBorders(0, 12, 3, 1, Aspose.Grid.Web.SetBorderPosition.Left, borderStyle);

Hi,

First, please be sure that you are using the latest version 1.7.

Next, the displaying in web grid has some difference with in excel. If you define the borders of the cells right beside the thick brown border, the web grid will show the thick brown border, but the excel will show the right cells' borders. The below code shows this problem:

Aspose.Grid.Web.Data.WebWorksheet sheet = GridWeb1.WebWorksheets[0];
Aspose.Grid.Web.WebBorderStyle borderStyle = new Aspose.Grid.Web.WebBorderStyle();
borderStyle.BorderStyle = BorderStyle.Solid;
borderStyle.BorderWidth = new Unit(3, UnitType.Pixel);
borderStyle.BorderColor = Color.Brown;
sheet.Cells.SetBorders(0, 12, 3, 1, Aspose.Grid.Web.SetBorderPosition.Left, borderStyle);
sheet.Cells["m1"].Style.BorderStyle = BorderStyle.Solid;
sheet.Cells["m1"].Style.BorderColor = Color.Black;
sheet.Cells["m1"].Style.BorderWidth = 1;

You may fix this problem by setting the right cells' top, bottom and right borders respectively:

Aspose.Grid.Web.Data.WebWorksheet sheet = GridWeb1.WebWorksheets[0];
Aspose.Grid.Web.WebBorderStyle borderStyle = new Aspose.Grid.Web.WebBorderStyle();
borderStyle.BorderStyle = BorderStyle.Solid;
borderStyle.BorderWidth = new Unit(3, UnitType.Pixel);
borderStyle.BorderColor = Color.Brown;
sheet.Cells.SetBorders(0, 12, 3, 1, Aspose.Grid.Web.SetBorderPosition.Left, borderStyle);

sheet.Cells["m1"].Style.TopBorderStyle.BorderColor = Color.Black;
sheet.Cells["m1"].Style.TopBorderStyle.BorderStyle = BorderStyle.Solid;
sheet.Cells["m1"].Style.TopBorderStyle.BorderWidth = 1;

sheet.Cells["m1"].Style.RightBorderStyle.BorderColor = Color.Black;
sheet.Cells["m1"].Style.RightBorderStyle.BorderStyle = BorderStyle.Solid;
sheet.Cells["m1"].Style.RightBorderStyle.BorderWidth = 1;

sheet.Cells["m1"].Style.BottomBorderStyle.BorderColor = Color.Black;
sheet.Cells["m1"].Style.BottomBorderStyle.BorderStyle = BorderStyle.Solid;
sheet.Cells["m1"].Style.BottomBorderStyle.BorderWidth = 1;