Skip to content

Commit 158b475

Browse files
990137-ExcelToPdfSample
1 parent 1be6799 commit 158b475

File tree

32 files changed

+73
-297
lines changed
  • Excel to PDF
    • Automatic Layout/.NET/Automatic Layout/Automatic Layout
    • Blank Page to PDF/.NET/Blank Page to PDF/Blank Page to PDF
    • Blank Sheet to PDF/.NET/Blank Sheet to PDF/Blank Sheet to PDF
    • Bookmarks in PDF/.NET/Bookmarks in PDF/Bookmarks in PDF
    • Chart to PDF/.NET/Chart to PDF/Chart to PDF
    • Comments in Place to PDF/.NET/Comments in Place to PDF/Comments in Place to PDF
    • Comments to PDF at End/.NET/Comments to PDF at End/Comments to PDF at End
    • Complex Script to PDF/.NET/Complex Script to PDF/Complex Script to PDF
    • Custom Paper Size/.NET/Custom Paper Size/Custom Paper Size
    • Custom Scaling/.NET/Custom Scaling/Custom Scaling
    • Document Properties to PDF/.NET/Document Properties to PDF/Document Properties to PDF
    • Each Worksheet to PDF/.NET/Each Worksheet to PDF/Each Worksheet to PDF
    • Embed Fonts in PDF/.NET/Embed Fonts in PDF/Embed Fonts in PDF
    • Empty Excel to PDF/.NET/Empty Excel to PDF/Empty Excel to PDF
    • Fallback fonts based on script type/.NET/Fallback_fonts_based_on_scripttype/Fallback_fonts_based_on_scripttype
    • Fallback fonts for unicode range/.NET/Fallback_fonts_for_unicode_range/Fallback_fonts_for_unicode_range
    • Fit All Columns On One Page/.NET/Fit All Columns On One Page/Fit All Columns On One Page
    • Fit All Rows On One Page/.NET/Fit All Rows On One Page/Fit All Rows On One Page
    • Fit Sheet On One Page/.NET/Fit Sheet On One Page/Fit Sheet On One Page
    • Gridlines in PDF/.NET/Gridlines in PDF/Gridlines in PDF
    • Initialize default fallback fonts/.NET/Initialize_default-fallback_fonts/Initialize_default-fallback_fonts
    • Modify the existing fallback fonts/.NET/Modify_the_existing_fallback_fonts/Modify_the_existing_fallback_fonts
    • Multiple Excel to PDF/.NET/Multiple Excel to PDF/Multiple Excel to PDF
    • No Comments in PDF/.NET/No Comments in PDF/No Comments in PDF
    • No Scaling/.NET/No Scaling/No Scaling
    • PDF Conformance/.NET/PDF Conformance/PDF Conformance
    • Quality Image in PDF/.NET/Quality Image in PDF/Quality Image in PDF
    • Selected Worksheets to PDF/.NET/Selected Worksheets to PDF/Selected Worksheets to PDF
    • Warnings/.NET/Warnings/Warnings
    • Workbook to PDF/.NET/Workbook to PDF/Workbook to PDF
    • Worksheet to PDF/.NET/Worksheet to PDF/Worksheet to PDF

32 files changed

+73
-297
lines changed

Excel to PDF/Automatic Layout/.NET/Automatic Layout/Automatic Layout/Program.cs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ static void Main(string[] args)
1313
{
1414
IApplication application = excelEngine.Excel;
1515
application.DefaultVersion = ExcelVersion.Xlsx;
16-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
17-
IWorkbook workbook = application.Workbooks.Open(inputStream);
16+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
1817

1918
//Initialize XlsIORendererSettings
2019
XlsIORendererSettings settings = new XlsIORendererSettings();
@@ -30,19 +29,9 @@ static void Main(string[] args)
3029

3130
#region Save
3231
//Saving the workbook
33-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Automatic.pdf"), FileMode.Create, FileAccess.Write);
34-
pdfDocument.Save(outputStream);
32+
pdfDocument.Save(Path.GetFullPath("Output/Automatic.pdf"));
3533
#endregion
36-
37-
//Dispose streams
38-
outputStream.Dispose();
39-
inputStream.Dispose();
4034
}
4135
}
4236
}
43-
}
44-
45-
46-
47-
48-
37+
}

Excel to PDF/Blank Page to PDF/.NET/Blank Page to PDF/Blank Page to PDF/Program.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ static void Main(string[] args)
1313
{
1414
IApplication application = excelEngine.Excel;
1515
application.DefaultVersion = ExcelVersion.Xlsx;
16-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
17-
IWorkbook workbook = application.Workbooks.Open(inputStream);
16+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
1817

1918
//Initialize XlsIORendererSettings
2019
XlsIORendererSettings settings = new XlsIORendererSettings();
@@ -30,13 +29,8 @@ static void Main(string[] args)
3029

3130
#region Save
3231
//Saving the workbook
33-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/BlankPageToPDF.pdf"), FileMode.Create, FileAccess.Write);
34-
pdfDocument.Save(outputStream);
32+
pdfDocument.Save(Path.GetFullPath("Output/BlankPageToPDF.pdf"));
3533
#endregion
36-
37-
//Dispose streams
38-
outputStream.Dispose();
39-
inputStream.Dispose();
4034
}
4135
}
4236
}

Excel to PDF/Blank Sheet to PDF/.NET/Blank Sheet to PDF/Blank Sheet to PDF/Program.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ static void Main(string[] args)
1313
{
1414
IApplication application = excelEngine.Excel;
1515
application.DefaultVersion = ExcelVersion.Xlsx;
16-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
17-
IWorkbook workbook = application.Workbooks.Open(inputStream);
16+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
1817

1918
//Initialize XlsIORendererSettings
2019
XlsIORendererSettings settings = new XlsIORendererSettings();
@@ -30,13 +29,8 @@ static void Main(string[] args)
3029

3130
#region Save
3231
//Saving the workbook
33-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/BlankSheetToPDF.pdf"), FileMode.Create, FileAccess.Write);
34-
pdfDocument.Save(outputStream);
32+
pdfDocument.Save(Path.GetFullPath("Output/BlankSheetToPDF.pdf"));
3533
#endregion
36-
37-
//Dispose streams
38-
outputStream.Dispose();
39-
inputStream.Dispose();
4034
}
4135
}
4236
}

Excel to PDF/Bookmarks in PDF/.NET/Bookmarks in PDF/Bookmarks in PDF/Program.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ static void Main(string[] args)
1313
{
1414
IApplication application = excelEngine.Excel;
1515
application.DefaultVersion = ExcelVersion.Xlsx;
16-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
17-
IWorkbook workbook = application.Workbooks.Open(inputStream);
16+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
1817

1918
//Initialize XlsIORendererSettings
2019
XlsIORendererSettings settings = new XlsIORendererSettings();
@@ -30,13 +29,8 @@ static void Main(string[] args)
3029

3130
#region Save
3231
//Saving the workbook
33-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/BookmarksInPDF.pdf"), FileMode.Create, FileAccess.Write);
34-
pdfDocument.Save(outputStream);
32+
pdfDocument.Save(Path.GetFullPath("Output/BookmarksInPDF.pdf"));
3533
#endregion
36-
37-
//Dispose streams
38-
outputStream.Dispose();
39-
inputStream.Dispose();
4034
}
4135
}
4236
}

Excel to PDF/Chart to PDF/.NET/Chart to PDF/Chart to PDF/Program.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ static void Main(string[] args)
1313
{
1414
IApplication application = excelEngine.Excel;
1515
application.DefaultVersion = ExcelVersion.Xlsx;
16-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
17-
IWorkbook workbook = application.Workbooks.Open(inputStream);
16+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
1817
IWorksheet worksheet = workbook.Worksheets[0];
1918

2019
IChart chart = worksheet.Charts[0];
@@ -27,13 +26,8 @@ static void Main(string[] args)
2726

2827
#region Save
2928
//Saving the workbook
30-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/ChartToPDF.pdf"), FileMode.Create, FileAccess.Write);
31-
pdfDocument.Save(outputStream);
29+
pdfDocument.Save(Path.GetFullPath("Output/ChartToPDF.pdf"));
3230
#endregion
33-
34-
//Dispose streams
35-
outputStream.Dispose();
36-
inputStream.Dispose();
3731
}
3832
}
3933
}

Excel to PDF/Comments in Place to PDF/.NET/Comments in Place to PDF/Comments in Place to PDF/Program.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ static void Main(string[] args)
1313
{
1414
IApplication application = excelEngine.Excel;
1515
application.DefaultVersion = ExcelVersion.Xlsx;
16-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
17-
IWorkbook workbook = application.Workbooks.Open(inputStream);
16+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
1817
IWorksheet worksheet = workbook.Worksheets[0];
1918

2019
//Set print location to comments
@@ -28,13 +27,8 @@ static void Main(string[] args)
2827

2928
#region Save
3029
//Saving the workbook
31-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/CommentsInPlaceToPDF.pdf"), FileMode.Create, FileAccess.Write);
32-
pdfDocument.Save(outputStream);
30+
pdfDocument.Save(Path.GetFullPath("Output/CommentsInPlaceToPDF.pdf"));
3331
#endregion
34-
35-
//Dispose streams
36-
outputStream.Dispose();
37-
inputStream.Dispose();
3832
}
3933
}
4034
}

Excel to PDF/Comments to PDF at End/.NET/Comments to PDF at End/Comments to PDF at End/Program.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ static void Main(string[] args)
1313
{
1414
IApplication application = excelEngine.Excel;
1515
application.DefaultVersion = ExcelVersion.Xlsx;
16-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
17-
IWorkbook workbook = application.Workbooks.Open(inputStream);
16+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
1817
IWorksheet worksheet = workbook.Worksheets[0];
1918

2019
//Set print location to comments
@@ -28,13 +27,8 @@ static void Main(string[] args)
2827

2928
#region Save
3029
//Saving the workbook
31-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/CommentsToPDFAtEnd.pdf"), FileMode.Create, FileAccess.Write);
32-
pdfDocument.Save(outputStream);
30+
pdfDocument.Save(Path.GetFullPath("Output/CommentsToPDFAtEnd.pdf"));
3331
#endregion
34-
35-
//Dispose streams
36-
outputStream.Dispose();
37-
inputStream.Dispose();
3832
}
3933
}
4034
}

Excel to PDF/Complex Script to PDF/.NET/Complex Script to PDF/Complex Script to PDF/Program.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ static void Main(string[] args)
1313
{
1414
IApplication application = excelEngine.Excel;
1515
application.DefaultVersion = ExcelVersion.Xlsx;
16-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
17-
IWorkbook workbook = application.Workbooks.Open(inputStream);
16+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
1817

1918
//Initialize XlsIORendererSettings
2019
XlsIORendererSettings settings = new XlsIORendererSettings();
@@ -30,13 +29,8 @@ static void Main(string[] args)
3029

3130
#region Save
3231
//Saving the workbook
33-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/ComplexScriptToPDF.pdf"), FileMode.Create, FileAccess.Write);
34-
pdfDocument.Save(outputStream);
32+
pdfDocument.Save(Path.GetFullPath("Output/ComplexScriptToPDF.pdf"));
3533
#endregion
36-
37-
//Dispose streams
38-
outputStream.Dispose();
39-
inputStream.Dispose();
4034
}
4135
}
4236
}

Excel to PDF/Custom Paper Size/.NET/Custom Paper Size/Custom Paper Size/Program.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ static void Main(string[] args)
1414
{
1515
IApplication application = excelEngine.Excel;
1616
application.DefaultVersion = ExcelVersion.Xlsx;
17-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
18-
IWorkbook workbook = application.Workbooks.Open(inputStream);
17+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
1918

2019
//Initialize XlsIORendererSettings
2120
XlsIORendererSettings settings = new XlsIORendererSettings();
@@ -31,13 +30,8 @@ static void Main(string[] args)
3130

3231
#region Save
3332
//Saving the workbook
34-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/CustomPaperSize.pdf"), FileMode.Create, FileAccess.Write);
35-
pdfDocument.Save(outputStream);
33+
pdfDocument.Save(Path.GetFullPath("Output/CustomPaperSize.pdf"));
3634
#endregion
37-
38-
//Dispose streams
39-
outputStream.Dispose();
40-
inputStream.Dispose();
4135
}
4236
}
4337
}

Excel to PDF/Custom Scaling/.NET/Custom Scaling/Custom Scaling/Program.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ static void Main(string[] args)
1313
{
1414
IApplication application = excelEngine.Excel;
1515
application.DefaultVersion = ExcelVersion.Xlsx;
16-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
17-
IWorkbook workbook = application.Workbooks.Open(inputStream);
16+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
1817

1918
//Initialize XlsIORendererSettings
2019
XlsIORendererSettings settings = new XlsIORendererSettings();
@@ -30,13 +29,8 @@ static void Main(string[] args)
3029

3130
#region Save
3231
//Saving the workbook
33-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/CustomScaling.pdf"), FileMode.Create, FileAccess.Write);
34-
pdfDocument.Save(outputStream);
32+
pdfDocument.Save(Path.GetFullPath("Output/CustomScaling.pdf"));
3533
#endregion
36-
37-
//Dispose streams
38-
outputStream.Dispose();
39-
inputStream.Dispose();
4034
}
4135
}
4236
}

0 commit comments

Comments
 (0)