简体   繁体   中英

Spreadsheetlight: Border around cell range, no internal borders

Using SpreadsheetLight I want to add a border (only) around a cell range. There shouldn't be any borders inside that range.

What I want:

我想要的是

What I get:

在此处输入图像描述

Code I used:

var testDoc = new SLDocument();

var testStyle = testDoc.CreateStyle();
testStyle.Border.Outline = true;
testStyle.Border.SetLeftBorder(DocumentFormat.OpenXml.Spreadsheet.BorderStyleValues.Thin, Color.Black);
testStyle.Border.SetRightBorder(DocumentFormat.OpenXml.Spreadsheet.BorderStyleValues.Thin, Color.Black);
testStyle.Border.SetTopBorder(DocumentFormat.OpenXml.Spreadsheet.BorderStyleValues.Thin, Color.Black);
testStyle.Border.SetBottomBorder(DocumentFormat.OpenXml.Spreadsheet.BorderStyleValues.Thin, Color.Black);
testDoc.SetCellStyle("A3", "F5", testStyle);

return testDoc;

What am I doing wrong? I expected the option Border.Outline = true to result in only producing an outline. Setting it to false doesn't change anything in the output. I'm using SpreadsheetLight in the version 3.5.0 (most current version on NuGet).

I couldn't fix the problem with the styles, but I found another option to draw borders, and this one actually draws an outline like I wanted. Maybe this helps others having the same problem:

testDoc.DrawBorder("A3", "F5", DocumentFormat.OpenXml.Spreadsheet.BorderStyleValues.Thin, Color.Black);

Estableces tus estilos:

style.Border.LeftBorder.BorderStyle = BorderStyleValues.Thin;
style.Border.LeftBorder.Color = System.Drawing.Color.Black;
style.Border.RightBorder.BorderStyle = BorderStyleValues.Thin;
style.Border.RightBorder.Color = System.Drawing.Color.Black;
style.Border.BottomBorder.BorderStyle = BorderStyleValues.Thin;
style.Border.BottomBorder.Color = System.Drawing.Color.Black;
style.Border.TopBorder.BorderStyle = BorderStyleValues.Thin;
style.Border.TopBorder.Color = System.Drawing.Color.Black;

Defines el rango de celdas a aplicarle el estilo definido que incluyen los margenes

slExcel.MergeWorksheetCells("B6","P6", style);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM