简体   繁体   中英

How to create a diagonal line in excel with C# using Aspose

I've worked with aspose for rendering reports but i don't know how to create a diagonal line across multiple cells in excel using aspose for C#? It can be seen as a diagonal line is laid above the cells but i do not find a solution for that.

See the following sample code on how to apply Diagonal border to a cell in the worksheet using Aspose.Cells for your reference:

eg

Sample code:

// Instantiating a Workbook object
Workbook workbook = new Workbook();

// Obtaining the reference of the first (default) worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[0];

// Accessing the "A1" cell from the worksheet
Aspose.Cells.Cell cell = worksheet.Cells["A1"];

// Adding some value to the "A1" cell
cell.PutValue("Test!");

// Create a style object
Style style = cell.GetStyle();

// Setting the line style of the top border
style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thick;

// Setting the color of the top border
style.Borders[BorderType.TopBorder].Color = Color.Black;

// Setting the line style of the bottom border
style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thick;

// Setting the color of the bottom border
style.Borders[BorderType.BottomBorder].Color = Color.Black;

// Setting the line style of the diagonal border
style.Borders[BorderType.DiagonalDown].LineStyle = CellBorderType.Thin;

// Setting the color of the diagonal border
style.Borders[BorderType.DiagonalDown].Color = Color.Black;


// Apply the border styles to the cell
cell.SetStyle(style);

// Saving the Excel file
workbook.Save(dataDir + "book1.out.xls");

You may also post your queries/comments in Aspose forums .

PS. I am working as Support developer/ Evangelist at Aspose.

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