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 @@ -32,13 +32,9 @@ static void Main(string[] args)

#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();
}
}
}
}
}
5 changes: 1 addition & 4 deletions FAQ/Barcode/.NET/Add Barcode/Barcode/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@ static void Main(string[] args)
worksheet.Pictures.AddPicture(15, 10, barcode2);

// Save to file system
FileStream stream = new FileStream("Output/Output.xlsx", FileMode.OpenOrCreate, FileAccess.ReadWrite);
workbook.SaveAs(stream);
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
workbook.Close();
excelEngine.Dispose();
}

}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ static void Main(string[] args)
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(inputStream);
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
IWorksheet worksheet = workbook.Worksheets[0];

//Get the first chart in the worksheet
Expand All @@ -28,16 +27,9 @@ static void Main(string[] args)

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

//Dispose streams
outputStream.Dispose();
inputStream.Dispose();
}

}

}
}
}
6 changes: 1 addition & 5 deletions FAQ/Chart/.NET/Show leader line/Show leader line/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,8 @@ static void Main(string[] args)

#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();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,8 @@ static void Main(string[] args)

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

//Dispose streams
outputStream.Dispose();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ static void Main(string[] args)
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(inputStream);
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
IWorksheet worksheet = workbook.Worksheets[0];
IWorksheet worksheet1 = workbook.Worksheets[1];

Expand All @@ -39,14 +38,9 @@ static void Main(string[] args)

#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();
inputStream.Dispose();
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ static void Main(string[] args)
{
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 @@ -28,12 +27,7 @@ static void Main(string[] args)
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"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,9 @@ static void Main(string[] args)
iconSet.IconSet = ExcelIconSetType.ThreeTrafficLights1;

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

}

}
}

Expand Down
6 changes: 1 addition & 5 deletions FAQ/Conversions/.NET/JSON to CSV/JSON to CSV/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ static void Main()
sheet.ImportDataTable(dataTable, true, 1, 1);

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

//Dispose streams
outputStream.Dispose();
workbook.SaveAs(Path.GetFullPath("Output/Sample.csv"), ",");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ public static void Main(string[] args)
{
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 @@ -23,12 +22,7 @@ public static void Main(string[] args)
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"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,18 @@ static void Main(string[] args)
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
FileStream inputStream = new FileStream("Data/InputTemplate.xlsx", FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(inputStream);
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
IWorksheet worksheet = workbook.Worksheets[0];

// Remove first hyperlink without affecting cell styles
HyperLinksCollection hyperlink = worksheet.HyperLinks as HyperLinksCollection;
hyperlink.Remove(hyperlink[0] as HyperLinkImpl);

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

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ static void Main(string[] args)
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;

//Open an existing Excel file as stream
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Sample.xlsx"), FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(inputStream);
//Open an existing Excel file
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Sample.xlsx"));
IWorksheet worksheet = workbook.Worksheets[0];

//Modify the data
Expand All @@ -26,12 +25,8 @@ static void Main(string[] args)

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

//Dispose output stream
outputStream.Dispose();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ public static void Main(string[] args)
Console.WriteLine($"Red: {red}, Green: {green}, Blue: {blue}");

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

//Dispose stream
outputStream.Dispose();
workbook.SaveAs(Path.GetFullPath("../../../Output/Output.xlsx"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@ static void Main(string[] args)

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

//Dispose streams
outputStream.Dispose();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ static void Main(string[] args)
sheet.Range["A1"].Text = "This is default font and size";

//Save to file
FileStream outputStream = new FileStream("Output/Output.xlsx", FileMode.Create, FileAccess.Write);
workbook.SaveAs(outputStream);

//Dispose streams
outputStream.Dispose();

workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ static void Main(string[] args)
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;

FileStream inputStream = new FileStream("Data/Input.xlsx", FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(inputStream);
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Input.xlsx"));

//Get the worksheets collection
WorksheetsCollection worksheets = workbook.Worksheets as WorksheetsCollection;
Expand All @@ -25,11 +24,7 @@ static void Main(string[] args)
{
Console.WriteLine(worksheet.Name);
}

//Dispose streams
inputStream.Dispose();
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ static void Main(string[] args)
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;

FileStream inputStream = new FileStream("Data/Input.xlsx", FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(inputStream);
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Input.xlsx"));

//Get the worksheets collection
WorksheetsCollection worksheets = workbook.Worksheets as WorksheetsCollection;
Expand All @@ -26,10 +25,6 @@ static void Main(string[] args)
if (worksheet.Visibility == WorksheetVisibility.Hidden)
Console.WriteLine(worksheet.Name);
}

//Dispose streams
inputStream.Dispose();

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ static void Main(string[] args)
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
FileStream inputStream = new FileStream("Data/Input.xlsx", FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(inputStream);
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Input.xlsx"));

//Get the worksheets collection
WorksheetsCollection worksheets = workbook.Worksheets as WorksheetsCollection;
Expand All @@ -25,10 +24,6 @@ static void Main(string[] args)
if (worksheet.Visibility == WorksheetVisibility.Visible)
Console.WriteLine(worksheet.Name);
}

//Dispose streams
inputStream.Dispose();

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ static void Main(string[] args)
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
FileStream inputStream = new FileStream("Data/Input.xlsx", FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(inputStream, ExcelOpenType.Automatic, ExcelParseOptions.ParseWorksheetsOnDemand);
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Input.xlsx"), ExcelOpenType.Automatic, ExcelParseOptions.ParseWorksheetsOnDemand);

// Access the first worksheet (triggers parsing)
IWorksheet worksheet = workbook.Worksheets[0];
Expand All @@ -24,13 +23,10 @@ static void Main(string[] args)
string value = worksheet.Range["A1"].Text;

// Save to file system
FileStream stream = new FileStream("Output/Output.xlsx", FileMode.OpenOrCreate, FileAccess.ReadWrite);
workbook.SaveAs(stream);
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
workbook.Close();
excelEngine.Dispose();
}

}

}
}