Skip to content

Commit aa1b6d7

Browse files
authored
Update to v3.0.0 of the SDK (#260)
1 parent 4891e31 commit aa1b6d7

File tree

7 files changed

+115
-138
lines changed

7 files changed

+115
-138
lines changed

samples/Directory.Build.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Project>
22
<ItemGroup>
3-
<PackageReference Include="DocumentFormat.OpenXml" Version="2.20.0" />
3+
<PackageReference Include="DocumentFormat.OpenXml" Version="3.0.0" />
44
</ItemGroup>
55
</Project>

samples/presentation/get_all_the_text_all_slides/cs/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ static void GetSlideIdAndText(out string sldText, string docName, int index)
5858
{
5959
// Get the relationship ID of the first slide.
6060
PresentationPart? part = ppt.PresentationPart;
61-
OpenXmlElementList? slideIds = part?.Presentation?.SlideIdList?.ChildElements;
61+
OpenXmlElementList slideIds = part?.Presentation?.SlideIdList?.ChildElements ?? default;
6262

63-
if (part is null || slideIds is null || slideIds.Count == 0)
63+
if (part is null || slideIds.Count == 0)
6464
{
6565
sldText = "";
6666
return;

samples/presentation/get_the_titles_of_all_the_slides/cs/Program.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,7 @@ static bool IsTitleShape(Shape shape)
115115

116116
if (placeholderShape is not null && placeholderShape.Type is not null && placeholderShape.Type.HasValue)
117117
{
118-
switch ((PlaceholderValues)placeholderShape.Type)
119-
{
120-
// Any title shape.
121-
case PlaceholderValues.Title:
122-
123-
// A centered title.
124-
case PlaceholderValues.CenteredTitle:
125-
return true;
126-
127-
default:
128-
return false;
129-
}
118+
return placeholderShape.Type == PlaceholderValues.Title || placeholderShape.Type == PlaceholderValues.CenteredTitle;
130119
}
131120

132121
return false;

samples/presentation/insert_a_new_slideto/cs/Program.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,7 @@ static void InsertNewSlideFromPresentation(PresentationDocument presentationDocu
9191
uint maxSlideId = 1;
9292
SlideId? prevSlideId = null;
9393

94-
OpenXmlElementList? slideIds = slideIdList?.ChildElements;
95-
96-
if (slideIds is null)
97-
{
98-
throw new ArgumentNullException(nameof(slideIds));
99-
}
94+
OpenXmlElementList slideIds = slideIdList?.ChildElements ?? default;
10095

10196
foreach (SlideId slideId in slideIds)
10297
{

samples/presentation/open_for_read_only_access/cs/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ static void GetSlideIdAndText(out string sldText, string docName, int index)
1616
{
1717
// Get the relationship ID of the first slide.
1818
PresentationPart? part = ppt.PresentationPart;
19-
OpenXmlElementList? slideIds = part?.Presentation?.SlideIdList?.ChildElements;
19+
OpenXmlElementList slideIds = part?.Presentation?.SlideIdList?.ChildElements ?? default;
2020

2121
// If there are no slide IDs then there are no slides.
22-
if (slideIds is null || slideIds.Count() < 1)
22+
if (slideIds.Count == 0)
2323
{
2424
sldText = "";
2525
return;

samples/samples.sln

Lines changed: 82 additions & 86 deletions
Large diffs are not rendered by default.

samples/spreadsheet/retrieve_the_values_of_cells/cs/Program.cs

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -51,38 +51,35 @@ static string GetCellValue(string fileName, string sheetName, string addressName
5151
// the words TRUE or FALSE.
5252
if (theCell.DataType is not null)
5353
{
54-
switch (theCell.DataType.Value)
54+
if (theCell.DataType.Value == CellValues.SharedString)
5555
{
56-
case CellValues.SharedString:
5756

58-
// For shared strings, look up the value in the
59-
// shared strings table.
60-
var stringTable =
61-
wbPart.GetPartsOfType<SharedStringTablePart>().FirstOrDefault();
57+
// For shared strings, look up the value in the
58+
// shared strings table.
59+
var stringTable =
60+
wbPart.GetPartsOfType<SharedStringTablePart>().FirstOrDefault();
6261

63-
// If the shared string table is missing, something
64-
// is wrong. Return the index that is in
65-
// the cell. Otherwise, look up the correct text in
66-
// the table.
67-
if (stringTable is not null)
68-
{
69-
value =
70-
stringTable.SharedStringTable.ElementAt(int.Parse(value)).InnerText;
71-
}
72-
73-
break;
74-
75-
case CellValues.Boolean:
76-
switch (value)
77-
{
78-
case "0":
79-
value = "FALSE";
80-
break;
81-
default:
82-
value = "TRUE";
83-
break;
84-
}
85-
break;
62+
// If the shared string table is missing, something
63+
// is wrong. Return the index that is in
64+
// the cell. Otherwise, look up the correct text in
65+
// the table.
66+
if (stringTable is not null)
67+
{
68+
value =
69+
stringTable.SharedStringTable.ElementAt(int.Parse(value)).InnerText;
70+
}
71+
}
72+
else if (theCell.DataType.Value == CellValues.Boolean)
73+
{
74+
switch (value)
75+
{
76+
case "0":
77+
value = "FALSE";
78+
break;
79+
default:
80+
value = "TRUE";
81+
break;
82+
}
8683
}
8784
}
8885
}

0 commit comments

Comments
 (0)