Skip to content

Commit b616619

Browse files
committed
Excel Shapes
1 parent 6f6c0c3 commit b616619

File tree

5 files changed

+100
-3
lines changed

5 files changed

+100
-3
lines changed

Excel Shapes/Comment/.NET/Comment/Comment/Program.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ static void Main(string[] args)
1212
IApplication application = excelEngine.Excel;
1313
application.DefaultVersion = ExcelVersion.Xlsx;
1414
IWorkbook workbook = application.Workbooks.Create(1);
15-
IWorksheet sheet = workbook.Worksheets[0];
15+
IWorksheet worksheet = workbook.Worksheets[0];
1616

1717
//Adding comments to a cell
18-
sheet.Range["A1"].AddComment().Text = "Comments";
18+
worksheet.Range["A1"].AddComment().Text = "Comments";
19+
20+
//Adding comments with author to a cell
21+
worksheet.Range["A3"].AddComment().Text = worksheet.Range["A3"].Comment.Author;
1922

2023
//Add Rich Text Comments
21-
IRange range = sheet.Range["A6"];
24+
IRange range = worksheet.Range["A6"];
2225
range.AddComment().RichText.Text = "RichText";
2326
IRichTextString richText = range.Comment.RichText;
2427

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.9.34310.174
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Formatting Comment", "Formatting Comment\Formatting Comment.csproj", "{7BEC1F35-BC70-459B-9751-6F8E9E1A8311}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{7BEC1F35-BC70-459B-9751-6F8E9E1A8311}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{7BEC1F35-BC70-459B-9751-6F8E9E1A8311}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{7BEC1F35-BC70-459B-9751-6F8E9E1A8311}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{7BEC1F35-BC70-459B-9751-6F8E9E1A8311}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {87B43642-0128-46FA-96BE-B5F21C14DAC9}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Formatting_Comment</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="Output\*">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
</ItemGroup>
20+
</Project>

Excel Shapes/Format Comment/.NET/Formatting Comment/Formatting Comment/Output/.gitkeep

Whitespace-only changes.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using Syncfusion.XlsIO;
2+
3+
namespace Formatting_Comment
4+
{
5+
class Program
6+
{
7+
public static void Main(string[] args)
8+
{
9+
using (ExcelEngine excelEngine = new ExcelEngine())
10+
{
11+
IApplication application = excelEngine.Excel;
12+
application.DefaultVersion = ExcelVersion.Xlsx;
13+
IWorkbook workbook = application.Workbooks.Create(1);
14+
IWorksheet worksheet = workbook.Worksheets[0];
15+
16+
//Adding comment in the worksheet with text
17+
worksheet.Range["A1"].AddComment();
18+
ICommentShape comment = worksheet.Comments[0];
19+
comment.Text = "Comment";
20+
21+
//Set size for the comment
22+
comment.Height = 150;
23+
comment.Width = 100;
24+
25+
//Set position for the comment
26+
comment.Left = 200;
27+
comment.Top = 100;
28+
29+
//Set alignment for the comment
30+
comment.HAlignment = ExcelCommentHAlign.Right;
31+
comment.VAlignment = ExcelCommentVAlign.Bottom;
32+
33+
//Set fill for the comment
34+
comment.Fill.TwoColorGradient();
35+
comment.Fill.GradientStyle = ExcelGradientStyle.Horizontal;
36+
comment.Fill.GradientColorType = ExcelGradientColor.TwoColor;
37+
comment.Fill.ForeColorIndex = ExcelKnownColors.Red;
38+
comment.Fill.BackColorIndex = ExcelKnownColors.White;
39+
40+
//Saving the workbook as stream
41+
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Output.xlsx"), FileMode.Create, FileAccess.ReadWrite);
42+
workbook.SaveAs(outputStream);
43+
44+
//Dispose stream
45+
outputStream.Dispose();
46+
}
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)