繁体   English   中英

如何使用 Aspose 在 excel 和 C# 中创建对角线

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

我曾使用 aspose 来渲染报告,但我不知道如何使用 aspose 为 C# 创建跨 excel 中的多个单元格的对角线? 可以看作是对角线放置在单元格上方,但我没有找到解决方案。

请参阅以下示例代码,了解如何使用 Aspose.Cells 将对角边框应用于工作表中的单元格以供参考:

例如

示例代码:

// 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");

您也可以在 Aspose论坛中发布您的查询/评论。

PS。 我在 Aspose 担任支持开发人员/传播者。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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