Skip to content

Commit

Permalink
Update to v3.0.0 of the SDK (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
twsouthwick authored Nov 15, 2023
1 parent 4891e31 commit aa1b6d7
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 138 deletions.
2 changes: 1 addition & 1 deletion samples/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<ItemGroup>
<PackageReference Include="DocumentFormat.OpenXml" Version="2.20.0" />
<PackageReference Include="DocumentFormat.OpenXml" Version="3.0.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ static void GetSlideIdAndText(out string sldText, string docName, int index)
{
// Get the relationship ID of the first slide.
PresentationPart? part = ppt.PresentationPart;
OpenXmlElementList? slideIds = part?.Presentation?.SlideIdList?.ChildElements;
OpenXmlElementList slideIds = part?.Presentation?.SlideIdList?.ChildElements ?? default;

if (part is null || slideIds is null || slideIds.Count == 0)
if (part is null || slideIds.Count == 0)
{
sldText = "";
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,7 @@ static bool IsTitleShape(Shape shape)

if (placeholderShape is not null && placeholderShape.Type is not null && placeholderShape.Type.HasValue)
{
switch ((PlaceholderValues)placeholderShape.Type)
{
// Any title shape.
case PlaceholderValues.Title:

// A centered title.
case PlaceholderValues.CenteredTitle:
return true;

default:
return false;
}
return placeholderShape.Type == PlaceholderValues.Title || placeholderShape.Type == PlaceholderValues.CenteredTitle;
}

return false;
Expand Down
7 changes: 1 addition & 6 deletions samples/presentation/insert_a_new_slideto/cs/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,7 @@ static void InsertNewSlideFromPresentation(PresentationDocument presentationDocu
uint maxSlideId = 1;
SlideId? prevSlideId = null;

OpenXmlElementList? slideIds = slideIdList?.ChildElements;

if (slideIds is null)
{
throw new ArgumentNullException(nameof(slideIds));
}
OpenXmlElementList slideIds = slideIdList?.ChildElements ?? default;

foreach (SlideId slideId in slideIds)
{
Expand Down
4 changes: 2 additions & 2 deletions samples/presentation/open_for_read_only_access/cs/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ static void GetSlideIdAndText(out string sldText, string docName, int index)
{
// Get the relationship ID of the first slide.
PresentationPart? part = ppt.PresentationPart;
OpenXmlElementList? slideIds = part?.Presentation?.SlideIdList?.ChildElements;
OpenXmlElementList slideIds = part?.Presentation?.SlideIdList?.ChildElements ?? default;

// If there are no slide IDs then there are no slides.
if (slideIds is null || slideIds.Count() < 1)
if (slideIds.Count == 0)
{
sldText = "";
return;
Expand Down
168 changes: 82 additions & 86 deletions samples/samples.sln

Large diffs are not rendered by default.

55 changes: 26 additions & 29 deletions samples/spreadsheet/retrieve_the_values_of_cells/cs/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,38 +51,35 @@ static string GetCellValue(string fileName, string sheetName, string addressName
// the words TRUE or FALSE.
if (theCell.DataType is not null)
{
switch (theCell.DataType.Value)
if (theCell.DataType.Value == CellValues.SharedString)
{
case CellValues.SharedString:

// For shared strings, look up the value in the
// shared strings table.
var stringTable =
wbPart.GetPartsOfType<SharedStringTablePart>().FirstOrDefault();
// For shared strings, look up the value in the
// shared strings table.
var stringTable =
wbPart.GetPartsOfType<SharedStringTablePart>().FirstOrDefault();

// If the shared string table is missing, something
// is wrong. Return the index that is in
// the cell. Otherwise, look up the correct text in
// the table.
if (stringTable is not null)
{
value =
stringTable.SharedStringTable.ElementAt(int.Parse(value)).InnerText;
}

break;

case CellValues.Boolean:
switch (value)
{
case "0":
value = "FALSE";
break;
default:
value = "TRUE";
break;
}
break;
// If the shared string table is missing, something
// is wrong. Return the index that is in
// the cell. Otherwise, look up the correct text in
// the table.
if (stringTable is not null)
{
value =
stringTable.SharedStringTable.ElementAt(int.Parse(value)).InnerText;
}
}
else if (theCell.DataType.Value == CellValues.Boolean)
{
switch (value)
{
case "0":
value = "FALSE";
break;
default:
value = "TRUE";
break;
}
}
}
}
Expand Down

0 comments on commit aa1b6d7

Please sign in to comment.