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 @@ -11,8 +11,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"));

#region Access
//Accessing via index
Expand All @@ -21,9 +20,6 @@ static void Main(string[] args)
//Accessing via sheet name
IWorksheet NamedSheet = workbook.Worksheets["Sample"];
#endregion

//Dispose streams
inputStream.Dispose();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@ static void Main(string[] args)

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

//Dispose streams
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)
source.AutoFill(destinationRange, ExcelAutoFillType.FillSeries);

//Saving the workbook
FileStream outputStream = new FileStream(Path.GetFullPath("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 @@ -10,9 +10,7 @@ static void Main(string[] args)
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;

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

IWorksheet sourceWorksheet = workbook.Worksheets[0];
IWorksheet destinationWorksheet = workbook.Worksheets[1];
Expand All @@ -23,13 +21,8 @@ static void Main(string[] args)
//Copy the cell range to the next sheet
source.CopyTo(destination);

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

//Dispose streams
outputStream.Dispose();
sourceStream.Dispose();
//Saving the workbook
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ public 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 sourceWorksheet = workbook.Worksheets[0];
IWorksheet destinationWorksheet = workbook.Worksheets[1];
Expand All @@ -26,13 +24,8 @@ public static void Main(string[] args)
//Copy the entire column to the next sheet
sourceColumn.EntireColumn.CopyTo(destinationColumn);

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

//Dispose streams
outputStream.Dispose();
inputStream.Dispose();
//Saving the workbook
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
}
}
}
Expand Down
10 changes: 2 additions & 8 deletions Worksheet Features/Copy Row/.NET/Copy Row/Copy Row/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public 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 sourceWorksheet = workbook.Worksheets[0];
IWorksheet destinationWorksheet = workbook.Worksheets[1];
Expand All @@ -27,12 +26,7 @@ public static void Main(string[] args)
sourceRow.EntireRow.CopyTo(destinationRow);

//Saving the workbook as stream
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 @@ -13,22 +13,14 @@ public static void Main(string[] args)
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
FileStream sourceStream = new FileStream(Path.GetFullPath(@"Data/SourceWorkbookTemplate.xlsx"), FileMode.Open, FileAccess.Read);
IWorkbook sourceWorkbook = application.Workbooks.Open(sourceStream);
FileStream destinationStream = new FileStream(Path.GetFullPath(@"Data/DestinationWorkbookTemplate.xlsx"), FileMode.Open, FileAccess.Read);
IWorkbook destinationWorkbook = application.Workbooks.Open(destinationStream);
IWorkbook sourceWorkbook = application.Workbooks.Open(Path.GetFullPath(@"Data/SourceWorkbookTemplate.xlsx"));
IWorkbook destinationWorkbook = application.Workbooks.Open(Path.GetFullPath(@"Data/DestinationWorkbookTemplate.xlsx"));

//Clone the workbook
destinationWorkbook = sourceWorkbook.Clone();

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

//Dispose streams
outputStream.Dispose();
destinationStream.Dispose();
sourceStream.Dispose();
//Saving the workbook
destinationWorkbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ static void Main(string[] args)
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;

FileStream sourceStream = new FileStream(Path.GetFullPath(@"Data/SourceTemplate.xlsx"), FileMode.Open, FileAccess.Read);
IWorkbook sourceWorkbook = application.Workbooks.Open(sourceStream);

FileStream destinationStream = new FileStream(Path.GetFullPath(@"Data/DestinationTemplate.xlsx"), FileMode.Open, FileAccess.Read);
IWorkbook destinationWorkbook = application.Workbooks.Open(destinationStream);
IWorkbook sourceWorkbook = application.Workbooks.Open(Path.GetFullPath(@"Data/SourceTemplate.xlsx"));
IWorkbook destinationWorkbook = application.Workbooks.Open(Path.GetFullPath(@"Data/DestinationTemplate.xlsx"));

#region Copy Worksheet
//Copy first worksheet from the source workbook to the destination workbook
Expand All @@ -26,14 +22,8 @@ static void Main(string[] args)

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

//Dispose streams
outputStream.Dispose();
destinationStream.Dispose();
sourceStream.Dispose();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@ static void Main(string[] args)

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

//Dispose streams
outputStream.Dispose();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ public static void Main(string[] args)
range.FillSeries(ExcelSeriesBy.Columns, ExcelFillSeries.Years, 2, new DateTime(2100, 1, 1));

//Saving the workbook
FileStream outputStream = new FileStream(Path.GetFullPath("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 @@ -25,11 +25,7 @@ public static void Main(string[] args)
range.FillSeries(ExcelSeriesBy.Columns, ExcelFillSeries.Linear, true);

//Saving the workbook
FileStream outputStream = new FileStream(Path.GetFullPath("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 @@ -23,11 +23,7 @@ public static void Main(string[] args)
range.FillSeries(ExcelSeriesBy.Columns, ExcelFillSeries.Linear, 5, 1000);

//Saving the workbook
FileStream outputStream = new FileStream(Path.GetFullPath("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 @@ -31,12 +31,8 @@ static void Main(string[] args)

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

//Dispose streams
outputStream.Dispose();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,8 @@ static void Main(string[] args)

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

//Dispose streams
outputStream.Dispose();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,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];

//Applying freeze columns to the sheet by specifying a cell
Expand All @@ -21,13 +20,8 @@ static void Main(string[] args)
//Set first visible column in the right pane
worksheet.FirstVisibleColumn = 4;

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

//Dispose streams
outputStream.Dispose();
inputStream.Dispose();
//Saving the workbook
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,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];

//Applying freeze rows to the sheet by specifying a cell
Expand All @@ -21,13 +20,8 @@ static void Main(string[] args)
//Set first visible row in the bottom pane
worksheet.FirstVisibleRow = 3;

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

//Dispose streams
outputStream.Dispose();
inputStream.Dispose();
//Saving the workbook
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ static void Main(string[] args)
//Adding the file name to the right footer with blue color formatting
worksheet.PageSetup.RightFooter = "&K0000FF&F";

//Saving the workbook as stream
FileStream stream = new FileStream(Path.GetFullPath("Output/Output.xlsx"), FileMode.Create);
workbook.SaveAs(stream);
stream.Dispose();
//Saving the workbook
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ static void Main(string[] args)

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

//Dispose streams
outputStream.Dispose();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ static void Main(string[] args)

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

//Dispose streams
outputStream.Dispose();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,15 @@ 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];

//Hide row and column
worksheet.HideRow(2);
worksheet.HideColumn(2);

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

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

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

//Dispose streams
outputStream.Dispose();
}
}
}
Expand Down
Loading