Cell Border Question

I have a template worksheet that I have defined column borders in. When I copy the worksheet into a new workbook and add data the borders are only visible for the cells that contained data pre-copy. What is the quickest way to set the borders for cells in these columns? The example in the wiki shows a seperate call for every border side at the cell level. Is there an easier method?

Hi,

Thanks for considering Aspose.

Following is a sample code which sets the inside borders to all the cells in the column "C":

Workbook workbook = new Workbook();

Column col = workbook.Worksheets[0].Cells.Columns[2];

col.Style.Borders[BorderType.TopBorder].Color = Color.Red;

col.Style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Medium;

col.Style.Borders[BorderType.BottomBorder].Color = Color.Red;

col.Style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Medium;

col.Style.Borders[BorderType.LeftBorder].Color = Color.Red;

col.Style.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Medium;

col.Style.Borders[BorderType.RightBorder].Color = Color.Red;

col.Style.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Medium;

workbook.Save(@"d:\testborders1.xls",FileFormatType.Excel2003);

You may also try to set an outline border to a range of cells with the following sample code:

Workbook workbook = new Workbook();

Cells cells = workbook.Worksheets[0].Cells;

Range range = cells.CreateRange("B2", "N30");

range.SetOutlineBorder(BorderType.TopBorder, CellBorderType.Medium, Color.FromArgb(0, 0, 128));

range.SetOutlineBorder(BorderType.BottomBorder, CellBorderType.Medium, Color.FromArgb(0, 0, 128));

range.SetOutlineBorder(BorderType.LeftBorder, CellBorderType.Medium, Color.FromArgb(0, 0, 128));

range.SetOutlineBorder(BorderType.RightBorder, CellBorderType.Medium, Color.FromArgb(0, 0, 128));

workbook.Save(@"d:\testborders.xls",FileFormatType.Excel2003);

Could you post us your template file, so that we may sort out your issue related borders of the cells when copying worksheet to other Workbook.

Thank you

Regards

Amjad Sahi

Aspose Nanjing Team