Skip to content

Commit e22bec5

Browse files
authored
Merge pull request #249 from SyncfusionExamples/988804-WorkingWithPicturesSamples
988804-Modify file streams of C# [Cross-platform] in XlsIO UG
2 parents c86dfe1 + 14f3073 commit e22bec5

File tree

6 files changed

+8
-27
lines changed
  • Pictures in Excel
    • Add Picture/.NET/Add Picture/Add Picture
    • Add SVG Picture/.NET/Add SVG Picture/Add SVG Picture
    • External Image/.NET/External Image/External Image
    • ImageInMergedRegion/.NET/ImageInMergedRegion/ImageInMergedRegion
    • Move and Size with cells/.NET/Move and Size with cells/Move and Size with cells
    • Position and Resize Picture/.NET/Position and Resize Picture/Position and Resize Picture

6 files changed

+8
-27
lines changed

Pictures in Excel/Add Picture/.NET/Add Picture/Add Picture/Program.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@ static void Main(string[] args)
2020

2121
#region Save
2222
//Saving the workbook
23-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/AddPicture.xlsx"), FileMode.Create, FileAccess.Write);
24-
workbook.SaveAs(outputStream);
23+
workbook.SaveAs(Path.GetFullPath("Output/AddPicture.xlsx"));
2524
#endregion
2625

2726
//Dispose streams
28-
outputStream.Dispose();
2927
imageStream.Dispose();
3028
}
3129
}

Pictures in Excel/Add SVG Picture/.NET/Add SVG Picture/Add SVG Picture/Program.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ static void Main(string[] args)
2222

2323
#region Save
2424
//Saving the workbook
25-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/SVGImage.xlsx"), FileMode.Create, FileAccess.Write);
26-
workbook.SaveAs(outputStream);
25+
workbook.SaveAs(Path.GetFullPath("Output/SVGImage.xlsx"));
2726
#endregion
2827

2928
//Dispose streams
30-
outputStream.Dispose();
3129
svgStream.Dispose();
3230
pngStream.Dispose();
3331
}

Pictures in Excel/External Image/.NET/External Image/External Image/Program.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,8 @@ static void Main(string[] args)
1919

2020
#region Save
2121
//Saving the workbook
22-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/ExternalImage.xlsx"), FileMode.Create, FileAccess.Write);
23-
workbook.SaveAs(outputStream);
22+
workbook.SaveAs(Path.GetFullPath("Output/ExternalImage.xlsx"));
2423
#endregion
25-
26-
//Dispose streams
27-
outputStream.Dispose();
2824
}
2925
}
3026
}

Pictures in Excel/ImageInMergedRegion/.NET/ImageInMergedRegion/ImageInMergedRegion/Program.cs

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

1918
//Get the merged cells
@@ -42,14 +41,8 @@ static void Main(string[] args)
4241

4342
#region Save
4443
//Saving the workbook
45-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/ImageInMergedRegion.xlsx"), FileMode.Create, FileAccess.Write);
46-
workbook.SaveAs(outputStream);
44+
workbook.SaveAs(Path.GetFullPath("Output/ImageInMergedRegion.xlsx"));
4745
#endregion
48-
49-
//Dispose streams
50-
outputStream.Dispose();
51-
inputStream.Dispose();
52-
5346
}
5447
}
5548
}

Pictures in Excel/Move and Size with cells/.NET/Move and Size with cells/Move and Size with cells/Program.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,11 @@ public static void Main(string[] args)
2828
//Hide the column
2929
worksheet.HideColumn(5);
3030

31-
//Saving the workbook as stream
32-
FileStream OutputStream = new FileStream(Path.GetFullPath(@"Output/Output.xlsx"), FileMode.Create, FileAccess.ReadWrite);
33-
workbook.SaveAs(OutputStream);
31+
//Saving the workbook
32+
workbook.SaveAs(Path.GetFullPath(@"Output/Output.xlsx"));
3433

3534
//Dispose streams
3635
imageStream.Dispose();
37-
OutputStream.Dispose();
3836
}
3937
}
4038
}

Pictures in Excel/Position and Resize Picture/.NET/Position and Resize Picture/Position and Resize Picture/Program.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,10 @@ static void Main(string[] args)
2828

2929
#region Save
3030
//Saving the workbook
31-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/ResizePicture.xlsx"), FileMode.Create, FileAccess.Write);
32-
workbook.SaveAs(outputStream);
31+
workbook.SaveAs(Path.GetFullPath("Output/ResizePicture.xlsx"));
3332
#endregion
3433

3534
//Dispose streams
36-
outputStream.Dispose();
3735
imageStream.Dispose();
3836
}
3937
}

0 commit comments

Comments
 (0)