Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
FileStream inputStream = new FileStream("InputTemplate.xlsx", FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(inputStream);
IWorkbook workbook = application.Workbooks.Open("InputTemplate.xlsx");
IWorksheet worksheet = workbook.Worksheets[0];

//Enable sheet calculation
Expand All @@ -41,10 +40,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
}
}

//Saving the workbook as stream
FileStream outputStream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.ReadWrite);
workbook.SaveAs(outputStream);
outputStream.Dispose();
//Saving the workbook
workbook.SaveAs("Output.xlsx");
}
{% endhighlight %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
pageSetup.RightFooter = "Right Footer Line 1\nRight Footer Line 2";

//Save the excel file
FileStream outputStream = new FileStream("Output.xlsx", FileMode.OpenOrCreate, FileAccess.ReadWrite);
workbook.SaveAs(outputStream);
workbook.SaveAs("Output.xlsx");
workbook.Close();
excelEngine.Dispose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@ The following code snippet shows how to use font substitution in Excel to PDF co
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
FileStream fileStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(fileStream);
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx");

//Initializes the SubstituteFont event to perform font substitution during Excel to PDF conversion
application.SubstituteFont += new SubstituteFontEventHandler(SubstituteFont);

XlsIORenderer renderer = new XlsIORenderer();
PdfDocument pdfDocument = renderer.ConvertToPDF(workbook);

FileStream stream = new FileStream("Output.pdf", FileMode.OpenOrCreate, FileAccess.ReadWrite);
pdfDocument.Save(stream);
pdfDocument.Save("Output.pdf");
}

private static void SubstituteFont(object sender, SubstituteFontEventArgs args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
FileStream inputStream = new FileStream("D:../../../Data/InputTemplate.xlsx", FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(inputStream);
IWorkbook workbook = application.Workbooks.Open("InputTemplate.xlsx");
IWorksheet worksheet = workbook.Worksheets[0];

//Initialize the table
Expand All @@ -38,9 +37,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
}
}

//Saving the workbook as stream
FileStream outputStream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.ReadWrite);
workbook.SaveAs(outputStream);
//Saving the workbook
workbook.SaveAs("Output.xlsx");
}
{% endhighlight %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
worksheet.Pictures.AddPicture(15, 10, barcode2);

// Save to file system
FileStream stream = new FileStream("Output.xlsx",FileMode.OpenOrCreate, FileAccess.ReadWrite);
workbook.SaveAs(stream);
workbook.SaveAs("Output.xlsx");
workbook.Close();
excelEngine.Dispose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
//Setting sheet view to see the page breaks
worksheet.View = SheetView.PageBreakPreview;

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

//Dispose streams
outputStream.Dispose();
//Saving the workbook
workbook.SaveAs("Output.xlsx");
}
{% endhighlight %}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: How to add Oval shape to Excel chart using XlsIO | Syncfusion
description: Code example to add Oval shape to Excel chart using Syncfusion .NET Excel library (XlsIO).
description: This page explains how to add Oval shape to Excel chart in C# (cross-platform and Windows-specific) and VB.NET using Syncfusion .NET Excel library (XlsIO).
platform: document-processing
control: XlsIO
documentation: UG
Expand Down Expand Up @@ -35,12 +35,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())

#region Save
//Saving the workbook
FileStream outputStream = new FileStream(Path.GetFullPath("Output.xlsx"), FileMode.Create, FileAccess.Write);
workbook.SaveAs(outputStream);
workbook.SaveAs("Output.xlsx");
#endregion

//Dispose streams
outputStream.Dispose();
}
{% endhighlight %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.xlsx"), FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(inputStream);
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Input.xlsx"));
IWorksheet worksheet = workbook.Worksheets[0];

//Apply conditional format for specific time period
Expand All @@ -34,12 +33,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
conditionalFormat.BackColor = ExcelKnownColors.Sky_blue;

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

//Dispose streams
outputStream.Dispose();
inputStream.Dispose();
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
}
{% endhighlight %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.xlsx"), FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(inputStream);
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Input.xlsx"));
IWorksheet worksheet = workbook.Worksheets[0];

//Creating an AutoFilter
Expand All @@ -30,12 +29,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
firstCondition.String = "1000.00";

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

//Dispose streams
outputStream.Dispose();
inputStream.Dispose();
workbook.SaveAs(Path.GetFullPath(@"Output/Output.xlsx"));
}
{% endhighlight %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
FileStream fileStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(fileStream);
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx");
IWorksheet worksheet = workbook.Worksheets[0];
IWorksheet pivotSheet = workbook.Worksheets[1];

Expand All @@ -40,10 +39,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
pivotTable.BuiltInStyle = PivotBuiltInStyles.PivotStyleDark15;
pivotTable.Layout();

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

{% endhighlight %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
IApplication application = excelEngine.Excel;

//Load an existing Excel file into IWorkbook
FileStream inputStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(inputStream);
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx");
IWorksheet worksheet = workbook.Worksheets[0];

System.Drawing.Image image = System.Drawing.Image.FromFile("image.png");
Expand All @@ -37,13 +36,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())

#region Save
//Saving the workbook
FileStream outputStream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.Write);
workbook.SaveAs(outputStream);
workbook.SaveAs("Output.xlsx");
#endregion

//Dispose streams
outputStream.Dispose();
inputStream.Dispose();
}
{% endhighlight %}
{% endtabs %}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
IWorksheet sheet_1 = workbook.Worksheets.Create("Sheet");
IWorksheet sheet_2 = workbook.Worksheets.Create("Sheet");

//Saving the workbook as stream
FileStream file = new FileStream("Output.xlsx", FileMode.Create, FileAccess.ReadWrite);
workbook.SaveAs(file);
file.Dispose();
//Saving the workbook
workbook.SaveAs("Output.xlsx");
}
{% endhighlight %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
sorter.Sort();
worksheet.UsedRange.AutofitColumns();

FileStream stream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.ReadWrite);
workbook.SaveAs(stream);
stream.Dispose();
workbook.SaveAs("Output.xlsx");
}
{% endhighlight %}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ platform: document-processing
control: XlsIO
documentation: UG
---
# How to avoid processing unnecessary worksheets when opening an Excel document using C#?
# How to avoid processing unnecessary worksheets using C#?
XlsIO provides support to avoid processing unnecessary worksheets when opening an Excel. The following code snippet illustrates this.
{% tabs %}
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/FAQ/Worksheet/.NET/Parse%20Worksheets%20On%20Demand/Parse%20Worksheets%20On%20Demand/Program.cs,180" %}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
FileStream inputStream = new FileStream("Input.xlsx", FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(inputStream,ExcelOpenType.Automatic, ExcelParseOptions.ParseWorksheetsOnDemand);
IWorkbook workbook = application.Workbooks.Open("Input.xlsx",ExcelOpenType.Automatic, ExcelParseOptions.ParseWorksheetsOnDemand);

// Access the first worksheet (triggers parsing)
IWorksheet worksheet = workbook.Worksheets[0];
Expand All @@ -23,8 +22,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
string value = worksheet.Range["A1"].Text;

// Save to file system
FileStream stream = new FileStream("Output.xlsx", FileMode.OpenOrCreate, FileAccess.ReadWrite);
workbook.SaveAs(stream);
workbook.SaveAs("Output.xlsx");
workbook.Close();
excelEngine.Dispose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2016;
FileStream inputStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(inputStream,ExcelOpenType.Automatic);
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx",ExcelOpenType.Automatic);
IWorksheet sheet = workbook.Worksheets[0];

//Accessing first chart in the sheet
Expand All @@ -27,10 +26,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
chart.Series[0].DataPoints[0].DataLabels.IsValue = true;
chart.Series[0].DataPoints[0].DataLabels.RGBColor = Color.Green;

//Saving the workbook as stream
FileStream stream = new FileStream("Waterfall.xlsx", FileMode.Create, FileAccess.ReadWrite);
workbook.SaveAs(stream);
stream.Dispose();
//Saving the workbook
workbook.SaveAs("Waterfall.xlsx");
}
{% endhighlight %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
FileStream inputStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(inputStream, ExcelOpenType.Automatic);
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx", ExcelOpenType.Automatic);
IWorksheet worksheet = workbook.Worksheets[0];

IFont font = workbook.CreateFont();
Expand All @@ -27,10 +26,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
IShape shape = worksheet.Shapes[0];
shape.TextFrame.TextRange.RichText.SetFont(1, 3, font);

//Saving the workbook as stream
FileStream stream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.ReadWrite);
workbook.SaveAs(stream);
stream.Dispose();
//Saving the workbook
workbook.SaveAs("Output.xlsx");
}
{% endhighlight %}

Expand Down
Loading