-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.34414.90 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExcelTable", "ExcelTable\ExcelTable.csproj", "{3AC8CBBD-68FB-485B-A202-35ABE6681BE6}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{3AC8CBBD-68FB-485B-A202-35ABE6681BE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{3AC8CBBD-68FB-485B-A202-35ABE6681BE6}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{3AC8CBBD-68FB-485B-A202-35ABE6681BE6}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{3AC8CBBD-68FB-485B-A202-35ABE6681BE6}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {ED8871A2-860B-4E8F-9EFD-F92673F1AACB} | ||
EndGlobalSection | ||
EndGlobal |
Binary file not shown.
18 changes: 18 additions & 0 deletions
18
Create and Edit Table/ExcelTable/ExcelTable/ExcelTable.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="25.1.40" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="Output\" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using Syncfusion.XlsIO; | ||
|
||
namespace ExcelTable | ||
{ | ||
class Program | ||
{ | ||
public static void Main() | ||
{ | ||
Program program = new Program(); | ||
program.CreateTable(); | ||
} | ||
|
||
/// <summary> | ||
/// Creates a Excel table in the existing Excel document. | ||
/// </summary> | ||
public void CreateTable() | ||
{ | ||
using (ExcelEngine excelEngine = new ExcelEngine()) | ||
{ | ||
IApplication application = excelEngine.Excel; | ||
application.DefaultVersion = ExcelVersion.Xlsx; | ||
FileStream fileStream = new FileStream("../../../Data/SalesReport.xlsx", FileMode.Open, FileAccess.Read); | ||
IWorkbook workbook = application.Workbooks.Open(fileStream, ExcelOpenType.Automatic); | ||
IWorksheet worksheet = workbook.Worksheets[0]; | ||
|
||
AddExcelTable("Table1", worksheet.UsedRange); | ||
|
||
string fileName = "../../../Output/SalesReport.xlsx"; | ||
|
||
//Saving the workbook as stream | ||
FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite); | ||
workbook.SaveAs(stream); | ||
stream.Dispose(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Adds a table to the worksheet with the given name and range | ||
/// </summary> | ||
/// <param name="tableName">Table name</param> | ||
/// <param name="tableRange">Table range</param> | ||
public void AddExcelTable(string tableName, IRange tableRange) | ||
{ | ||
IWorksheet worksheet = tableRange.Worksheet; | ||
|
||
//Create table with the data in given range | ||
IListObject table = worksheet.ListObjects.Create(tableName, tableRange); | ||
|
||
//Set table style | ||
table.BuiltInTableStyle = TableBuiltInStyles.TableStyleMedium14; | ||
} | ||
} | ||
} |