c# - 使用 C# 在 excel 中创建一个矩形?

标签 c# winforms excel

这是我的代码:

using Excel = Microsoft.Office.Interop.Excel;

Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
xlWorkSheet.Shapes.AddShape(MsoAutoShapeType.msoShapeRectangle, 47, 280, 140, 90);
xlWorkSheet.Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect1, "simple text", "Arial", 14, MsoTriState.msoTrue, MsoTriState.msoFalse, 67, 320);

我想在 MS Office 2010 中创建一个格式类似于“彩色轮廓 - 橙色,重音 6”的圆角矩形。有人帮我吗?

最佳答案

您可以使用EPPLUS支持很多形状。

只需将引用添加到您的项目中。

在下面包含以下命名空间和代码片段以添加圆角矩形。

using OfficeOpenXml;
using OfficeOpenXml.Style;
using OfficeOpenXml.Drawing;       

FileInfo newFile = new FileInfo(@"C:\ExcelFiles\RoundedRectangle.xlsx");
ExcelPackage pck = new ExcelPackage(newFile);
//Add the Content sheet
var ws = pck.Workbook.Worksheets.Add("MySheet");
ws.View.ShowGridLines = false;
var shape = ws.Drawings.AddShape("Description", eShapeStyle.RoundRect);
shape.SetPosition(0, 5, 5, 5);
shape.SetSize(400, 200);
shape.Text = "Text inside the round rectangle";
shape.Fill.Style = eFillStyle.SolidFill;
shape.Fill.Transparancy = 20;
shape.Border.Fill.Style = eFillStyle.SolidFill;
shape.Border.LineStyle = eLineStyle.LongDash;
shape.Border.Width = 1;
shape.Border.Fill.Color = Color.Black;
shape.Border.LineCap = eLineCap.Round;
shape.TextAnchoring = eTextAnchoringType.Top;
shape.TextVertical = eTextVerticalType.Horizontal;
shape.TextAnchoringControl = false;

pck.Save();

关于c# - 使用 C# 在 excel 中创建一个矩形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13603360/

相关文章:

vba - 根据最后一行生成一个直接的数字序列

python - pandas、python 中的数据解析

javascript - 如何根据 Windows 10 UWP 中的 HTML 内容调整 Webview 高度?

c# - 用户定义值类型的装箱

c# - 用作变量错误的类型

c# - 在面板内的控件之上绘图 (C# WinForms)

.net - 按名称选择特定打印机 VB

excel - 访问文件时出错。网络连接可能已丢失

c# - 如何以编程方式设置 UITableViewCell 中显示的文本

c# - 如何检索 'AssemblyCompany' 设置(在 AssemblyInfo.cs 中)?