Cell borders printing (unwanted)


#1

Hi

I want the cell borders to display in default style in the worksheet, and for no borders to be displayed when I print it. When I use the following code the worksheet looks fine but when printed it prints the borders only on those cells for which I have set the style (i.e. written data to).

style.Borders.SetStyle( CellBorderType.Thin );

style.Borders.SetColor( Color.Silver );

style.Borders.DiagonalColor = style.ForegroundColor;

style.Borders.DiagonalStyle = CellBorderType.None;

What am I doing wrong?

Thanks

Alan


#2

1. Which version of Aspose.Cells are you using?

2. How do you set the default style to make it show borders?

3. What's your exact code to set borders? If you set those Style objects to cells, sure only set cells will show borders.


#3

1. Version of ASPOSE.CELLS: v1.0.3705

2. I don't set a default style. I set styles on a cell by cell basis. I don't know how to set a default style.

3. I define a number of style objects, such as this:

Style style = null;

int index = excel.Styles.Add();

Color styleColor = Color.FromArgb( 129, 65, 81 );

style = excel.Styles[index];

style.Name = "SummaryStyle";

excel.ChangePalette( styleColor, 1 );

style.ForegroundColor = styleColor;

style.Pattern = BackgroundType.Solid;

style.HorizontalAlignment = TextAlignmentType.Left;

style.VerticalAlignment = TextAlignmentType.Bottom;

style.Font.Name = "Arial";

style.Font.Size = 16;

style.Font.Color = Color.Black;

style.Font.IsBold = true;

style.Font.IsItalic = false;

style.Borders.SetStyle( CellBorderType.Thin );

style.Borders.SetColor( Color.Silver );

style.Borders.DiagonalColor = styleColor;

style.Borders.DiagonalStyle = CellBorderType.None;

and then for each cell, assign the style like this:

Range range = ws.Cells.CreateRange( i, j, 1, 1 );

range.Style = excel.Styles["SummaryStyle"];

range.RowHeight = 18;

Alan


#4

1. This is not version of Aspose.Cells. I think it's version of your program. The latest version of Aspose.Cells is v4.0.3.

2. To make all borders show with silver color, please try this piece of code:

Workbook wb = new Workbook();
Aspose.Cells.Style style = wb.DefaultStyle;
style.Borders.SetColor(Color.Silver);
style.Borders.SetStyle(CellBorderType.Thin);
style.Borders.DiagonalStyle = CellBorderType.None;

wb.DefaultStyle = style;
wb.Save("d:\\test\\abc.xls");


#5

VB sample code:

Dim wb As Workbook = New Workbook()
Dim style As Aspose.Cells.Style = wb.DefaultStyle
style.Borders.SetColor(Color.Silver)
style.Borders.SetStyle(CellBorderType.Thin)
style.Borders.DiagonalStyle = CellBorderType.None

wb.DefaultStyle = style
wb.Save("d:\test\abc.xls")


#6

Hi Laurence

In VS.NET, the ASPOSE.CELLS properties tells me that the version is 4.0.1.0 and the runtime version v1.0.3705. Using the default cell style does not solve the problem. The actual code I am trying to get to work (default gridlines in worksheet, no gridlines when printed) is as follows:

private void btnGridStyle_Click( object sender, EventArgs e )

{

Workbook wb = new Workbook();

Aspose.Cells.Style defaultStyle = wb.DefaultStyle;

Color styleColor1 = Color.FromArgb( 50, 120, 220 );

Style cellStyle = null;

int index = wb.Styles.Add();

cellStyle = wb.Styles[index];

cellStyle.Name = "Style1";

wb.ChangePalette( styleColor1, 1 );

cellStyle.ForegroundColor = styleColor1;

cellStyle.Pattern = BackgroundType.Solid;

cellStyle.HorizontalAlignment = TextAlignmentType.Left;

cellStyle.VerticalAlignment = TextAlignmentType.Bottom;

cellStyle.Font.Name = "Arial";

cellStyle.Font.Size = 12;

cellStyle.Font.Color = Color.Black;

cellStyle.Font.IsBold = true;

cellStyle.Font.IsItalic = false;

cellStyle.Borders.SetColor( defaultStyle.BackgroundColor );

cellStyle.Borders.SetStyle( CellBorderType.Thin );

cellStyle.Borders.DiagonalStyle = CellBorderType.None;

Color styleColor2 = Color.FromArgb( 123, 66, 23 );

index = wb.Styles.Add();

cellStyle = wb.Styles[index];

cellStyle.Name = "Style2";

wb.ChangePalette( styleColor2, 2 );

cellStyle.ForegroundColor = styleColor2;

cellStyle.Pattern = BackgroundType.Solid;

cellStyle.HorizontalAlignment = TextAlignmentType.Left;

cellStyle.VerticalAlignment = TextAlignmentType.Bottom;

cellStyle.Font.Name = "Arial";

cellStyle.Font.Size = 12;

cellStyle.Font.Color = Color.White;

cellStyle.Font.IsBold = true;

cellStyle.Font.IsItalic = false;

cellStyle.Borders.SetColor( defaultStyle.BackgroundColor );

cellStyle.Borders.SetStyle( CellBorderType.Thin );

cellStyle.Borders.DiagonalStyle = CellBorderType.None;

Color styleColor3 = Color.FromArgb( 255, 255, 255 );

index = wb.Styles.Add();

cellStyle = wb.Styles[index];

cellStyle.Name = "Style3";

wb.ChangePalette( styleColor3, 0 );

cellStyle.ForegroundColor = styleColor3;

cellStyle.Pattern = BackgroundType.Solid;

cellStyle.HorizontalAlignment = TextAlignmentType.Left;

cellStyle.VerticalAlignment = TextAlignmentType.Bottom;

cellStyle.Font.Name = "Arial";

cellStyle.Font.Size = 12;

cellStyle.Font.Color = Color.Black;

cellStyle.Font.IsBold = false;

cellStyle.Font.IsItalic = false;

cellStyle.Borders.SetColor( defaultStyle.BackgroundColor );

cellStyle.Borders.SetStyle( CellBorderType.Thin );

cellStyle.Borders.DiagonalStyle = CellBorderType.None;

Range range = wb.Worksheets[0].Cells.CreateRange( 0, 0, 1, 1 );

range.Style = wb.Styles["Style1"];

wb.Worksheets[0].Cells[0, 0].PutValue( "Style 1" );

range = wb.Worksheets[0].Cells.CreateRange( 0, 1, 1, 1 );

range.Style = wb.Styles["Style2"];

wb.Worksheets[0].Cells[0, 1].PutValue( "Style 2" );

range = wb.Worksheets[0].Cells.CreateRange( 1, 0, 1, 1 );

range.Style = wb.Styles["Style3"];

wb.Worksheets[0].Cells[1, 0].PutValue( "Style 3" );

range = wb.Worksheets[0].Cells.CreateRange( 1, 1, 1, 1 );

range.Style = wb.Styles["Style3"];

wb.Worksheets[0].Cells[1, 1].PutValue( "Style 3" );

wb.Save( "c:\\aspose.xls", FileFormatType.Default );

}

Thanks

Alan


#7

I am confused with your need. Do you mean:

1. In MS Excel, cell borders will show as set.

2. When you print the Excel file, cell borders won't show.

If yes, I think it's impossible. Could you make it manually in MS Excel? I think it's no.


#8

No, what I want is that:

(1) The cell borders are displayed in MS Excel

(2) The cell borders are not printed to a page of paper

The behaviour I want is achievable. I have an app written in C# using Interop.Excel that does precisely this.


#9

Could you please post a file to show your need?

I think you may talk about this property:

worksheet.IsGridlinesVisible = true;


#10

Hi Laurence

I've now got this working.

Thanks

Alan