Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

261741 - Add sample for formatting comment #143

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Excel Shapes/Comment/.NET/Comment/Comment/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ static void Main(string[] args)
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
IWorksheet worksheet = workbook.Worksheets[0];

//Adding comments to a cell
sheet.Range["A1"].AddComment().Text = "Comments";
worksheet.Range["A1"].AddComment().Text = "Comments";

//Adding comments with author to a cell
worksheet.Range["A3"].AddComment().Text = worksheet.Range["A3"].Comment.Author;

//Add Rich Text Comments
IRange range = sheet.Range["A6"];
IRange range = worksheet.Range["A6"];
range.AddComment().RichText.Text = "RichText";
IRichTextString richText = range.Comment.RichText;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34310.174
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Formatting Comment", "Formatting Comment\Formatting Comment.csproj", "{7BEC1F35-BC70-459B-9751-6F8E9E1A8311}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7BEC1F35-BC70-459B-9751-6F8E9E1A8311}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7BEC1F35-BC70-459B-9751-6F8E9E1A8311}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7BEC1F35-BC70-459B-9751-6F8E9E1A8311}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7BEC1F35-BC70-459B-9751-6F8E9E1A8311}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {87B43642-0128-46FA-96BE-B5F21C14DAC9}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Formatting_Comment</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="*" />
</ItemGroup>

<ItemGroup>
<None Update="Output\*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Syncfusion.XlsIO;

namespace Formatting_Comment
{
class Program
{
public static void Main(string[] args)
{
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];

//Adding comment in the worksheet with text
worksheet.Range["A1"].AddComment();
ICommentShape comment = worksheet.Comments[0];
comment.Text = "Comment";

//Set size for the comment
comment.Height = 150;
comment.Width = 100;

//Set position for the comment
comment.Left = 200;
comment.Top = 100;

//Set alignment for the comment
comment.HAlignment = ExcelCommentHAlign.Right;
comment.VAlignment = ExcelCommentVAlign.Bottom;

//Set fill for the comment
comment.Fill.TwoColorGradient();
comment.Fill.GradientStyle = ExcelGradientStyle.Horizontal;
comment.Fill.GradientColorType = ExcelGradientColor.TwoColor;
comment.Fill.ForeColorIndex = ExcelKnownColors.Red;
comment.Fill.BackColorIndex = ExcelKnownColors.White;

//Saving the workbook as stream
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Output.xlsx"), FileMode.Create, FileAccess.ReadWrite);
workbook.SaveAs(outputStream);

//Dispose stream
outputStream.Dispose();
}
}
}
}
Loading