-
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
104 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}") = "ExcelToPDF", "ExcelToPDF\ExcelToPDF.csproj", "{9F221130-3DD2-4908-A5AC-90C4256FDAA0}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{9F221130-3DD2-4908-A5AC-90C4256FDAA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{9F221130-3DD2-4908-A5AC-90C4256FDAA0}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{9F221130-3DD2-4908-A5AC-90C4256FDAA0}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{9F221130-3DD2-4908-A5AC-90C4256FDAA0}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {7BCABE38-D969-49F0-B057-2F80DB8458E1} | ||
EndGlobalSection | ||
EndGlobal |
Binary file not shown.
18 changes: 18 additions & 0 deletions
18
Real Time Examples in Excel/ExcelToPDF/ExcelToPDF/ExcelToPDF.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.XlsIORenderer.Net.Core" Version="24.2.8" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="Output\" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Binary file not shown.
61 changes: 61 additions & 0 deletions
61
Real Time Examples in Excel/ExcelToPDF/ExcelToPDF/Program.cs
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,61 @@ | ||
using Syncfusion.XlsIO; | ||
using Syncfusion.XlsIORenderer; | ||
using Syncfusion.Pdf; | ||
|
||
namespace ExcelToPDF | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
string filePath = "../../../Data/Invoice.xlsx"; | ||
Stream inputExcelData = File.OpenRead(filePath); | ||
Stream outputPDFData = ConvertExcelToPDF(inputExcelData); | ||
File.WriteAllBytes("../../../Output/Invoice.pdf", ((MemoryStream)outputPDFData).ToArray()); | ||
} | ||
|
||
static Stream ConvertExcelToPDF(Stream inputExcelData) | ||
{ | ||
MemoryStream pdfStream = new MemoryStream(); | ||
|
||
//Instantiate the spreadsheet creation engine. | ||
using (ExcelEngine excelEngine = new ExcelEngine()) | ||
{ | ||
//Instantiate the Excel application object. | ||
IApplication application = excelEngine.Excel; | ||
|
||
//Set the default application version. | ||
application.DefaultVersion = ExcelVersion.Xlsx; | ||
|
||
//Load the existing Excel file into IWorkbook. | ||
IWorkbook workbook = application.Workbooks.Open(inputExcelData); | ||
|
||
//Settings for Excel to PDF conversion | ||
XlsIORendererSettings settings = new XlsIORendererSettings(); | ||
|
||
//Set the layout option to fit all columns on one page. | ||
settings.LayoutOptions = LayoutOptions.FitAllColumnsOnOnePage; | ||
|
||
//Initialize the XlsIORenderer. | ||
XlsIORenderer renderer = new XlsIORenderer(); | ||
|
||
//Initialize the PDF document. | ||
PdfDocument pdfDocument = new PdfDocument(); | ||
|
||
//Convert the Excel document to PDF. | ||
pdfDocument = renderer.ConvertToPDF(workbook, settings); | ||
|
||
//Save the PDF file. | ||
pdfDocument.Save(pdfStream); | ||
|
||
//Close the PDF document. | ||
pdfDocument.Close(); | ||
|
||
//Close the workbook. | ||
workbook.Close(); | ||
} | ||
|
||
return pdfStream; | ||
} | ||
} | ||
} |